1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-05 19:47:12 +00:00

Move modules and module_utils unit tests to correct place (#81)

* Move modules and module_utils unit tests to correct place.

* Update ignore.txt

* Fix imports.

* Fix typos.

* Fix more typos.
This commit is contained in:
Felix Fontein 2020-03-31 10:42:38 +02:00 committed by GitHub
parent ab3c2120fb
commit be191cce6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1170 changed files with 732 additions and 751 deletions

View file

@ -0,0 +1 @@
Directory of /flash/

View file

@ -0,0 +1,12 @@
!
hostname router
!
interface ethernet 1/1
ip address 1.2.3.4 255.255.255.0
port-name test string
enable
!
interface ethernet 1/2
ip address 6.7.8.9 255.255.255.0
port-name test string
!

View file

@ -0,0 +1,13 @@
!
hostname router
!
interface ethernet 1/1
ip address 1.2.3.4 255.255.255.0
port-name test string
enable
!
interface ethernet 1/2
ip address 6.7.8.9 255.255.255.0
port-name test string
disable
!

View file

@ -0,0 +1,10 @@
!
hostname foo
!
interface ethernet 1/1
no ip address
!
interface ethernet 1/2
ip address 6.7.8.9 255.255.255.0
port-name test string
!

View file

@ -0,0 +1,45 @@
*** MLXe 4-slot Chassis ***
---POWERS ---
Power 1: (23-0000129-02 BMG2J50F014 - AC 1800W): Installed (OK)
Power 2: ( 32006000 113186101409 - AC 1200W): Installed (OK)
Power 3: not present
Power 4: not present
Total power budget for chassis = 3000 W
Total power used by system core = 450 W
Total power used by LPs = 406 W
Total power available = 2144 W
Slot Power-On Priority and Power Usage:
Slot1 pri=1 module type=NI-MLX-10Gx8-M 8-port 10GbE (M) Module power usage=246W
Slot2 pri=1 module type=BR-MLX-1GFx24-X 24-port 1GbE SFP Module power usage=160W
--- FANS ---
Back fan A-1: Status = OK, Speed = LOW (50%)
Back fan A-2: Status = OK, Speed = LOW (50%)
Back fan B-1: Status = OK, Speed = LOW (50%)
Back fan B-2: Status = OK, Speed = LOW (50%)
Back fan C-1: Status = OK, Speed = LOW (50%)
Back fan C-2: Status = OK, Speed = LOW (50%)
Back fan D-1: Status = OK, Speed = LOW (50%)
Back fan D-2: Status = OK, Speed = LOW (50%)
--- TEMPERATURE READINGS ---
Active Mgmt Module: 33.500C 44.375C
Standby Mgmt Module: 35.500C 47.250C
SFM1: FE1:34.625C
SFM2: FE1:37.0C
SFM3: not present
LP1 Sensor1: 37.500C
LP1 Sensor2: 38.375C
LP1 Sensor3: 34.750C
LP1 Sensor4: 33.0C
LP1 Sensor5: 39.125C
LP1 Sensor6: 39.0C
LP1 Sensor7: 43.0C
LP2 Sensor1: 47.500C
LP2 Sensor2: 43.500C
LP2 Sensor3: 38.625C
Fans are in auto mode (current speed is LOW (50%)). Temperature monitoring poll period is 60 seconds.
--- MISC INFO ---
Backplane EEPROM MAC Address: 0024.38ae.ff00

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
Type Codes - I:ISIS O:OSPF R:RIP
Interface Status/Protocol IGPs IPv6 Address VRF
eth 1/1 up/up fe80::224:38ff:feae:ff00 default-vrf
2001:db8::1/64
2001:db8::/64[Anycast]

View file

@ -0,0 +1,3 @@
Total number of LLDP neighbors on all ports: 6
Lcl Port Chassis ID Port ID Port Description System Name
1/2 748e.f863.3600 748e.f863.3631 10GigabitEthernet2/1 ces01.lab

View file

@ -0,0 +1,30 @@
====================================================================
NetIron MLX active MP slot 5:
Total SDRAM : 4294967295 bytes
Available Memory : 3806097408 bytes
Available Memory (%): 88 percent
Free Physical Pages : 925008 pages
Malloc statistics: total 633606628
OS malloc count: 2437418082
OS malloc fail: 0
OS free count: 2437404486
OS free fail: 0
diff: 13596
====================================================================
NetIron MLX standby MP slot 6:
Total SDRAM : 4294967295 bytes
Available Memory : 3784171520 bytes
Available Memory (%): 88 percent
Free Physical Pages : 917843 pages
====================================================================
NetIron MLX LP SL 1:
Total SDRAM : 1073741824 bytes
Available Memory : 485294080 bytes
Available Memory (%): 45 percent
====================================================================
NetIron MLX LP SL 2:
Total SDRAM : 1073741824 bytes
Available Memory : 561364992 bytes
Available Memory (%): 52 percent

View file

@ -0,0 +1,32 @@
LSP LSP1, to 192.0.2.1
From: (n/a), admin: DOWN, status: DOWN
revert timer: 300 seconds
Times primary LSP goes up since enabled: 1
Metric: 0, Adaptive
Maximum retries: NONE, no. of retries: 0
Pri. path: NONE, up: no, active: no
Setup priority: 7, hold priority: 0, cos 1
Max rate: 0 kbps, mean rate: 0 kbps, max burst: 0 bytes
CSPF-computation-mode configured: use te-metric(global)
ReoptimizeTimer configured 1800
Tie breaking: random, hop limit: 0
LDP tunneling enabled: yes
Soft preemption enabled: no
Active Path attributes:
Fast Reroute: facility backup desired, node protection desired
Backup LSP: DOWN
Global revertiveness enabled with hold time 5 secs
FRR Forwarding State: Pri(down), Backup(down)
LSP LSP3, to 192.0.2.3
From: (n/a), admin: DOWN, status: DOWN
Times primary LSP goes up since enabled: 0
Metric: 0
Maximum retries: NONE, no. of retries: 0
Pri. path: NONE, up: no, active: no
Setup priority: 7, hold priority: 0
Max rate: 0 kbps, mean rate: 0 kbps, max burst: 0 bytes
CSPF-computation-mode configured: use te-metric(global)
Tie breaking: random, hop limit: 0
LDP tunneling enabled: no
Soft preemption enabled: no
Active Path attributes:

View file

@ -0,0 +1,7 @@
VLL TEST-LOCAL VLL-ID 1 IFL-ID --
State: DOWN - endpoint port is down
End-point 1: untagged e 2/8
COS: --
End-point 2: tagged vlan 5 e 2/9
COS: --
Extended Counters: Enabled

View file

@ -0,0 +1,19 @@
VLL TEST-VLL, VC-ID 111, VLL-INDEX 4
End-point : tagged vlan 2005 e 2/1
End-Point state : Up
MCT state : None
IFL-ID : --
Local VC type : untag
Local VC MTU : 9190
COS : 1
Extended Counters: Enabled
Vll-Peer : 192.0.2.1
State : DOWN - PW is Down (Reason:Wait for peer label)
Remote VC type : -- Remote VC MTU : --
Local label : -- Remote label : --
Local group-id : 0 Remote group-id: --
Tunnel LSP : lsp1 (tnl1)
MCT Status TLV : --
LSPs assigned : No LSPs assigned

View file

@ -0,0 +1,21 @@
VPLS TEST-VPLS, Id 333, Max mac entries: 2048
Total vlans: 2, Tagged ports: 2 (0 Up), Untagged ports 2 (0 Up)
IFL-ID: n/a
Vlan 5
L2 Protocol: NONE
Untagged: ethe 2/4
Vlan 6
L2 Protocol: NONE
Tagged: ethe 2/5 to 2/6
Untagged: ethe 2/7
VC-Mode: Raw
Total VPLS peers: 1 (0 Operational)
Peer address: 192.0.2.3, State: Wait for functional local ports
Tnnl in use: tnl1(3)[RSVP] Peer Index:0
Local VC lbl: N/A, Remote VC lbl: N/A
Local VC MTU: 9190, Remote VC MTU: 0
Local VC-Type: Ethernet(0x05), Remote VC-Type: UNKNOWN
CPU-Protection: OFF
Local Switching: Enabled
Extended Counter: ON
Multicast Snooping: Disabled

View file

@ -0,0 +1,291 @@
!Current configuration:
!
ver V5.8.0fT163
module 1 ni-mlx-8-port-10g-m
module 2 br-mlx-24-port-1gf-x
!
!
mirror ethernet 2/20
!
lag "LAG" dynamic id 3
ports ethernet 1/1
primary-port 1/1
lacp-timeout short
deploy
!
!
!
!
no spanning-tree
!
!
vlan 1 name DEFAULT-VLAN
no untagged ethe 2/1 to 2/2 ethe 2/4 to 2/9
!
vlan 150
!
vlan 666 name LACP_ISOLATION_CUSTOMER
!
vlan 1000
!
vlan 2007
tagged ethe 2/1
!
vlan 4040
untagged ethe 1/1
!
!
!
qos-mapping
!
default-max-frame-size 9216
cpu-usage on
aaa authentication login default tacacs+ local enable
tacacs-server host 192.0.2.5
tacacs-server key 2 $X3FSZjgzKGzPIXVd
!
!
enable password-display
enable super-user-password 8 $1$WV1..Pi2$B6acbjDxeHsof2BKrpyqQ0
enable aaa console
logging host 192.0.2.5
logging facility local7
logging buffered 5000
logging console
username admin password 8 $1$MF/..XD4$MYUy7kcm/1eAuqXnVyvVO1
username admin history $1$MF/..XD4$MYUy7kcm/1eAuqXnVyvVO1 $1$KE/..Cs2$WlfErdta9.sG9v5QmbaTd/
!
tag-type 9100 ethe 1/4
tag-type 9100 ethe 2/2
tag-type 9100 ethe 2/24
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
snmp-server
snmp-server community 2 $YkAtaSs/fFE6Sz97 ro
snmp-server max-ifindex-per-module 64
snmp-server cache size 128
hostname mlx01.lab
no transceiver-type-check
!
netconf server
!
router isis
net 49.0001.0100.6900.0006.00
fast-flood 4
no hello padding
is-type level-2
log adjacency
address-family ipv4 unicast
metric-style wide
redistribute connected
exit-address-family
address-family ipv6 unicast
no adjacency-check
exit-address-family
!
!
!
!
!
qos-policy
!
policy-map CUST-100Mb
cir 99992032 cbs 3125000
!
policy-map core-to-core-interface
!
!
hqos scheduler-policy core-to-core-interface-4.2G level level-0
shaper-rate 4193280
shaper-burst-size 256
scheduler-type strict
!
!
!
hqos scheduler-policy P5 level level-1
shaper-rate 10000000
shaper-burst-size 10
scheduler-type strict
!
!
!
!
interface loopback 1
ip address 10.69.0.6/32
no ip redirect
!
!
interface ethernet 1/1
enable
load-interval 30
bfd interval 100 min-rx 100 multiplier 5
ip router isis
ip address 10.69.1.6/30
ip mtu 9198
ipv6 address 2001:db8::1/64
isis bfd
isis circuit-type level-2
isis metric 500
isis point-to-point
!
interface ethernet 1/2
port-name foo
enable
load-interval 30
bfd interval 100 min-rx 100 multiplier 5
ip router isis
ip address 10.69.1.77/30
ip mtu 9198
isis circuit-type level-2
isis ipv6 metric 250
isis point-to-point
!
interface ethernet 1/3
enable
forward-lacp
!
interface ethernet 1/4
enable
forward-lacp
!
interface ethernet 2/1
enable
mon ethernet 2/20 both
!
interface ethernet 2/2
enable
load-interval 30
rate-limit input broadcast unknown-unicast multicast 521216 64000
no spanning-tree
!
interface ethernet 2/3
load-interval 30
rate-limit input broadcast unknown-unicast multicast 521216 64000
no fdp enable
no cdp enable
no spanning-tree
!
interface ethernet 2/4
enable
load-interval 30
rate-limit input broadcast unknown-unicast multicast 521216 64000
no fdp enable
no cdp enable
no spanning-tree
!
interface ethernet 2/13
enable
load-interval 30
!
interface ethernet 2/20
enable
!
interface ethernet 2/21
enable
!
interface ethernet 2/24
enable
!
ip tacacs source-interface loopback 1
!
!
router mpls
bfd
dynamic-bypass
enable
reoptimize-timer 1800
policy
traffic-eng isis level-2
handle-isis-neighbor-down
cspf-computation-mode use-te-metric
rsvp
rsvp-reliable-messaging
ldp
tunnel-metric 10
mpls-interface e1/1
rsvp-reliable-messaging
dynamic-bypass
enable
name-prefix dyn
adaptive
cos 1
mpls-interface e1/2
rsvp-reliable-messaging
dynamic-bypass
enable
name-prefix dyn
adaptive
cos 1
lsp LSP1
to 192.0.2.1
no cspf
adaptive
enable
lsp LSP3
to 192.0.2.3
shortcuts isis level2
adaptive
reoptimize-timer 1800
frr
facility-backup
revert-timer 300
enable
vll TEST-VLL 111 raw-mode cos 1
vll-peer 192.0.2.1
vlan 2005
tagged e 2/1
vll-local TEST-LOCAL
extended-counters on
untag e 2/8
vlan 5
tag e 2/9
vpls TEST-VPLS 333
vpls-peer 192.0.2.3
vlan 5
untagged ethe 2/4
vlan 6
tagged ethe 2/5 to 2/6
untagged ethe 2/7
!
!
!
lldp enable ports ethe 1/1 to 1/8 ethe 2/1 to 2/24
lldp run
!
!
!
!
!
end

View file

@ -0,0 +1,92 @@
System Mode: MLX
Chassis: MLXe 4-slot (Serial #: BGD2503J01F, Part #: 40-1000363-04)
NI-X-HSF Switch Fabric Module 1 (Serial #: BEW0444H01V, Part #: 60-1001512-10)
FE 1: Type fe600, Version 1
Switch Fabric Module 1 Up Time is 203 days 4 hours 44 minutes 54 seconds
NI-X-HSF Switch Fabric Module 2 (Serial #: BEW0432H06S, Part #: 60-1001512-10)
FE 1: Type fe600, Version 1
Switch Fabric Module 2 Up Time is 203 days 4 hours 44 minutes 54 seconds
==========================================================================
SL M1: BR-MLX-MR2-M Management Module Active (Serial #: BVP0425L02W, Part #: 60-1002374-07):
Boot : Version 5.8.0T165 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:10 labeled as xmprm05800
(521590 bytes) from boot flash
Monitor : Version 5.8.0T165 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:01:40 labeled as xmb05800
(539721 bytes) from code flash
IronWare : Version 5.8.0fT163 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on Feb 24 2017 at 02:54:38 labeled as xmr05800fb
(9983317 bytes) from Primary
Board ID : 00 MBRIDGE Revision : 37
1666 MHz Power PC processor 7448 (version 8004/0202) 166 MHz bus
512 KB Boot Flash (MX29LV040C), 128 MB Code Flash (MT28F256J3)
4096 MB DRAM INSTALLED
4096 MB DRAM ADDRESSABLE
Active Management uptime is 203 days 4 hours 44 minutes 54 seconds
==========================================================================
SL M2: BR-MLX-MR2-M Management Module Standby (Serial #: BVP0407L00D, Part #: 60-1002374-07):
Boot : Version 5.8.0T165 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:10 labeled as xmprm05800
(521590 bytes) from boot flash
Monitor : Version 5.8.0T165 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:01:40 labeled as xmb05800
(539721 bytes) from code flash
IronWare : Version 5.8.0fT163 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on Feb 24 2017 at 02:54:38 labeled as xmr05800fb
(9983317 bytes) from Primary
Board ID : 00 MBRIDGE Revision : 37
1666 MHz Power PC processor 7448 (version 8004/0202) 166 MHz bus
512 KB Boot Flash (MX29LV040C), 128 MB Code Flash (MT28F256J3)
4096 MB DRAM INSTALLED
4096 MB DRAM ADDRESSABLE
Standby Management uptime is 203 days 4 hours 44 minutes 15 seconds
==========================================================================
SL 1: NI-MLX-10Gx8-M 8-port 10GbE (M) Module (Serial #: BEQ0403G05E, Part #: 60-1001587-13)
(LID: dgsFJFIiFKg)
Boot : Version 5.8.0T175 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:24 labeled as xmlprm05800
(449481 bytes) from boot flash
Monitor : Version 5.8.0T175 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:40 labeled as xmlb05800
(568745 bytes) from code flash
IronWare : Version 5.8.0fT177 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on Feb 24 2017 at 03:02:10 labeled as xmlp05800fb
(9304807 bytes) from Primary
FPGA versions:
Valid PBIF Version = 2.24, Build Time = 4/7/2016 14:16:00
Valid XPP Version = 0.08, Build Time = 6/27/2016 10:36:00
MACXPP40G 0
MACXPP40G 1
1333 MHz MPC MPC8548 (version 8021/0022) 533 MHz bus
512 KB Boot Flash (MX29LV040C), 64 MB Code Flash (MT28F256J3)
1024 MB DRAM, 8 KB SRAM
LP Slot 1 uptime is 203 days 4 hours 44 minutes 12 seconds
==========================================================================
SL 2: BR-MLX-1GFx24-X 24-port 1GbE SFP Module (Serial #: BND0415H003, Part #: 60-1001892-11)
License: (LID: dpfFJGKjFFI)
Boot : Version 5.8.0T175 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:24 labeled as xmlprm05800
(449481 bytes) from boot flash
Monitor : Version 5.8.0T175 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on May 18 2015 at 13:02:40 labeled as xmlb05800
(568745 bytes) from code flash
IronWare : Version 5.8.0fT177 Copyright (c) 1996-2014 Brocade Communications Systems, Inc.
Compiled on Feb 24 2017 at 03:02:10 labeled as xmlp05800fb
(9304807 bytes) from Primary
FPGA versions:
Valid PBIF Version = 4.04, Build Time = 11/10/2014 22:10:00
Valid XPP Version = 1.03, Build Time = 6/30/2016 10:37:00
Valid STATS Version = 0.09, Build Time = 11/21/2010 14:52:00
BCM56512GMAC 0
BCM56512GMAC 1
666 MHz MPC MPC8541E (version 8020/0020) 333 MHz bus
512 KB Boot Flash (MX29LV040C), 16 MB Code Flash (MT28F128J3)
1024 MB DRAM, 8 KB SRAM
LP Slot 2 uptime is 21 days 20 hours 23 minutes 19 seconds
==========================================================================
All show version done

View file

@ -0,0 +1,88 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestIronwareModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
self.load_fixtures(commands)
if failed:
result = self.failed()
self.assertTrue(result['failed'], result)
else:
result = self.changed(changed)
self.assertEqual(result['changed'], changed, result)
if commands is not None:
if sort:
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
else:
self.assertEqual(commands, result['commands'], result['commands'])
return result
def failed(self):
with self.assertRaises(AnsibleFailJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
with self.assertRaises(AnsibleExitJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
return result
def load_fixtures(self, commands=None):
pass

View file

@ -0,0 +1,100 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.plugins.modules.network.ironware import ironware_command
from .ironware_module import TestIronwareModule, load_fixture
class TestIronwareCommandModule(TestIronwareModule):
module = ironware_command
def setUp(self):
super(TestIronwareCommandModule, self).setUp()
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.ironware.ironware_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestIronwareCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for command in commands:
filename = str(command).replace(' ', '_')
output.append(load_fixture(filename))
return output
self.run_commands.side_effect = load_from_file
def test_ironware_command_simple(self):
set_module_args(dict(commands=['show version']))
result = self.execute_module()
self.assertEqual(len(result['stdout']), 1)
self.assertTrue(result['stdout'][0].startswith('System Mode: MLX'))
def test_ironware_command_multiple(self):
set_module_args(dict(commands=['show version', 'show version']))
result = self.execute_module()
self.assertEqual(len(result['stdout']), 2)
self.assertTrue(result['stdout'][0].startswith('System Mode: MLX'))
def test_ironware_command_wait_for(self):
wait_for = 'result[0] contains "IronWare"'
set_module_args(dict(commands=['show version'], wait_for=wait_for))
self.execute_module()
def test_ironware_command_wait_for_fails(self):
wait_for = 'result[0] contains "test string"'
set_module_args(dict(commands=['show version'], wait_for=wait_for))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 10)
def test_ironware_command_retries(self):
wait_for = 'result[0] contains "test string"'
set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 2)
def test_ironware_command_match_any(self):
wait_for = ['result[0] contains "IronWare"',
'result[0] contains "test string"']
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any'))
self.execute_module()
def test_ironware_command_match_all(self):
wait_for = ['result[0] contains "IronWare"',
'result[0] contains "uptime is"']
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all'))
self.execute_module()
def test_ironware_command_match_all_failure(self):
wait_for = ['result[0] contains "IronWare"',
'result[0] contains "test string"']
commands = ['show version', 'show version']
set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
self.execute_module(failed=True)

View file

@ -0,0 +1,165 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.plugins.modules.network.ironware import ironware_config
from .ironware_module import TestIronwareModule, load_fixture
class TestIronwareConfigModule(TestIronwareModule):
module = ironware_config
def setUp(self):
super(TestIronwareConfigModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.ironware.ironware_config.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.ironware.ironware_config.load_config')
self.load_config = self.mock_load_config.start()
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.ironware.ironware_config.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestIronwareConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
config_file = 'ironware_config_config.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def execute_module(self, failed=False, changed=False, updates=None, sort=True, defaults=False):
self.load_fixtures(updates)
if failed:
result = self.failed()
self.assertTrue(result['failed'], result)
else:
result = self.changed(changed)
self.assertEqual(result['changed'], changed, result)
if updates is not None:
if sort:
self.assertEqual(sorted(updates), sorted(result['updates']), result['updates'])
else:
self.assertEqual(updates, result['updates'], result['updates'])
return result
def test_ironware_config_unchanged(self):
src = load_fixture('ironware_config_config.cfg')
set_module_args(dict(src=src))
self.execute_module()
def test_ironware_config_src(self):
src = load_fixture('ironware_config_src.cfg')
set_module_args(dict(src=src))
updates = ['hostname foo', 'interface ethernet 1/1',
'no ip address']
self.execute_module(changed=True, updates=updates)
def test_ironware_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_ironware_config_save_always(self):
self.run_commands.return_value = "hostname foobar"
set_module_args(dict(save_when='always'))
self.execute_module(changed=True)
self.assertEqual(self.run_commands.call_count, 1)
self.assertEqual(self.get_config.call_count, 1)
self.assertEqual(self.load_config.call_count, 0)
def test_ironware_config_lines_wo_parents(self):
set_module_args(dict(lines=['hostname foobar']))
updates = ['hostname foobar']
self.execute_module(changed=True, updates=updates)
def test_ironware_config_lines_w_parents(self):
set_module_args(dict(lines=['disable'], parents=['interface ethernet 1/1']))
updates = ['interface ethernet 1/1', 'disable']
self.execute_module(changed=True, updates=updates)
def test_ironware_config_before(self):
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
updates = ['test1', 'test2', 'hostname foo']
self.execute_module(changed=True, updates=updates, sort=False)
def test_ironware_config_after(self):
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
updates = ['hostname foo', 'test1', 'test2']
self.execute_module(changed=True, updates=updates, sort=False)
def test_ironware_config_before_after_no_change(self):
set_module_args(dict(lines=['hostname router'],
before=['test1', 'test2'],
after=['test3', 'test4']))
self.execute_module()
def test_ironware_config_config(self):
config = 'hostname localhost'
set_module_args(dict(lines=['hostname router'], config=config))
updates = ['hostname router']
self.execute_module(changed=True, updates=updates)
def test_ironware_config_replace_block(self):
lines = ['port-name test string', 'test string']
parents = ['interface ethernet 1/1']
set_module_args(dict(lines=lines, replace='block', parents=parents))
updates = parents + lines
self.execute_module(changed=True, updates=updates)
def test_ironware_config_match_none(self):
lines = ['hostname router']
set_module_args(dict(lines=lines, match='none'))
self.execute_module(changed=True, updates=lines)
def test_ironware_config_match_none_parents(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'port-name test string']
parents = ['interface ethernet 1/1']
set_module_args(dict(lines=lines, parents=parents, match='none'))
updates = parents + lines
self.execute_module(changed=True, updates=updates, sort=False)
def test_ironware_config_match_strict(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'port-name test string',
'disable']
parents = ['interface ethernet 1/1']
set_module_args(dict(lines=lines, parents=parents, match='strict'))
updates = parents + ['disable']
self.execute_module(changed=True, updates=updates, sort=False)
def test_ironware_config_match_exact(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'port-name test string',
'disable']
parents = ['interface ethernet 1/1']
set_module_args(dict(lines=lines, parents=parents, match='exact'))
updates = parents + lines
self.execute_module(changed=True, updates=updates, sort=False)

View file

@ -0,0 +1,102 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from ansible_collections.community.general.plugins.modules.network.ironware import ironware_facts
from .ironware_module import TestIronwareModule, load_fixture
class TestIronwareFacts(TestIronwareModule):
module = ironware_facts
def setUp(self):
super(TestIronwareFacts, self).setUp()
self.mock_run_commands = patch(
'ansible_collections.community.general.plugins.modules.network.ironware.ironware_facts.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestIronwareFacts, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None):
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for item in commands:
try:
obj = json.loads(item)
command = obj['command']
except ValueError:
command = item
filename = str(command).split(' | ')[0].replace(' ', '_').replace('/', '7')
output.append(load_fixture(filename))
return output
self.run_commands.side_effect = load_from_file
def test_ironware_facts_gather_subset_default(self):
set_module_args(dict())
result = self.execute_module()
ansible_facts = result['ansible_facts']
self.assertIn('hardware', ansible_facts['ansible_net_gather_subset'])
self.assertIn('default', ansible_facts['ansible_net_gather_subset'])
self.assertIn('interfaces', ansible_facts['ansible_net_gather_subset'])
self.assertEqual(['/flash/'], ansible_facts['ansible_net_filesystems'])
self.assertIn('1/1', ansible_facts['ansible_net_interfaces'].keys())
self.assertIn('10.69.1.6', ansible_facts['ansible_net_all_ipv4_addresses'])
self.assertIn('2001:db8::1', ansible_facts['ansible_net_all_ipv6_addresses'])
self.assertIn('ansible_net_neighbors', ansible_facts)
self.assertIn('1/2', ansible_facts['ansible_net_neighbors'].keys())
self.assertEqual(4096, ansible_facts['ansible_net_memtotal_mb'])
self.assertEqual(3630, ansible_facts['ansible_net_memfree_mb'])
self.assertEqual('5.8.0fT163', ansible_facts['ansible_net_version'])
self.assertEqual('MLXe 4-slot Chassis', ansible_facts['ansible_net_model'])
self.assertEqual('BGD2503J01F', ansible_facts['ansible_net_serialnum'])
def test_ironware_facts_gather_subset_config(self):
set_module_args({'gather_subset': 'config'})
result = self.execute_module()
ansible_facts = result['ansible_facts']
self.assertIn('default', ansible_facts['ansible_net_gather_subset'])
self.assertIn('config', ansible_facts['ansible_net_gather_subset'])
self.assertIn('ansible_net_config', ansible_facts)
def test_ironware_facts_gather_subset_mpls(self):
set_module_args({'gather_subset': 'mpls'})
result = self.execute_module()
ansible_facts = result['ansible_facts']
self.assertIn('default', ansible_facts['ansible_net_gather_subset'])
self.assertIn('mpls', ansible_facts['ansible_net_gather_subset'])
self.assertIn('ansible_net_mpls_lsps', ansible_facts)
self.assertIn('ansible_net_mpls_vll', ansible_facts)
self.assertIn('ansible_net_mpls_vll_local', ansible_facts)
self.assertIn('ansible_net_mpls_vpls', ansible_facts)
self.assertIn('LSP1', ansible_facts['ansible_net_mpls_lsps'].keys())
self.assertIn('TEST-VLL', ansible_facts['ansible_net_mpls_vll'].keys())
self.assertIn('TEST-LOCAL', ansible_facts['ansible_net_mpls_vll_local'].keys())
self.assertIn('TEST-VPLS', ansible_facts['ansible_net_mpls_vpls'].keys())