mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-11 06:25:04 +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:
parent
ab3c2120fb
commit
be191cce6c
1170 changed files with 732 additions and 751 deletions
0
tests/unit/plugins/modules/network/icx/__init__.py
Normal file
0
tests/unit/plugins/modules/network/icx/__init__.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
banner motd require-enter-key
|
||||
banner motd $
|
||||
welcome
|
||||
new user
|
||||
$
|
||||
!
|
||||
interface ethernet 1/1/1
|
||||
port-name port name
|
||||
disable
|
||||
speed-duplex 10-full
|
||||
inline power power-limit 7000
|
||||
!
|
||||
interface ethernet 1/1/2
|
||||
speed-duplex 10-full
|
||||
inline power power-limit 3000
|
||||
!
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
!
|
||||
hostname router
|
||||
!
|
||||
interface ethernet 1/1/4
|
||||
port-name test-interface-4
|
||||
speed-duplex 10-full
|
||||
!
|
||||
interface ethernet 1/1/5
|
||||
port-name port5
|
||||
ip address 172.18.20.4 255.255.255.0
|
||||
!
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
!
|
||||
hostname foo
|
||||
!
|
||||
interface ethernet 1/1/4
|
||||
disable
|
||||
!
|
||||
interface ethernet 1/1/5
|
||||
port-name port5
|
||||
ip address 172.18.20.4 255.255.255.0
|
||||
!
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Translating hostname client fileserver.alethea.in ....
|
||||
......
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
lag blue static id 11
|
||||
ports ethe 1/1/1
|
||||
port-name test-interface-1 ethernet 1/1/1
|
||||
!
|
||||
interface ethernet 1/1/1
|
||||
port-name test-interface-1
|
||||
speed-duplex 10-full
|
||||
!
|
||||
interface ethernet 1/1/2
|
||||
port-name test-interface-2
|
||||
speed-duplex 10-full
|
||||
inline power power-limit 2000
|
||||
!
|
||||
interface ethernet 1/1/48
|
||||
inline power power-by-class 2
|
||||
!
|
||||
interface ethernet 1/1/3
|
||||
speed-duplex 10-full
|
||||
inline power power-limit 3000
|
||||
!
|
||||
interface loopback 10
|
||||
port-name loopback10
|
||||
disable
|
||||
!
|
||||
interface lag 11
|
||||
port-name lag ports
|
||||
speed-duplex 10-full
|
||||
!
|
||||
|
||||
GigabitEthernet1/1/1 is up, line protocol is up
|
||||
Port up for 18 hour(s) 40 minute(s) 16 second(s)
|
||||
Hardware is GigabitEthernet, address is 609c.9fe7.d130 (bia 609c.9fe7.d130)
|
||||
Configured speed 10Mbit, actual 10Mbit, configured duplex fdx, actual fdx
|
||||
Configured mdi mode AUTO, actual MDI
|
||||
Member of L2 VLAN ID 1, port is untagged, port state is FORWARDING
|
||||
BPDU guard is Disabled, ROOT protect is Disabled, Designated protect is Disabled
|
||||
Link Error Dampening is Disabled
|
||||
STP configured to ON, priority is level0, mac-learning is enabled
|
||||
Openflow is Disabled, Openflow Hybrid mode is Disabled, Flow Control is config enabled, oper enabled, negotiation disabled
|
||||
Mirror disabled, Monitor disabled
|
||||
Mac-notification is disabled
|
||||
Member of active trunk ports 1/1/1,1/1/2,1/1/4,lg11, Lag Interface is lg11
|
||||
Member of configured trunk ports 1/1/1,1/1/2,1/1/4,lg11, Lag Interface is lg11
|
||||
Port name is test-interface-1
|
||||
IPG MII 0 bits-time, IPG GMII 0 bits-time
|
||||
MTU 1500 bytes, encapsulation ethernet
|
||||
MMU Mode is Store-and-forward
|
||||
300 second input rate: 88 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
300 second output rate: 616 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
14836 packets input, 2695975 bytes, 0 no buffer
|
||||
Received 3223 broadcasts, 11613 multicasts, 0 unicasts
|
||||
2 input errors, 2 CRC, 0 frame, 0 ignored
|
||||
0 runts, 0 giants
|
||||
64676 packets output, 5181136 bytes, 0 underruns
|
||||
Transmitted 28724 broadcasts, 35952 multicasts, 0 unicasts
|
||||
0 output errors, 0 collisions
|
||||
Relay Agent Information option: Disabled
|
||||
Protected: No
|
||||
MAC Port Security: Disabled
|
||||
|
||||
This port is not being monitored for queue drops
|
||||
Egress queues:
|
||||
Queue counters Queued packets Dropped Packets
|
||||
0 6682 0
|
||||
1 0 0
|
||||
2 0 0
|
||||
3 0 0
|
||||
4 22042 0
|
||||
5 20 0
|
||||
6 33680 0
|
||||
7 2252 0
|
||||
|
||||
|
||||
Local port: 1/1/48
|
||||
Neighbor: 609c.9fe7.d15f, TTL 95 seconds
|
||||
+ Chassis ID (MAC address): 609c.9fe7.d130
|
||||
+ Port ID (MAC address): 609c.9fe7.d15f
|
||||
+ Time to live: 120 seconds
|
||||
+ System name : "ICX7150-48 Router"
|
||||
+ Port description : "GigabitEthernet1/1/48"
|
||||
+ System capabilities : bridge, router
|
||||
Enabled capabilities: bridge, router
|
||||
+ 802.3 MAC/PHY : auto-negotiation enabled
|
||||
Advertised capabilities: 10BaseT-HD, 10BaseT-FD, 100BaseTX-HD,
|
||||
100BaseTX-FD, fdxSPause, fdxBPause,
|
||||
1000BaseT-HD, 1000BaseT-FD
|
||||
Operational MAU type : 1000BaseT-FD
|
||||
+ Link aggregation: not capable
|
||||
+ Maximum frame size: 1522 octets
|
||||
+ Port VLAN ID: 1
|
||||
+ Management address (IPv4): 172.16.10.182
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
LLDP transmit interval : 30 seconds
|
||||
LLDP transmit hold multiplier : 4 (transmit TTL: 120 seconds)
|
||||
LLDP transmit delay : 2 seconds
|
||||
LLDP SNMP notification interval : 5 seconds
|
||||
LLDP reinitialize delay : 2 seconds
|
||||
LLDP-MED fast start repeat count : 3
|
||||
|
||||
LLDP maximum neighbors : 2048
|
||||
LLDP maximum neighbors per port : 4
|
||||
|
|
@ -0,0 +1 @@
|
|||
LLDP is not running
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
logging host 172.16.10.21
|
||||
logging host 172.16.10.21 udp-port 2000
|
||||
logging host 172.16.10.22
|
||||
logging host 172.16.10.23 udp-port 2500
|
||||
logging host 172.16.10.55 udp-port 2500
|
||||
logging facility local1
|
||||
logging host ipv6 2001:db8::1 udp-port 5500
|
||||
logging buffered 200
|
||||
no logging buffered critical
|
||||
no logging buffered debugging
|
||||
no logging buffered emergencies
|
||||
no logging buffered errors
|
||||
no logging buffered informational
|
||||
no logging buffered notifications
|
||||
logging enable rfc5424
|
||||
logging console
|
||||
logging persistence
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Sending 1, 16-byte ICMP Echo to 10.255.255.250, timeout 100 msec, TTL 64
|
||||
Type Control-c to abort
|
||||
Request timed out.
|
||||
No reply from remote host.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Sending 1, 16-byte ICMP Echo to 10.255.255.250, timeout 100 msec, TTL 64
|
||||
Type Control-c to abort
|
||||
Request timed out.
|
||||
No reply from remote host.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Sending 2, 16-byte ICMP Echo to 8.8.8.8, timeout 5000 msec, TTL 64
|
||||
Type Control-c to abort
|
||||
Reply from 8.8.8.8 : bytes=16 time=49ms TTL=45
|
||||
Reply from 8.8.8.8 : bytes=16 time=41ms TTL=45
|
||||
Success rate is 100 percent (2/2), round-trip min/avg/max=41/45/49 ms.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Sending 5, 16-byte ICMP Echo to 8.8.8.8, timeout 5000 msec, TTL 70
|
||||
Type Control-c to abort
|
||||
Reply from 8.8.8.8 : bytes=16 time=40ms TTL=45
|
||||
Reply from 8.8.8.8 : bytes=16 time=40ms TTL=45
|
||||
Reply from 8.8.8.8 : bytes=16 time=40ms TTL=45
|
||||
Reply from 8.8.8.8 : bytes=16 time=40ms TTL=45
|
||||
Reply from 8.8.8.8 : bytes=16 time=40ms TTL=45
|
||||
Success rate is 100 percent (5/5), round-trip min/avg/max=40/40/40 ms.
|
||||
|
|
@ -0,0 +1 @@
|
|||
Invalid size - valid range (0-10000)
|
||||
|
|
@ -0,0 +1 @@
|
|||
Bad value for TTL, valid range is from 1 to 255.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
ip route 172.16.0.0/16 10.0.0.8
|
||||
ip route 172.16.10.0/24 10.0.0.8
|
||||
ip route 192.0.0.0/8 10.10.15.3
|
||||
ip route 192.126.0.0/16 10.10.14.31
|
||||
ip route 192.126.23.0/24 10.10.14.31
|
||||
ip route 192.128.0.0/16 10.10.14.3
|
||||
ip route 192.128.0.0/16 10.10.15.3
|
||||
ip route 192.128.0.0/16 10.10.15.31
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
ip dns domain-list ansib.eg.com
|
||||
ip dns domain-list red.com
|
||||
ip dns domain-list test1.com
|
||||
ip dns server-address 10.22.22.64
|
||||
ip dns server-address 172.22.22.64
|
||||
radius-server host 172.16.20.14 auth-port 1837 acct-port 5021 accounting-only key database mac-auth
|
||||
tacacs-server host 182.16.10.20
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
************show vlan brief*****************
|
||||
System-max vlan Params: Max(4095) Default(64) Current(64)
|
||||
Default vlan Id :1
|
||||
Total Number of Vlan Configured :5
|
||||
VLANs Configured :1 3 6 10 21
|
||||
|
||||
|
||||
************* show vlan id**********
|
||||
Maximum PORT-VLAN entries: 64
|
||||
|
||||
Legend: [Stk=Stack-Id, S=Slot]
|
||||
|
||||
PORT-VLAN 3, Name vlan, Priority level0, Spanning tree On
|
||||
Untagged Ports: (U1/M1) 1 2 3 4 5 7 20 21 22 23 24 25
|
||||
Untagged Ports: (U1/M1) 26 27 28
|
||||
Untagged Ports: (LAG) 11 12 15
|
||||
Tagged Ports: (U1/M1) 9 10 11 31
|
||||
Tagged Ports: (LAG) 13
|
||||
Uplink Ports: None
|
||||
DualMode Ports: None
|
||||
Mac-Vlan Ports: None
|
||||
Monitoring: Disabled
|
||||
|
||||
************* show run vlan id**********
|
||||
vlan 3 name vlan by port
|
||||
tagged ethe 1/1/31 ethe 1/1/9 to 1/1/11 lag 13
|
||||
untagged ethe 1/1/27 ethe 1/1/20 to 1/1/22 lag 11 to 12
|
||||
spanning-tree
|
||||
!
|
||||
!
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
lag LAG1 dynamic id 100
|
||||
ports ethe 1/1/3 ethe 1/1/5 to 1/1/8
|
||||
disable ethe 1/1/3 ethe 1/1/5 to 1/1/8
|
||||
!
|
||||
lag LAG2 dynamic id 200
|
||||
ports ethe 1/1/11 ethe 1/1/13 ethe 1/1/15
|
||||
disable ethe 1/1/11 ethe 1/1/13 ethe 1/1/15
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Stack unit 1:
|
||||
NAND Type: Micron NAND 2GiB (x 1)
|
||||
Compressed Pri Code size = 25966800, Version:08.0.80bT211 (primary.bin)
|
||||
Compressed Sec Code size = 29451996, Version:08.0.70dT213 (SPR08070d.bin)
|
||||
Compressed Boot-Monitor Image size = 786944, Version:10.1.09T225
|
||||
Code Flash Free Space = 1318699008
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
GigabitEthernet1/1/1 is down, line protocol is down
|
||||
Port down for 2 day(s) 23 hour(s) 4 minute(s) 18 second(s)
|
||||
Hardware is GigabitEthernet, address is 609c.9fe7.d600 (bia 609c.9fe7.d600)
|
||||
Configured speed 10Mbit, actual unknown, configured duplex fdx, actual unknown
|
||||
Configured mdi mode AUTO, actual unknown
|
||||
Member of L2 VLAN ID 1, port is untagged, port state is BLOCKING
|
||||
BPDU guard is Disabled, ROOT protect is Disabled, Designated protect is Disabled
|
||||
Link Error Dampening is Disabled
|
||||
STP configured to ON, priority is level0, mac-learning is enabled
|
||||
Openflow is Disabled, Openflow Hybrid mode is Disabled, Flow Control is config enabled, oper enabled, negotiation disabled
|
||||
Mirror disabled, Monitor disabled
|
||||
Mac-notification is disabled
|
||||
Not member of any active trunks
|
||||
Not member of any configured trunks
|
||||
Port name is test name
|
||||
IPG MII 0 bits-time, IPG GMII 0 bits-time
|
||||
Internet address is 192.168.1.1/24, MTU 1500 bytes, encapsulation ethernet
|
||||
MMU Mode is Store-and-forward
|
||||
300 second input rate: 0 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
300 second output rate: 0 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
0 packets input, 0 bytes, 0 no buffer
|
||||
Received 0 broadcasts, 0 multicasts, 0 unicasts
|
||||
0 input errors, 0 CRC, 0 frame, 0 ignored
|
||||
0 runts, 0 giants
|
||||
0 packets output, 0 bytes, 0 underruns
|
||||
Transmitted 0 broadcasts, 0 multicasts, 0 unicasts
|
||||
0 output errors, 0 collisions
|
||||
Relay Agent Information option: Disabled
|
||||
Protected: No
|
||||
MAC Port Security: Disabled
|
||||
|
||||
This port is not being monitored for queue drops
|
||||
Egress queues:
|
||||
Queue counters Queued packets Dropped Packets
|
||||
0 0 0
|
||||
1 0 0
|
||||
2 0 0
|
||||
3 0 0
|
||||
4 0 0
|
||||
5 0 0
|
||||
6 0 0
|
||||
7 0 0
|
||||
|
||||
GigabitEthernet1/1/2 is down, line protocol is down
|
||||
Port down for 2 day(s) 23 hour(s) 4 minute(s) 18 second(s)
|
||||
Hardware is GigabitEthernet, address is 609c.9fe7.d601 (bia 609c.9fe7.d601)
|
||||
Configured speed auto, actual unknown, configured duplex fdx, actual unknown
|
||||
Configured mdi mode AUTO, actual unknown
|
||||
Member of L2 VLAN ID 1, port is untagged, port state is BLOCKING
|
||||
BPDU guard is Disabled, ROOT protect is Disabled, Designated protect is Disabled
|
||||
Link Error Dampening is Disabled
|
||||
STP configured to ON, priority is level0, mac-learning is enabled
|
||||
Openflow is Disabled, Openflow Hybrid mode is Disabled, Flow Control is config enabled, oper enabled, negotiation disabled
|
||||
Mirror disabled, Monitor disabled
|
||||
Mac-notification is disabled
|
||||
Not member of any active trunks
|
||||
Not member of any configured trunks
|
||||
No port name
|
||||
IPG MII 0 bits-time, IPG GMII 0 bits-time
|
||||
MTU 1500 bytes, encapsulation ethernet
|
||||
MMU Mode is Store-and-forward
|
||||
300 second input rate: 0 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
300 second output rate: 0 bits/sec, 0 packets/sec, 0.00% utilization
|
||||
0 packets input, 0 bytes, 0 no buffer
|
||||
Received 0 broadcasts, 0 multicasts, 0 unicasts
|
||||
0 input errors, 0 CRC, 0 frame, 0 ignored
|
||||
0 runts, 0 giants
|
||||
0 packets output, 0 bytes, 0 underruns
|
||||
Transmitted 0 broadcasts, 0 multicasts, 0 unicasts
|
||||
0 output errors, 0 collisions
|
||||
Relay Agent Information option: Disabled
|
||||
Protected: No
|
||||
MAC Port Security: Disabled
|
||||
|
||||
This port is not being monitored for queue drops
|
||||
Egress queues:
|
||||
Queue counters Queued packets Dropped Packets
|
||||
0 0 0
|
||||
1 0 0
|
||||
2 0 0
|
||||
3 0 0
|
||||
4 0 0
|
||||
5 0 0
|
||||
6 0 0
|
||||
7 0 0
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
LLDP transmit interval : 30 seconds
|
||||
LLDP transmit hold multiplier : 4 (transmit TTL: 120 seconds)
|
||||
LLDP transmit delay : 2 seconds
|
||||
LLDP SNMP notification interval : 5 seconds
|
||||
LLDP reinitialize delay : 2 seconds
|
||||
LLDP-MED fast start repeat count : 3
|
||||
|
||||
LLDP maximum neighbors : 2048
|
||||
LLDP maximum neighbors per port : 4
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Port 1/1/1: Type : 1G M-C (Gig-Copper)
|
||||
Port 1/1/2: Type : 1G M-C (Gig-Copper)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Stack unit 1:
|
||||
Total DRAM: 954695680 bytes
|
||||
Dynamic memory: 954695680 bytes total, 375963648 bytes free, 60% used
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
Current configuration:
|
||||
!
|
||||
ver 08.0.70dT213
|
||||
!
|
||||
stack unit 1
|
||||
module 1 icx7150-48-port-management-module
|
||||
module 2 icx7150-2-copper-port-2g-module
|
||||
module 3 icx7150-4-sfp-plus-port-40g-module
|
||||
!
|
||||
!
|
||||
!
|
||||
lag LAG1 dynamic id 100
|
||||
ports ethe 1/1/4 to 1/1/7
|
||||
!
|
||||
lag LAG2 dynamic id 200
|
||||
ports ethe 1/1/12 to 1/1/15
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
aaa authentication enable implicit-user
|
||||
aaa authentication login default local
|
||||
enable super-user-password .....
|
||||
hostname ruchusRouter148
|
||||
ip dns domain-list fileserver.alethea.in
|
||||
ip dns server-address 8.8.8.8
|
||||
!
|
||||
username alethea password .....
|
||||
username ale6 password .....
|
||||
!
|
||||
!
|
||||
banner exec ^C
|
||||
welcome icx exec^C
|
||||
^C
|
||||
!
|
||||
banner motd ^C
|
||||
welcome icx motd^C
|
||||
^C
|
||||
!
|
||||
banner incoming ^C
|
||||
welcome icx incomingg^C
|
||||
^C
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
interface management 1
|
||||
no ip dhcp-client enable
|
||||
ip address 10.10.10.148 255.255.255.0
|
||||
!
|
||||
interface ethernet 1/1/1
|
||||
port-name test name
|
||||
ip address 192.168.1.1 255.255.255.0
|
||||
ipv6 address 2001:db8:85a3::8a2e:370:7334/64
|
||||
speed-duplex 10-full
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
lldp run
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
end
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
router-interface ve 1
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
aaa authentication enable implicit-user
|
||||
aaa authentication login default local
|
||||
enable super-user-password .....
|
||||
hostname ruchusRouter148
|
||||
ip dns domain-list fileserver.alethea.in
|
||||
ip dns server-address 8.8.8.8
|
||||
!
|
||||
username alethea password .....
|
||||
username ale6 password .....
|
||||
!
|
||||
!
|
||||
banner exec ^C
|
||||
welcome icx exec^C
|
||||
^C
|
||||
!
|
||||
banner motd ^C
|
||||
welcome icx motd^C
|
||||
^C
|
||||
!
|
||||
banner incoming ^C
|
||||
welcome icx incomingg^C
|
||||
^C
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
interface management 1
|
||||
no ip dhcp-client enable
|
||||
ip address 10.10.10.148 255.255.255.0
|
||||
!
|
||||
interface ethernet 1/1/1
|
||||
port-name test name
|
||||
ip address 192.160.1.1 255.255.255.0
|
||||
ipv6 address 2001:db8:85a3::8a2e:370:7334/64
|
||||
ipv6 address 2001:db8:85a3:0:0:0:0:0/64
|
||||
ip address 192.168.1.1 255.255.255.0
|
||||
ipv6 ospf area 1
|
||||
ip ospf area 2
|
||||
speed-duplex 10-full
|
||||
!
|
||||
interface ethernet 1/1/2
|
||||
ip address 192.161.1.1 255.255.255.0
|
||||
ip address 192.168.255.1 255.255.255.0
|
||||
!
|
||||
interface ve 1
|
||||
ip address 10.1.2.1 255.255.255.0
|
||||
ip address 192.163.1.1 255.255.255.0
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
lldp run
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
!
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
hostname ruchusRouter148
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
username ale1 privilege 5 password .....
|
||||
username ale1 expires 3
|
||||
username ale2 privilege 5 password .....
|
||||
username ale2 expires 3
|
||||
username ale3 privilege 5 password .....
|
||||
username ale3 expires 3
|
||||
username ale4 privilege 5 password .....
|
||||
username ale4 expires 3
|
||||
26
tests/unit/plugins/modules/network/icx/fixtures/show_version
Normal file
26
tests/unit/plugins/modules/network/icx/fixtures/show_version
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
Copyright (c) 1996-2017 Brocade Communications Systems, Inc. All rights reserved.
|
||||
UNIT 1: compiled on Feb 17 2017 at 16:03:13 labeled as SPS08060
|
||||
(23946048 bytes) from Secondary SPS08060.bin
|
||||
SW: Version 08.0.60T211
|
||||
Compressed Boot-Monitor Image size = 786944, Version:10.1.09T225 (mnz10109)
|
||||
Compiled on Sat Feb 18 00:15:43 2017
|
||||
|
||||
HW: Stackable ICX7150-48-POE
|
||||
==========================================================================
|
||||
UNIT 1: SL 1: ICX7150-48P-4X1G POE 48-port Management Module
|
||||
Serial #:FEC3220N00C
|
||||
Current License: 4X1G
|
||||
P-ASIC 0: type B160, rev 11 Chip BCM56160_B0
|
||||
==========================================================================
|
||||
UNIT 1: SL 2: ICX7150-2X1GC 2-port 2G Module
|
||||
==========================================================================
|
||||
UNIT 1: SL 3: ICX7150-4X10GF 4-port 40G Module
|
||||
==========================================================================
|
||||
1000 MHz ARM processor ARMv7 88 MHz bus
|
||||
8192 KB boot flash memory
|
||||
2048 MB code flash memory
|
||||
1024 MB DRAM
|
||||
STACKID 1 system uptime is 4 day(s) 19 hour(s) 53 minute(s) 5 second(s)
|
||||
The system started at 00:01:49 GMT+00 Sat Jan 01 2000
|
||||
|
||||
The system : started=cold start
|
||||
1
tests/unit/plugins/modules/network/icx/fixtures/skip
Normal file
1
tests/unit/plugins/modules/network/icx/fixtures/skip
Normal file
|
|
@ -0,0 +1 @@
|
|||
Disable page display mode
|
||||
93
tests/unit/plugins/modules/network/icx/icx_module.py
Normal file
93
tests/unit/plugins/modules/network/icx/icx_module.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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 TestICXModule(ModuleTestCase):
|
||||
ENV_ICX_USE_DIFF = True
|
||||
|
||||
def set_running_config(self):
|
||||
self.ENV_ICX_USE_DIFF = self.get_running_config()
|
||||
|
||||
def get_running_config(self, compare=None):
|
||||
if compare is not None:
|
||||
diff = compare
|
||||
elif os.environ.get('ANSIBLE_CHECK_ICX_RUNNING_CONFIG') is not None:
|
||||
if os.environ.get('ANSIBLE_CHECK_ICX_RUNNING_CONFIG') == 'False':
|
||||
diff = False
|
||||
else:
|
||||
diff = True
|
||||
else:
|
||||
diff = True
|
||||
return diff
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False, fields=None):
|
||||
|
||||
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']))
|
||||
else:
|
||||
self.assertEqual(commands, result['commands'], result['commands'])
|
||||
|
||||
if fields is not None:
|
||||
for key in fields:
|
||||
if fields.get(key) is not None:
|
||||
self.assertEqual(fields.get(key), result.get(key))
|
||||
|
||||
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
|
||||
96
tests/unit/plugins/modules/network/icx/test_icx_banner.py
Normal file
96
tests/unit/plugins/modules/network/icx/test_icx_banner.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_banner
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXBannerModule(TestICXModule):
|
||||
|
||||
module = icx_banner
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXBannerModule, self).setUp()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_banner.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_banner.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_banner.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXBannerModule, self).tearDown()
|
||||
self.mock_exec_command.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('icx_banner_show_banner.txt').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.exec_command.return_value = (0, '', None)
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_icx_banner_create(self):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
set_module_args(dict(banner='motd', text='welcome\nnew user'))
|
||||
commands = ['banner motd $\nwelcome\nnew user\n$']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
for banner_type in ('motd', 'exec', 'incoming'):
|
||||
set_module_args(dict(banner=banner_type, text='test\nbanner\nstring'))
|
||||
commands = ['banner {0} $\ntest\nbanner\nstring\n$'.format(banner_type)]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_banner_remove(self):
|
||||
set_module_args(dict(banner='motd', state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['no banner motd']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
commands = ['no banner motd']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_banner_motd_enter_set(self):
|
||||
set_module_args(dict(banner='motd', enterkey=True))
|
||||
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['banner motd require-enter-key']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_icx_banner_motd_enter_remove(self):
|
||||
set_module_args(dict(banner='motd', state='absent', enterkey=False))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['no banner motd', 'no banner motd require-enter-key']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
else:
|
||||
commands = ['no banner motd', 'no banner motd require-enter-key']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_banner_remove_compare(self):
|
||||
set_module_args(dict(banner='incoming', state='absent', check_running_config='True'))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = []
|
||||
self.execute_module(changed=False, commands=commands)
|
||||
else:
|
||||
commands = []
|
||||
self.execute_module()
|
||||
113
tests/unit/plugins/modules/network/icx/test_icx_command.py
Normal file
113
tests/unit/plugins/modules/network/icx/test_icx_command.py
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_command
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXCommandModule(TestICXModule):
|
||||
|
||||
module = icx_command
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXCommandModule, self).setUp()
|
||||
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_command.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXCommandModule, 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:
|
||||
if item == 'skip':
|
||||
continue
|
||||
obj = json.loads(item['command'])
|
||||
command = obj['command']
|
||||
except ValueError:
|
||||
command = item['command']
|
||||
filename = str(command).replace(' ', '_')
|
||||
output.append(load_fixture(filename))
|
||||
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_icx_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('Copyright (c) 1996-2017 Brocade Communications Systems'))
|
||||
|
||||
def test_icx_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('Copyright (c) 1996-2017 Brocade Communications Systems'))
|
||||
|
||||
def test_icx_command_wait_for(self):
|
||||
wait_for = 'result[0] contains "ICX"'
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for))
|
||||
self.execute_module()
|
||||
|
||||
def test_icx_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)
|
||||
# run_commands call count is 1(skip) + 10(current)
|
||||
self.assertEqual(self.run_commands.call_count, 11)
|
||||
|
||||
def test_icx_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, 3)
|
||||
|
||||
def test_icx_command_match_any(self):
|
||||
wait_for = ['result[0] contains "ICX"',
|
||||
'result[0] contains "test string"']
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any'))
|
||||
self.execute_module()
|
||||
|
||||
def test_icx_command_match_all(self):
|
||||
wait_for = ['result[0] contains "ICX"',
|
||||
'result[0] contains "Version:10.1.09T225"']
|
||||
set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all'))
|
||||
self.execute_module()
|
||||
|
||||
def test_icx_command_match_all_failure(self):
|
||||
wait_for = ['result[0] contains "ICX"',
|
||||
'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)
|
||||
|
||||
def test_icx_command_configure_check_warning(self):
|
||||
commands = ['configure terminal']
|
||||
set_module_args({
|
||||
'commands': commands,
|
||||
'_ansible_check_mode': True,
|
||||
})
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['warnings'],
|
||||
['Only show commands are supported when using check mode, not executing configure terminal'],
|
||||
)
|
||||
|
||||
def test_icx_command_configure_not_warning(self):
|
||||
commands = ['configure terminal']
|
||||
set_module_args(dict(commands=commands))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(result['warnings'], [])
|
||||
219
tests/unit/plugins/modules/network/icx/test_icx_config.py
Normal file
219
tests/unit/plugins/modules/network/icx/test_icx_config.py
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock
|
||||
from ansible_collections.community.general.plugins.modules.network.icx import icx_config
|
||||
from ansible_collections.community.general.plugins.cliconf.icx import Cliconf
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXConfigModule(TestICXModule):
|
||||
|
||||
module = icx_config
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXConfigModule, self).setUp()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_config.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_get_connection = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_config.get_connection')
|
||||
self.get_connection = self.mock_get_connection.start()
|
||||
|
||||
self.conn = self.get_connection()
|
||||
self.conn.edit_config = MagicMock()
|
||||
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_config.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
self.cliconf_obj = Cliconf(MagicMock())
|
||||
self.running_config = load_fixture('icx_config_config.cfg')
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXConfigModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_get_connection.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
config_file = 'icx_config_config.cfg'
|
||||
self.get_config.return_value = load_fixture(config_file)
|
||||
self.get_connection.edit_config.return_value = None
|
||||
|
||||
def test_icx_config_unchanged(self):
|
||||
src = load_fixture('icx_config_config.cfg')
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, src))
|
||||
set_module_args(dict(src=src))
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_icx_config_src(self):
|
||||
src = load_fixture('icx_config_src.cfg')
|
||||
set_module_args(dict(src=src))
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config))
|
||||
commands = ['hostname foo', 'interface ethernet 1/1/4',
|
||||
'disable']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_config_backup(self):
|
||||
set_module_args(dict(backup=True))
|
||||
result = self.execute_module()
|
||||
self.assertIn('__backup__', result)
|
||||
|
||||
def test_icx_config_save_always(self):
|
||||
self.run_commands.return_value = "Hostname foo"
|
||||
set_module_args(dict(save_when='always'))
|
||||
self.execute_module(changed=True)
|
||||
self.assertEqual(self.run_commands.call_count, 2)
|
||||
self.assertEqual(self.get_config.call_count, 0)
|
||||
self.assertEqual(self.conn.edit_config.call_count, 0)
|
||||
args = self.run_commands.call_args[0][1]
|
||||
self.assertIn('write memory', args)
|
||||
|
||||
def test_icx_config_save_changed_false(self):
|
||||
set_module_args(dict(save_when='changed'))
|
||||
self.execute_module(changed=False)
|
||||
self.assertEqual(self.run_commands.call_count, 1)
|
||||
self.assertEqual(self.get_config.call_count, 0)
|
||||
self.assertEqual(self.conn.edit_config.call_count, 0)
|
||||
|
||||
def test_icx_config_lines_wo_parents(self):
|
||||
lines = ['hostname foo']
|
||||
set_module_args(dict(lines=lines))
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config))
|
||||
commands = ['hostname foo']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_config_lines_w_parents(self):
|
||||
lines = ['disable']
|
||||
parents = ['interface ethernet 1/1/4']
|
||||
set_module_args(dict(lines=lines, parents=parents))
|
||||
module = MagicMock()
|
||||
module.params = {'lines': lines, 'parents': parents, 'src': None}
|
||||
candidate_config = icx_config.get_candidate_config(module)
|
||||
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config))
|
||||
|
||||
commands = ['interface ethernet 1/1/4', 'disable']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_config_before_after_no_change(self):
|
||||
lines = ['hostname router']
|
||||
set_module_args(dict(lines=lines,
|
||||
before=['test1', 'test2'],
|
||||
after=['test3', 'test4']))
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config))
|
||||
self.execute_module()
|
||||
|
||||
def test_icx_config_config(self):
|
||||
config = 'hostname localhost'
|
||||
lines = ['hostname router']
|
||||
set_module_args(dict(lines=lines, config=config))
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), config))
|
||||
commands = ['hostname router']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_config_replace_block(self):
|
||||
lines = ['port-name test string', 'test string']
|
||||
parents = ['interface ethernet 1/1/4']
|
||||
set_module_args(dict(lines=lines, replace='block', parents=parents))
|
||||
|
||||
module = MagicMock()
|
||||
module.params = {'lines': lines, 'parents': parents, 'src': None}
|
||||
candidate_config = icx_config.get_candidate_config(module)
|
||||
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_replace='block', path=parents))
|
||||
|
||||
commands = parents + lines
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_config_match_none(self):
|
||||
lines = ['hostname router']
|
||||
set_module_args(dict(lines=lines, match='none'))
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff('\n'.join(lines), self.running_config, diff_match='none'))
|
||||
self.execute_module(changed=True, commands=lines)
|
||||
|
||||
def test_icx_config_match_none_block(self):
|
||||
lines = ['speed-duplex 10-full', 'port-name test-interface-4']
|
||||
parents = ['interface ethernet 1/1/4']
|
||||
set_module_args(dict(lines=lines, parents=parents, match='none'))
|
||||
|
||||
module = MagicMock()
|
||||
module.params = {'lines': lines, 'parents': parents, 'src': None}
|
||||
candidate_config = icx_config.get_candidate_config(module)
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_match='none', path=parents))
|
||||
|
||||
commands = parents + lines
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_icx_config_match_strict(self):
|
||||
lines = ['port-name test-interface-4', 'speed-duplex 10-full',
|
||||
'disable']
|
||||
parents = ['interface ethernet 1/1/4']
|
||||
set_module_args(dict(lines=lines, parents=parents, match='strict'))
|
||||
|
||||
module = MagicMock()
|
||||
module.params = {'lines': lines, 'parents': parents, 'src': None}
|
||||
candidate_config = icx_config.get_candidate_config(module)
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_match='strict', path=parents))
|
||||
|
||||
commands = parents + ['disable']
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_icx_config_match_exact(self):
|
||||
lines = ['speed-duplex 10-full', 'port-name test-interface-4',
|
||||
'disable']
|
||||
parents = ['interface ethernet 1/1/4']
|
||||
set_module_args(dict(lines=lines, parents=parents, match='exact'))
|
||||
|
||||
module = MagicMock()
|
||||
module.params = {'lines': lines, 'parents': parents, 'src': None}
|
||||
candidate_config = icx_config.get_candidate_config(module)
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate_config, self.running_config, diff_match='exact', path=parents))
|
||||
|
||||
commands = parents + lines
|
||||
self.execute_module(changed=True, commands=commands, sort=False)
|
||||
|
||||
def test_icx_config_src_and_lines_fails(self):
|
||||
args = dict(src='foo', lines='foo')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_src_and_parents_fails(self):
|
||||
args = dict(src='foo', parents='foo')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_match_exact_requires_lines(self):
|
||||
args = dict(match='exact')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_match_strict_requires_lines(self):
|
||||
args = dict(match='strict')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_replace_block_requires_lines(self):
|
||||
args = dict(replace='block')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_replace_config_requires_src(self):
|
||||
args = dict(replace='config')
|
||||
set_module_args(args)
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_config_save_changed_true(self):
|
||||
src = load_fixture('icx_config_src.cfg')
|
||||
set_module_args(dict(src=src, save_when='changed'))
|
||||
commands = ['hostname foo', 'interface ethernet 1/1/4', 'disable']
|
||||
self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config))
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
self.assertEqual(self.run_commands.call_count, 2)
|
||||
self.assertEqual(self.get_config.call_count, 1)
|
||||
self.assertEqual(self.conn.edit_config.call_count, 1)
|
||||
args = self.run_commands.call_args[0][1]
|
||||
self.assertIn('write memory', args)
|
||||
204
tests/unit/plugins/modules/network/icx/test_icx_copy.py
Normal file
204
tests/unit/plugins/modules/network/icx/test_icx_copy.py
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_copy
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXSCPModule(TestICXModule):
|
||||
|
||||
module = icx_copy
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXSCPModule, self).setUp()
|
||||
self.mock_exec_scp = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_copy.exec_scp')
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_copy.run_commands')
|
||||
self.exec_command = self.mock_exec_scp.start()
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_copy.exec_command')
|
||||
self.exec_commands = self.mock_exec_command.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXSCPModule, self).tearDown()
|
||||
self.mock_exec_scp.stop()
|
||||
self.mock_run_commands.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.exec_commands.return_value = (0, load_fixture('icx_copy.txt').strip(), None)
|
||||
# self.exec_command.return_value = (0, load_fixture('icx_banner_show_banner.txt').strip(), None)
|
||||
if(commands is not None):
|
||||
fixtureName = commands[0].replace(" ", "_") + ".txt"
|
||||
# print("loading fixture: ",load_fixture(fixtureName).strip())
|
||||
self.mock_exec_scp.return_value = load_fixture("icx_copy.txt").strip()
|
||||
self.mock_run_commands.return_value = load_fixture("icx_copy.txt").strip()
|
||||
else:
|
||||
self.exec_command.return_value = ""
|
||||
|
||||
def test_icx_scp_upload_running(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='running-config',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='running.conf',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy running-config scp 172.16.10.49 running.conf']
|
||||
self.execute_module(commands=commands)
|
||||
|
||||
def test_icx_scp_download_running(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='running-config',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='running.conf',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy scp running-config 172.16.10.49 running.conf']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_scp_upload_startup(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='startup-config',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='running.conf',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy startup-config scp 172.16.10.49 running.conf']
|
||||
self.execute_module(commands=commands, changed=False)
|
||||
|
||||
def test_icx_scp_download_startup(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='startup-config',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='running.conf',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy scp startup-config 172.16.10.49 running.conf']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_scp_upload_primary(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='flash_primary',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='SPS08080b.bin',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy flash scp 172.16.10.49 SPS08080b.bin primary']
|
||||
self.execute_module(commands=commands, changed=False)
|
||||
|
||||
def test_icx_scp_download_primary(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='flash_primary',
|
||||
protocol='scp',
|
||||
remote_server='172.16.10.49',
|
||||
remote_filename='SPS08080b.bin',
|
||||
remote_user='alethea',
|
||||
remote_pass='alethea123'))
|
||||
commands = ['copy scp flash 172.16.10.49 SPS08080b.bin primary']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
# HTTPS tests
|
||||
|
||||
def test_icx_https_upload_running(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='running-config',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/upload_running'))
|
||||
commands = ['copy running-config https fileserver.alethea.in filestorage/test/upload_running']
|
||||
self.execute_module(commands=commands)
|
||||
|
||||
def test_icx_https_download_running(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='running-config',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/running.conf'))
|
||||
commands = ['copy https running-config fileserver.alethea.in filestorage/test/running.conf']
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_icx_https_upload_startup(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='startup-config',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/upload_startup'))
|
||||
commands = ['copy startup-config https fileserver.alethea.in filestorage/test/upload_startup']
|
||||
self.execute_module(commands=commands)
|
||||
|
||||
def test_icx_https_download_startup(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='startup-config',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/startup.conf'))
|
||||
commands = ['copy https startup-config fileserver.alethea.in filestorage/test/startup.conf']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_https_upload_primary(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='flash_primary',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/upload_primary'))
|
||||
commands = ['copy startup-config https fileserver.alethea.in filestorage/test/upload_primary']
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_icx_https_download_primary(self):
|
||||
set_module_args(dict(download='flash_primary', protocol='https', remote_server='fileserver.alethea.in', remote_filename='filestorage/test/primary.bin'))
|
||||
commands = ['copy https flash fileserver.alethea.in filestorage/test/primary.bin primary']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_https_upload_secondary(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='flash_secondary',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/upload_secondary'))
|
||||
commands = ['copy flash https fileserver.alethea.in filestorage/test/upload_secondary secondary']
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_icx_https_download_secondary(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
download='flash_secondary',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/secondary.bin'))
|
||||
commands = ['copy https flash fileserver.alethea.in filestorage/test/secondary.bin secondary']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_https_upload_download(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
upload='flash_secondary',
|
||||
download='flash_secondary',
|
||||
protocol='https',
|
||||
remote_server='fileserver.alethea.in',
|
||||
remote_filename='filestorage/test/secondary.bin'))
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_icx_scp_no_user(self):
|
||||
set_module_args(dict(upload='running-config', protocol='scp', remote_server='172.16.10.49', remote_filename='running.conf'))
|
||||
self.execute_module(failed=True)
|
||||
137
tests/unit/plugins/modules/network/icx/test_icx_facts.py
Normal file
137
tests/unit/plugins/modules/network/icx/test_icx_facts.py
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_facts
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXFactsModule(TestICXModule):
|
||||
|
||||
module = icx_facts
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXFactsModule, self).setUp()
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_facts.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXFactsModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
commands = kwargs['commands']
|
||||
if(commands):
|
||||
resp = list()
|
||||
for cmd in commands:
|
||||
fixtureName = cmd.replace(" ", "_")
|
||||
newFixtureName = fixtureName.replace("_|_", "_")
|
||||
output = load_fixture(newFixtureName).strip()
|
||||
if(output):
|
||||
resp.append(output)
|
||||
return resp
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_icx_facts_default(self):
|
||||
set_module_args(dict(gather_subset=["default"]))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_model'], 'Stackable ICX7150-48-POE'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_serialnum'], 'FEC3220N00C'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_version'], '08.0.60T211'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_hostname'], 'ruchusRouter148'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_image'], 'SPS08060.bin'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_stacked_models'], ['ICX7150-48P-4X1G', 'ICX7150-2X1GC', 'ICX7150-4X10GF']
|
||||
)
|
||||
|
||||
def test_icx_facts_interfaces(self):
|
||||
set_module_args(dict(gather_subset=["interfaces"]))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["macaddress"], "609c.9fe7.d600"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["ipv4"]["address"], "192.168.1.1"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["ipv4"]["subnet"], "24"
|
||||
)
|
||||
|
||||
def test_icx_facts_hardware(self):
|
||||
set_module_args(dict(gather_subset=["hardware"]))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_filesystems'], "flash"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_filesystems_info'], {'flash': {'Stack unit 1': {'spacetotal': '2GiB', 'spacefree': '1287792Kb'}}}
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memfree_mb'], 367152
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memtotal_mb'], 932320
|
||||
)
|
||||
|
||||
def test_icx_facts_not_hardware(self):
|
||||
set_module_args(dict(gather_subset=["!hardware"]))
|
||||
result = self.execute_module()
|
||||
print(result)
|
||||
|
||||
def test_icx_facts_all(self):
|
||||
set_module_args(dict(gather_subset=["all"]))
|
||||
result = self.execute_module()
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_filesystems'], "flash"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_filesystems_info'], {'flash': {'Stack unit 1': {'spacetotal': '2GiB', 'spacefree': '1287792Kb'}}}
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memfree_mb'], 367152
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_memtotal_mb'], 932320
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["macaddress"], "609c.9fe7.d600"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["ipv4"]["address"], "192.168.1.1"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_interfaces']["GigabitEthernet1/1/1"]["ipv4"]["subnet"], "24"
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_model'], 'Stackable ICX7150-48-POE'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_serialnum'], 'FEC3220N00C'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_version'], '08.0.60T211'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_hostname'], 'ruchusRouter148'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_image'], 'SPS08060.bin'
|
||||
)
|
||||
self.assertEqual(
|
||||
result['ansible_facts']['ansible_net_stacked_models'], ['ICX7150-48P-4X1G', 'ICX7150-2X1GC', 'ICX7150-4X10GF']
|
||||
)
|
||||
208
tests/unit/plugins/modules/network/icx/test_icx_interface.py
Normal file
208
tests/unit/plugins/modules/network/icx/test_icx_interface.py
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_interface
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXInterfaceModule(TestICXModule):
|
||||
|
||||
module = icx_interface
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXInterfaceModule, self).setUp()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_interface.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_interface.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_interface.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXInterfaceModule, self).tearDown()
|
||||
self.mock_exec_command.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module, commands, val = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
self.exec_command.return_value = (0, load_fixture('icx_interface_config.cfg').strip(), None)
|
||||
return load_fixture('icx_interface_config.cfg').strip()
|
||||
else:
|
||||
self.exec_command.return_value = 0, '', None
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_interface_set_config(self):
|
||||
power = dict(dict(enabled='True'))
|
||||
set_module_args(dict(name='ethernet 1/1/1', description='welcome port', speed='1000-full', power=power))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/1',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port',
|
||||
'inline power',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/1',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port',
|
||||
'inline power'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_interface_remove(self):
|
||||
set_module_args(dict(name='ethernet 1/1/1', state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no interface ethernet 1/1/1'])
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no interface ethernet 1/1/1'])
|
||||
|
||||
def test_icx_interface_disable(self):
|
||||
set_module_args(dict(name='ethernet 1/1/1', enabled=False))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['interface ethernet 1/1/1', 'disable'])
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['interface ethernet 1/1/1', 'disable'])
|
||||
|
||||
def test_icx_interface_set_power(self):
|
||||
power = dict(by_class='2')
|
||||
set_module_args(dict(name='ethernet 1/1/2', power=dict(power)))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/2',
|
||||
'inline power power-by-class 2',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/2',
|
||||
'inline power power-by-class 2'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_interface_aggregate(self):
|
||||
power = dict(dict(enabled='True'))
|
||||
aggregate = [
|
||||
dict(name='ethernet 1/1/9', description='welcome port9', speed='1000-full', power=power),
|
||||
dict(name='ethernet 1/1/10', description='welcome port10', speed='1000-full', power=power)
|
||||
]
|
||||
set_module_args(dict(aggregate=aggregate))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/9',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port9',
|
||||
'inline power',
|
||||
'enable',
|
||||
'interface ethernet 1/1/10',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port10',
|
||||
'inline power',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface ethernet 1/1/9',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port9',
|
||||
'inline power',
|
||||
'enable',
|
||||
'interface ethernet 1/1/10',
|
||||
'speed-duplex 1000-full',
|
||||
'port-name welcome port10',
|
||||
'inline power',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_interface_lag_config(self):
|
||||
set_module_args(dict(name='lag 11', description='lag ports of id 11', speed='auto'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface lag 11',
|
||||
'speed-duplex auto',
|
||||
'port-name lag ports of id 11',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface lag 11',
|
||||
'speed-duplex auto',
|
||||
'port-name lag ports of id 11'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_interface_loopback_config(self):
|
||||
set_module_args(dict(name='loopback 10', description='loopback ports', enabled=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface loopback 10',
|
||||
'port-name loopback ports',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'interface loopback 10',
|
||||
'port-name loopback ports',
|
||||
'enable'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_interface_state_up_cndt(self):
|
||||
set_module_args(dict(name='ethernet 1/1/1', state='up', tx_rate='ge(0)'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.assertTrue(self.execute_module(failed=True))
|
||||
else:
|
||||
self.assertTrue(self.execute_module(failed=False))
|
||||
|
||||
def test_icx_interface_lldp_neighbors_cndt(self):
|
||||
set_module_args(dict(name='ethernet 1/1/48', neighbors=[dict(port='GigabitEthernet1/1/48', host='ICX7150-48 Router')]))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.assertTrue(self.execute_module(changed=False, failed=True))
|
||||
else:
|
||||
self.assertTrue(self.execute_module(changed=False, failed=False))
|
||||
|
||||
def test_icx_interface_disable_compare(self):
|
||||
set_module_args(dict(name='ethernet 1/1/1', enabled=True, check_running_config='True'))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=False)
|
||||
self.assertEqual(result['commands'], [])
|
||||
else:
|
||||
result = self.execute_module(changed=False)
|
||||
self.assertEqual(result['commands'], [])
|
||||
121
tests/unit/plugins/modules/network/icx/test_icx_l3_interface.py
Normal file
121
tests/unit/plugins/modules/network/icx/test_icx_l3_interface.py
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_l3_interface
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXFactsModule(TestICXModule):
|
||||
|
||||
module = icx_l3_interface
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXFactsModule, self).setUp()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_l3_interface.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_l3_interface.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_l3_interface.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXFactsModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('show_running-config_begin_interface').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
def write_config(*args, **kwargs):
|
||||
return ""
|
||||
|
||||
self.get_config.side_effect = load_from_file
|
||||
self.load_config.side_effect = write_config
|
||||
|
||||
def test_icx_l3_interface_set_ipv4(self):
|
||||
set_module_args(dict(name="ethernet 1/1/1", ipv4="192.168.1.1/24"))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
"ip address 192.168.1.1 255.255.255.0",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
"ip address 192.168.1.1 255.255.255.0",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_l3_interface_set_ipv6(self):
|
||||
set_module_args(dict(name="ethernet 1/1/1", ipv6="2001:db8:85a3:0:0:0:0:1/64"))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
"ipv6 address 2001:db8:85a3:0:0:0:0:1/64",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
"ipv6 address 2001:db8:85a3:0:0:0:0:1/64",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_l3_interface_remove_ipv6(self):
|
||||
set_module_args(dict(name="ethernet 1/1/1", ipv6="2001:db8:85a3:0:0:0:0:0/64", ipv4="192.168.1.1/24", state="absent"))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
"no ip address 192.168.1.1 255.255.255.0",
|
||||
"no ipv6 address 2001:db8:85a3:0:0:0:0:0/64",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
"interface ethernet 1/1/1",
|
||||
'no ip address 192.168.1.1 255.255.255.0',
|
||||
"no ipv6 address 2001:db8:85a3:0:0:0:0:0/64",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_l3_interface_set_aggregate(self):
|
||||
set_module_args(dict(aggregate=[
|
||||
dict(name="ve 1", ipv6="2001:db8:85a3:0:0:0:0:0/64", ipv4="192.168.1.1/24")
|
||||
]))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
"interface ve 1",
|
||||
"ipv6 address 2001:db8:85a3:0:0:0:0:0/64",
|
||||
"ip address 192.168.1.1 255.255.255.0",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
"interface ve 1",
|
||||
"ipv6 address 2001:db8:85a3:0:0:0:0:0/64",
|
||||
"ip address 192.168.1.1 255.255.255.0",
|
||||
"exit"
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
123
tests/unit/plugins/modules/network/icx/test_icx_linkagg.py
Normal file
123
tests/unit/plugins/modules/network/icx/test_icx_linkagg.py
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_linkagg
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXLinkaggModule(TestICXModule):
|
||||
|
||||
module = icx_linkagg
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXLinkaggModule, self).setUp()
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_linkagg.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_linkagg.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_linkagg.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXLinkaggModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('lag_running_config.txt').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_from_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_linkage_create_new_LAG(self):
|
||||
set_module_args(dict(group=10, name="LAG3", mode='static', members=['ethernet 1/1/4 to ethernet 1/1/7']))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['lag LAG3 static id 10', 'ports ethernet 1/1/4 to ethernet 1/1/7', 'exit']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['lag LAG3 static id 10', 'ports ethernet 1/1/4 to ethernet 1/1/7', 'exit']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_linkage_modify_LAG(self):
|
||||
set_module_args(dict(group=100, name="LAG1", mode='dynamic', members=['ethernet 1/1/4 to 1/1/7']))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'ports ethernet 1/1/4 to 1/1/7',
|
||||
'exit'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'no ports ethernet 1/1/3',
|
||||
'no ports ethernet 1/1/8',
|
||||
'ports ethernet 1/1/4',
|
||||
'exit'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_linkage_modify_LAG_compare(self):
|
||||
set_module_args(dict(group=100, name="LAG1", mode='dynamic', members=['ethernet 1/1/4 to 1/1/7'], check_running_config=True))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'no ports ethernet 1/1/3',
|
||||
'no ports ethernet 1/1/8',
|
||||
'ports ethernet 1/1/4',
|
||||
'exit'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'no ports ethernet 1/1/3',
|
||||
'no ports ethernet 1/1/8',
|
||||
'ports ethernet 1/1/4',
|
||||
'exit'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_linkage_purge_LAG(self):
|
||||
set_module_args(dict(aggregate=[dict(group=100, name="LAG1", mode='dynamic')], purge=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'exit'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'lag LAG1 dynamic id 100',
|
||||
'exit',
|
||||
'no lag LAG2 dynamic id 200'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_linkage_remove_LAG(self):
|
||||
set_module_args(dict(group=100, name="LAG1", mode='dynamic', members=['ethernet 1/1/4 to 1/1/7'], state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'no lag LAG1 dynamic id 100'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'no lag LAG1 dynamic id 100'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
99
tests/unit/plugins/modules/network/icx/test_icx_lldp.py
Normal file
99
tests/unit/plugins/modules/network/icx/test_icx_lldp.py
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_lldp
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXlldpModule(TestICXModule):
|
||||
|
||||
module = icx_lldp
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXlldpModule, self).setUp()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_lldp.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_lldp.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXlldpModule, self).tearDown()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
compares = None
|
||||
module, commands = args
|
||||
state = module.params['state']
|
||||
if module.params['check_running_config'] is True:
|
||||
return load_fixture('icx_lldp_%s' % state).strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_icx_lldp_enable_state_None(self):
|
||||
interfaces_spec = [dict(name='ethernet 1/1/9', state='present')]
|
||||
set_module_args(dict(interfaces=interfaces_spec))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(failed=True)
|
||||
else:
|
||||
result = self.execute_module(failed=True)
|
||||
|
||||
def test_icx_lldp_enable_state_absent_compare(self):
|
||||
interfaces_spec = [dict(name='ethernet 1/1/9', state='present')]
|
||||
set_module_args(dict(interfaces=interfaces_spec, state='absent', check_running_config=True))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no lldp run'])
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no lldp run'])
|
||||
|
||||
def test_icx_lldp_enable_state_present(self):
|
||||
interfaces_spec = [dict(name='ethernet 1/1/9', state='present')]
|
||||
set_module_args(dict(interfaces=interfaces_spec, state='present'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['lldp enable ports ethernet 1/1/9'])
|
||||
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['lldp enable ports ethernet 1/1/9'])
|
||||
|
||||
def test_icx_lldp_multi_enable_state_present(self):
|
||||
interfaces_spec = [dict(name=['ethernet 1/1/9', 'ethernet 1/1/1 to 1/1/6'], state='present')]
|
||||
set_module_args(dict(interfaces=interfaces_spec, state='present'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['lldp enable ports ethernet 1/1/9', 'lldp enable ports ethernet 1/1/1 to 1/1/6'])
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['lldp enable ports ethernet 1/1/9', 'lldp enable ports ethernet 1/1/1 to 1/1/6'])
|
||||
|
||||
def test_icx_lldp_multi_disable_state_present(self):
|
||||
interfaces_spec = [dict(name=['ethernet 1/1/9', 'ethernet 1/1/1 to 1/1/6'], state='absent')]
|
||||
set_module_args(dict(interfaces=interfaces_spec, state='present'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no lldp enable ports ethernet 1/1/9', 'no lldp enable ports ethernet 1/1/1 to 1/1/6'])
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
self.assertEqual(result['commands'], ['no lldp enable ports ethernet 1/1/9', 'no lldp enable ports ethernet 1/1/1 to 1/1/6'])
|
||||
|
||||
def test_icx_lldp_all_error(self):
|
||||
interfaces_spec = [dict(name=['ethernet all'], state='absent')]
|
||||
set_module_args(dict(interfaces=interfaces_spec, state='present'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.execute_module(failed=True)
|
||||
else:
|
||||
self.execute_module(failed=True)
|
||||
149
tests/unit/plugins/modules/network/icx/test_icx_logging.py
Normal file
149
tests/unit/plugins/modules/network/icx/test_icx_logging.py
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_logging
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXLoggingModule(TestICXModule):
|
||||
|
||||
module = icx_logging
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXLoggingModule, self).setUp()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_logging.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_logging.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_logging.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXLoggingModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('icx_logging_config.cfg').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_logging_set_host(self):
|
||||
set_module_args(dict(dest='host', name='172.16.10.15'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['logging host 172.16.10.15']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
commands = ['logging host 172.16.10.15']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_logging_set_ipv6_host(self):
|
||||
set_module_args(dict(dest='host', name='2001:db8::1'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['logging host 2001:db8::1']
|
||||
else:
|
||||
commands = ['logging host 2001:db8::1']
|
||||
|
||||
def test_icx_logging_set_host_udp_port(self):
|
||||
set_module_args(dict(dest='host', name='172.16.10.15', udp_port=2500))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['logging host 172.16.10.15 udp-port 2500']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
commands = ['logging host 172.16.10.15 udp-port 2500']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_logging_remove_console(self):
|
||||
set_module_args(dict(dest='console', state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['no logging console']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
commands = ['no logging console']
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_logging_remove_on(self):
|
||||
set_module_args(dict(dest='on', state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['no logging on']
|
||||
self.exec_command(changed=True, commands=commands)
|
||||
else:
|
||||
commands = ['no logging on']
|
||||
self.exec_command(changed=True, commands=commands)
|
||||
|
||||
def test_icx_logging_set_aggregate(self):
|
||||
aggregate = [
|
||||
dict(dest='host', name='172.16.10.16', udp_port=2500, facility='local0'),
|
||||
dict(dest='host', name='2001:db8::1', udp_port=5000)
|
||||
]
|
||||
set_module_args(dict(aggregate=aggregate, state='present'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'logging facility local0',
|
||||
'logging host 172.16.10.16 udp-port 2500',
|
||||
'logging host ipv6 2001:db8::1 udp-port 5000'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'logging facility local0',
|
||||
'logging host 172.16.10.16 udp-port 2500',
|
||||
'logging host ipv6 2001:db8::1 udp-port 5000'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_logging_set_aggregate_remove(self):
|
||||
aggregate = [
|
||||
dict(dest='host', name='172.16.10.55', udp_port=2500, facility='local0'),
|
||||
dict(dest='host', name='2001:db8::1', udp_port=5500)
|
||||
]
|
||||
set_module_args(dict(aggregate=aggregate, state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'no logging facility',
|
||||
'no logging host 172.16.10.55 udp-port 2500',
|
||||
'no logging host ipv6 2001:db8::1 udp-port 5500'
|
||||
]
|
||||
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'no logging facility',
|
||||
'no logging host 172.16.10.55 udp-port 2500',
|
||||
'no logging host ipv6 2001:db8::1 udp-port 5500'
|
||||
]
|
||||
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_logging_compare(self):
|
||||
set_module_args(dict(dest='host', name='172.16.10.21', check_running_config=True))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.execute_module(changed=False)
|
||||
else:
|
||||
self.execute_module(changed=False)
|
||||
86
tests/unit/plugins/modules/network/icx/test_icx_ping.py
Normal file
86
tests/unit/plugins/modules/network/icx/test_icx_ping.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_ping
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXPingModule(TestICXModule):
|
||||
''' Class used for Unit Tests agains icx_ping module '''
|
||||
module = icx_ping
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXPingModule, self).setUp()
|
||||
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_ping.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXPingModule, self).tearDown()
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
commands = kwargs['commands']
|
||||
output = list()
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
output.append(load_fixture('icx_ping_%s' % filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_icx_ping_expected_success(self):
|
||||
''' Test for successful pings when destination should be reachable '''
|
||||
set_module_args(dict(count=2, dest="8.8.8.8"))
|
||||
commands = ['ping 8.8.8.8 count 2']
|
||||
fields = {'packets_tx': 2}
|
||||
self.execute_module(commands=commands, fields=fields)
|
||||
|
||||
def test_icx_ping_expected_failure(self):
|
||||
''' Test for unsuccessful pings when destination should not be reachable '''
|
||||
set_module_args(dict(count=2, dest="10.255.255.250", state="absent"))
|
||||
self.execute_module()
|
||||
|
||||
def test_icx_ping_unexpected_success(self):
|
||||
''' Test for successful pings when destination should not be reachable - FAIL. '''
|
||||
set_module_args(dict(count=2, dest="8.8.8.8", state="absent"))
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_icx_ping_unexpected_failure(self):
|
||||
''' Test for unsuccessful pings when destination should be reachable - FAIL. '''
|
||||
set_module_args(dict(count=2, dest="10.255.255.250", timeout=45))
|
||||
fields = {'packets_tx': 1, 'packets_rx': 0, 'packet_loss': '100%', 'rtt': {'max': 0, 'avg': 0, 'min': 0}}
|
||||
self.execute_module(failed=True, fields=fields)
|
||||
|
||||
def test_icx_ping_expected_success_cmd(self):
|
||||
''' Test for successful pings when destination should be reachable '''
|
||||
set_module_args(dict(count=5, dest="8.8.8.8", ttl=70))
|
||||
commands = ['ping 8.8.8.8 count 5 ttl 70']
|
||||
self.execute_module(commands=commands)
|
||||
|
||||
def test_icx_ping_invalid_ttl(self):
|
||||
''' Test for invalid range of ttl for reachable '''
|
||||
set_module_args(dict(dest="8.8.8.8", ttl=300))
|
||||
commands = ['ping 8.8.8.8 ttl 300']
|
||||
self.execute_module(failed=True, sort=False)
|
||||
|
||||
def test_icx_ping_invalid_timeout(self):
|
||||
''' Test for invalid range of timeout for reachable '''
|
||||
set_module_args(dict(dest="8.8.8.8", timeout=4294967296))
|
||||
self.execute_module(failed=True, sort=False)
|
||||
|
||||
def test_icx_ping_invalid_count(self):
|
||||
''' Test for invalid range of count for reachable '''
|
||||
set_module_args(dict(dest="8.8.8.8", count=4294967296))
|
||||
self.execute_module(failed=True, sort=False)
|
||||
|
||||
def test_icx_ping_invalid_size(self):
|
||||
'''Test for invalid range of size for reachable '''
|
||||
set_module_args(dict(dest="8.8.8.8", size=10001))
|
||||
self.execute_module(failed=True, sort=False)
|
||||
122
tests/unit/plugins/modules/network/icx/test_icx_static_route.py
Normal file
122
tests/unit/plugins/modules/network/icx/test_icx_static_route.py
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_static_route
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXStaticRouteModule(TestICXModule):
|
||||
|
||||
module = icx_static_route
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXStaticRouteModule, self).setUp()
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_static_route.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_static_route.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXStaticRouteModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('icx_static_route_config.txt').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_static_route_config(self):
|
||||
set_module_args(dict(prefix='192.126.23.0/24', next_hop='10.10.14.3'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.23.0 255.255.255.0 10.10.14.3'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.23.0 255.255.255.0 10.10.14.3'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_static_route_config_compare(self):
|
||||
set_module_args(dict(prefix='172.16.10.0/24', next_hop='10.0.0.8', check_running_config=True))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=False)
|
||||
expected_commands = [
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=False)
|
||||
expected_commands = [
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_static_route_distance_config(self):
|
||||
set_module_args(dict(prefix='192.126.0.0', mask='255.255.0.0', next_hop='10.10.14.3', admin_distance='40'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.0.0 255.255.0.0 10.10.14.3 distance 40'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.0.0 255.255.0.0 10.10.14.3 distance 40'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_static_route_aggregate(self):
|
||||
aggregate = [
|
||||
dict(prefix='192.126.23.0/24', next_hop='10.10.14.3'),
|
||||
dict(prefix='192.126.0.0', mask='255.255.0.0', next_hop='10.10.14.3', admin_distance='40')
|
||||
]
|
||||
set_module_args(dict(aggregate=aggregate))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.23.0 255.255.255.0 10.10.14.3',
|
||||
'ip route 192.126.0.0 255.255.0.0 10.10.14.3 distance 40'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'ip route 192.126.23.0 255.255.255.0 10.10.14.3',
|
||||
'ip route 192.126.0.0 255.255.0.0 10.10.14.3 distance 40'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_static_route_remove(self):
|
||||
set_module_args(dict(prefix='172.16.10.0/24', next_hop='10.0.0.8', state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'no ip route 172.16.10.0 255.255.255.0 10.0.0.8',
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'no ip route 172.16.10.0 255.255.255.0 10.0.0.8',
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
164
tests/unit/plugins/modules/network/icx/test_icx_system.py
Normal file
164
tests/unit/plugins/modules/network/icx/test_icx_system.py
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_system
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXSystemModule(TestICXModule):
|
||||
|
||||
module = icx_system
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXSystemModule, self).setUp()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_system.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_system.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_system.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXSystemModule, self).tearDown()
|
||||
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('icx_system.txt').strip()
|
||||
else:
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_system_set_config(self):
|
||||
set_module_args(dict(hostname='ruckus', name_servers=['172.16.10.2', '11.22.22.4'], domain_search=['ansible.com', 'redhat.com']))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'hostname ruckus',
|
||||
'ip dns domain-list ansible.com',
|
||||
'ip dns domain-list redhat.com',
|
||||
'ip dns server-address 11.22.22.4',
|
||||
'ip dns server-address 172.16.10.2'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
else:
|
||||
commands = [
|
||||
'hostname ruckus',
|
||||
'ip dns domain-list ansible.com',
|
||||
'ip dns domain-list redhat.com',
|
||||
'ip dns server-address 11.22.22.4',
|
||||
'ip dns server-address 172.16.10.2',
|
||||
'no ip dns domain-list ansib.eg.com',
|
||||
'no ip dns domain-list red.com',
|
||||
'no ip dns domain-list test1.com',
|
||||
'no ip dns server-address 10.22.22.64',
|
||||
'no ip dns server-address 172.22.22.64'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_system_remove_config(self):
|
||||
set_module_args(dict(name_servers=['10.22.22.64', '11.22.22.4'], domain_search=['ansib.eg.com', 'redhat.com'], state='absent'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'no ip dns domain-list ansib.eg.com',
|
||||
'no ip dns domain-list redhat.com',
|
||||
'no ip dns server-address 10.22.22.64',
|
||||
'no ip dns server-address 11.22.22.4'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
else:
|
||||
commands = [
|
||||
'no ip dns domain-list ansib.eg.com',
|
||||
'no ip dns server-address 10.22.22.64',
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_system_remove_config_compare(self):
|
||||
set_module_args(
|
||||
dict(
|
||||
name_servers=[
|
||||
'10.22.22.64',
|
||||
'11.22.22.4'],
|
||||
domain_search=[
|
||||
'ansib.eg.com',
|
||||
'redhat.com'],
|
||||
state='absent',
|
||||
check_running_config=True))
|
||||
if self.get_running_config(compare=True):
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'no ip dns domain-list ansib.eg.com',
|
||||
'no ip dns server-address 10.22.22.64',
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
else:
|
||||
commands = [
|
||||
'no ip dns domain-list ansib.eg.com',
|
||||
'no ip dns server-address 10.22.22.64',
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_icx_aaa_servers_radius_set(self):
|
||||
radius = [
|
||||
dict(
|
||||
type='radius',
|
||||
hostname='2001:db8::1',
|
||||
auth_port_type='auth-port',
|
||||
auth_port_num='1821',
|
||||
acct_port_num='1321',
|
||||
acct_type='accounting-only',
|
||||
auth_key='radius',
|
||||
auth_key_type=[
|
||||
'mac-auth']),
|
||||
dict(
|
||||
type='radius',
|
||||
hostname='172.16.10.24',
|
||||
auth_port_type='auth-port',
|
||||
auth_port_num='2001',
|
||||
acct_port_num='5000',
|
||||
acct_type='authentication-only',
|
||||
auth_key='radius-server'),
|
||||
dict(
|
||||
type='tacacs',
|
||||
hostname='ansible.com')]
|
||||
set_module_args(dict(hostname='ruckus', aaa_servers=radius))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'hostname ruckus',
|
||||
'radius-server host 172.16.10.24 auth-port 2001 acct-port 5000 authentication-only key radius-server',
|
||||
'radius-server host ipv6 2001:db8::1 auth-port 1821 acct-port 1321 accounting-only key radius mac-auth',
|
||||
'tacacs-server host ansible.com'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
else:
|
||||
commands = [
|
||||
'hostname ruckus',
|
||||
'no radius-server host 172.16.20.14',
|
||||
'no tacacs-server host 182.16.10.20',
|
||||
'radius-server host 172.16.10.24 auth-port 2001 acct-port 5000 authentication-only key radius-server',
|
||||
'radius-server host ipv6 2001:db8::1 auth-port 1821 acct-port 1321 accounting-only key radius mac-auth',
|
||||
'tacacs-server host ansible.com'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
197
tests/unit/plugins/modules/network/icx/test_icx_user.py
Normal file
197
tests/unit/plugins/modules/network/icx/test_icx_user.py
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_user
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXSCPModule(TestICXModule):
|
||||
|
||||
module = icx_user
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXSCPModule, self).setUp()
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_user.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_user.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_user.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXSCPModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_exec_command.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
return load_fixture('show_running-config_include_username.txt').strip()
|
||||
else:
|
||||
return ''
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_user_create_new_with_password(self):
|
||||
set_module_args(dict(name='ale6', configured_password='alethea123'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['username ale6 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['username ale6 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_create_new_with_password_and_privilege(self):
|
||||
set_module_args(dict(name='ale6', privilege="5", configured_password='alethea123'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['username ale6 privilege 5 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['username ale6 privilege 5 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_update_privilege(self):
|
||||
set_module_args(dict(name='ale1', privilege="0", configured_password='alethea123'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['username ale1 privilege 0 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['username ale1 privilege 0 password alethea123']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_update_password(self):
|
||||
set_module_args(dict(name='ale1', configured_password='alethea123'))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['username ale1 password alethea123'] # previous privilage will be added
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['username ale1 privilege 5 password alethea123'] # previous privilage will be added
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_update_password_compare(self):
|
||||
set_module_args(dict(name='ale1', configured_password='alethea123', check_running_config=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['username ale1 privilege 5 password alethea123'] # previous privilage will be added
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['username ale1 privilege 5 password alethea123'] # previous privilage will be added
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_delete_user(self):
|
||||
set_module_args(dict(name='ale1', state="absent"))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = ['no username ale1']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = ['no username ale1']
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_agregate(self):
|
||||
set_module_args(dict(aggregate=[
|
||||
{
|
||||
"name": 'ale6',
|
||||
"configured_password": 'alethea123'
|
||||
},
|
||||
{
|
||||
"name": 'ale7',
|
||||
"configured_password": 'alethea123'
|
||||
}
|
||||
]))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'username ale6 password alethea123',
|
||||
'username ale7 password alethea123'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'username ale6 password alethea123',
|
||||
'username ale7 password alethea123'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_not_update_old_user_password(self):
|
||||
set_module_args(dict(aggregate=[
|
||||
{
|
||||
"name": 'ale6',
|
||||
"configured_password": 'alethea123'
|
||||
},
|
||||
{
|
||||
"name": 'ale1',
|
||||
"configured_password": 'alethea123',
|
||||
},
|
||||
],
|
||||
update_password='on_create'
|
||||
))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'username ale1 password alethea123',
|
||||
'username ale6 password alethea123',
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'username ale6 password alethea123',
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_only_update_changed_settings(self):
|
||||
set_module_args(dict(aggregate=[
|
||||
{
|
||||
"name": 'ale1'
|
||||
},
|
||||
{
|
||||
"name": 'ale2',
|
||||
"privilege": 5,
|
||||
"configured_password": "ale123"
|
||||
},
|
||||
{
|
||||
"name": 'ale3',
|
||||
"privilege": 4,
|
||||
"configured_password": "ale123"
|
||||
}
|
||||
],
|
||||
update_password="on_create"
|
||||
))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
'username ale2 privilege 5 password ale123',
|
||||
'username ale3 privilege 4 password ale123'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
else:
|
||||
commands = [
|
||||
'username ale3 privilege 4 password ale123'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
|
||||
def test_icx_user_purge(self):
|
||||
set_module_args(dict(aggregate=[
|
||||
{
|
||||
"name": 'ale1'
|
||||
}
|
||||
],
|
||||
purge=True
|
||||
))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
commands = [
|
||||
|
||||
]
|
||||
self.execute_module(commands=commands, changed=False)
|
||||
else:
|
||||
commands = [
|
||||
'no username ale2',
|
||||
'no username ale3',
|
||||
'no username ale4'
|
||||
]
|
||||
self.execute_module(commands=commands, changed=True)
|
||||
279
tests/unit/plugins/modules/network/icx/test_icx_vlan.py
Normal file
279
tests/unit/plugins/modules/network/icx/test_icx_vlan.py
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
# Copyright: (c) 2019, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
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.plugins.modules.network.icx import icx_vlan
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
|
||||
from .icx_module import TestICXModule, load_fixture
|
||||
|
||||
|
||||
class TestICXVlanModule(TestICXModule):
|
||||
|
||||
module = icx_vlan
|
||||
|
||||
def setUp(self):
|
||||
super(TestICXVlanModule, self).setUp()
|
||||
self.mock_exec_command = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_vlan.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
|
||||
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_vlan.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.icx.icx_vlan.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.set_running_config()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestICXVlanModule, self).tearDown()
|
||||
self.mock_exec_command.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_get_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
compares = None
|
||||
|
||||
def load_file(*args, **kwargs):
|
||||
module = args
|
||||
for arg in args:
|
||||
if arg.params['check_running_config'] is True:
|
||||
self.exec_command.return_value = (0, load_fixture('icx_vlan_config').strip(), None)
|
||||
return load_fixture('icx_banner_show_banner.txt').strip()
|
||||
else:
|
||||
self.exec_command.return_value = (0, ''.strip(), None)
|
||||
return ''
|
||||
|
||||
self.get_config.side_effect = load_file
|
||||
self.load_config.return_value = None
|
||||
|
||||
def test_icx_vlan_set_tagged_port(self):
|
||||
set_module_args(dict(name='test_vlan', vlan_id=5, tagged=dict(name=['ethernet 1/1/40 to 1/1/43', 'lag 44'])))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'vlan 5 name test_vlan',
|
||||
'tagged ethernet 1/1/40 to 1/1/43',
|
||||
'tagged lag 44'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'vlan 5 name test_vlan',
|
||||
'tagged ethernet 1/1/40 to 1/1/43',
|
||||
'tagged lag 44'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_add_untagged_port(self):
|
||||
set_module_args(dict(name='test_vlan', vlan_id=3, interfaces=dict(name=['ethernet 1/1/10', 'lag 5'])))
|
||||
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'vlan 3 name test_vlan',
|
||||
'untagged lag 5',
|
||||
'untagged ethernet 1/1/10'
|
||||
]
|
||||
self.assertEqual(set(result['commands']), set(expected_commands))
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'vlan 3 name test_vlan',
|
||||
'untagged lag 5',
|
||||
'untagged ethernet 1/1/10'
|
||||
]
|
||||
self.assertEqual(set(result['commands']), set(expected_commands))
|
||||
|
||||
def test_icx_vlan_purge_tagged_port(self):
|
||||
set_module_args(dict(vlan_id=3, tagged=dict(name=['ethernet 1/1/40 to 1/1/42', 'lag 44'], purge=True)))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'tagged ethernet 1/1/40 to 1/1/43',
|
||||
'tagged lag 44'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'no tagged ethernet 1/1/31',
|
||||
'no tagged ethernet 1/1/9',
|
||||
'no tagged ethernet 1/1/11',
|
||||
'no tagged lag 13',
|
||||
'no tagged ethernet 1/1/10',
|
||||
'tagged ethernet 1/1/40',
|
||||
'tagged ethernet 1/1/41',
|
||||
'tagged ethernet 1/1/42',
|
||||
'tagged lag 44'
|
||||
]
|
||||
self.assertEqual(set(result['commands']), set(expected_commands))
|
||||
|
||||
def test_icx_vlan_enable_ip_arp_inspection(self):
|
||||
set_module_args(dict(vlan_id=5, ip_arp_inspection=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'ip arp inspection vlan 5'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'ip arp inspection vlan 5'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_enable_ip_dhcp_snooping(self):
|
||||
set_module_args(dict(vlan_id=5, ip_dhcp_snooping=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'ip dhcp snooping vlan 5'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 5',
|
||||
'ip dhcp snooping vlan 5'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_aggregate(self):
|
||||
aggregate = [
|
||||
dict(vlan_id=9, name='vlan_9', interfaces=dict(name=['ethernet 1/1/40 to 1/1/43', 'ethernet 1/1/44']), ip_arp_inspection=True),
|
||||
dict(vlan_id=7, name='vlan_7', interfaces=dict(name=['ethernet 1/1/20 to 1/1/23', 'ethernet 1/1/24']), ip_dhcp_snooping=True),
|
||||
]
|
||||
set_module_args(dict(aggregate=aggregate))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 9',
|
||||
'vlan 9 name vlan_9',
|
||||
'untagged ethernet 1/1/40 to 1/1/43',
|
||||
'untagged ethernet 1/1/44',
|
||||
'ip arp inspection vlan 9',
|
||||
'vlan 7',
|
||||
'vlan 7 name vlan_7',
|
||||
'untagged ethernet 1/1/20 to 1/1/23',
|
||||
'untagged ethernet 1/1/24',
|
||||
'ip dhcp snooping vlan 7',
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 9',
|
||||
'vlan 9 name vlan_9',
|
||||
'untagged ethernet 1/1/40 to 1/1/43',
|
||||
'untagged ethernet 1/1/44',
|
||||
'ip arp inspection vlan 9',
|
||||
'vlan 7',
|
||||
'vlan 7 name vlan_7',
|
||||
'untagged ethernet 1/1/20 to 1/1/23',
|
||||
'untagged ethernet 1/1/24',
|
||||
'ip dhcp snooping vlan 7',
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_interfaces_cndt(self):
|
||||
set_module_args(dict(vlan_id=3, associated_interfaces=['ethernet 1/1/20 to 1/1/22', 'ethernet 1/1/27', 'lag 11 to 12']))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.execute_module(failed=True)
|
||||
else:
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_icx_vlan_tagged_cndt(self):
|
||||
set_module_args(dict(vlan_id=3, associated_tagged=['ethernet 1/1/9 to 1/1/11', 'ethernet 1/1/31', 'lag 13']))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
self.execute_module(failed=True)
|
||||
else:
|
||||
self.execute_module(changed=False)
|
||||
|
||||
def test_icx_vlan_purge(self):
|
||||
set_module_args(dict(vlan_id=3, purge=True))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=False)
|
||||
expected_commands = []
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'no vlan 6',
|
||||
'no vlan 10',
|
||||
'no vlan 21'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_stp_802_1w(self):
|
||||
stp_spec = dict(dict(type='802-1w', priority='20', enabled=True))
|
||||
set_module_args(dict(vlan_id=3, interfaces=dict(name=['ethernet 1/1/40']), stp=stp_spec))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'untagged ethernet 1/1/40',
|
||||
'spanning-tree 802-1w',
|
||||
'spanning-tree 802-1w priority 20'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'untagged ethernet 1/1/40',
|
||||
'spanning-tree 802-1w',
|
||||
'spanning-tree 802-1w priority 20'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_stp_rstp_absent(self):
|
||||
stp_spec = dict(dict(type='rstp', enabled=False))
|
||||
set_module_args(dict(vlan_id=3, interfaces=dict(name=['ethernet 1/1/40']), stp=stp_spec))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'untagged ethernet 1/1/40',
|
||||
'no spanning-tree'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'untagged ethernet 1/1/40',
|
||||
'no spanning-tree'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
|
||||
def test_icx_vlan_stp_802_1w_absent(self):
|
||||
stp_spec = dict(dict(type='802-1w', enabled=False))
|
||||
set_module_args(dict(vlan_id=3, stp=stp_spec))
|
||||
if not self.ENV_ICX_USE_DIFF:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'no spanning-tree 802-1w',
|
||||
'no spanning-tree'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
else:
|
||||
result = self.execute_module(changed=True)
|
||||
expected_commands = [
|
||||
'vlan 3',
|
||||
'no spanning-tree 802-1w',
|
||||
'no spanning-tree'
|
||||
]
|
||||
self.assertEqual(result['commands'], expected_commands)
|
||||
Loading…
Add table
Add a link
Reference in a new issue