1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-11 22:45:05 +00:00

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

* Move modules and module_utils unit tests to correct place.

* Update ignore.txt

* Fix imports.

* Fix typos.

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

View file

@ -0,0 +1,34 @@
##
## Running database "initial"
## Generated at 2009/01/14 12:53:06 +0000
## Hostname: r-ufm-sw102
##
##
## Running-config temporary prefix mode setting
##
no cli default prefix-modes enable
##
## BGP configuration
##
protocol bgp
router bgp 172 vrf default
router bgp 172 vrf default router-id 1.2.3.4 force
router bgp 172 vrf default bgp fast-external-fallover
router bgp 172 vrf default maximum-paths 31
router bgp 172 vrf default bestpath as-path multipath-relax force
router bgp 172 vrf default neighbor evpn peer-group
router bgp 172 vrf default neighbor evpn send-community extended
router bgp 172 vrf default neighbor 10.2.3.4 remote-as 173
router bgp 172 vrf default neighbor 10.2.3.5 remote-as 322
router bgp 172 vrf default neighbor 10.2.3.5 peer-group evpn
router bgp 172 vrf default neighbor 10.2.3.5 ebgp-multihop 255
router bgp 172 vrf default address-family l2vpn-evpn neighbor evpn next-hop-unchanged
router bgp 172 vrf default address-family l2vpn-evpn neighbor evpn activate
router bgp 172 vrf default network 172.16.1.0 /24
router bgp 172 vrf default address-family l2vpn-evpn auto-create
##
## Persistent prefix mode setting
##
cli default prefix-modes enable

View file

@ -0,0 +1,15 @@
{
"roce": [
{
"Type": "lossless",
"Switch Priorities": "3",
"Max Usage": "0",
"Usage": "0",
"Memory actual": "5.9M",
"Memory [%]": "50.00"
}
],
"Exception list": {
"message": "N/A"
}
}

View file

@ -0,0 +1,19 @@
Product name: MLNX-OS
Product release: 3.6.5000
Build ID: #1-dev
Build date: 2017-11-10 18:14:32
Target arch: x86_64
Target hw: x86_64
Built by: jenkins@cc45f26cd083
Version summary: X86_64 3.6.5000 2017-11-10 18:14:32 x86_64
Product model: x86onie
Host ID: 248A073D505C
System serial num: \"MT1632X00205\"
System UUID: 0b19d6d0-5eca-11e6-8000-7cfe90fadc40
Uptime: 1d 16h 31m 43.856s
CPU load averages: 0.06 / 0.12 / 0.13
Number of CPUs: 4
System memory: 2597 MB used / 5213 MB free / 7810 MB total
Swap: 0 MB used / 0 MB free / 0 MB total

View file

@ -0,0 +1,115 @@
##
## Running database "initial"
## Generated at 2017/11/28 17:52:08 +0000
## Hostname: ufm-switch16
##
##
## Running-config temporary prefix mode setting
##
no cli default prefix-modes enable
##
## License keys
##
license install 11223344
##
## MLAG protocol
##
protocol mlag
##
## Interface Ethernet configuration
##
interface mlag-port-channel 2
interface port-channel 1
interface ethernet 1/7-1/8 channel-group 1 mode active
interface ethernet 1/32 mlag-channel-group 2 mode on
interface mlag-port-channel 2 switchport mode hybrid
interface mlag-port-channel 2 no shutdown
##
## LAG configuration
##
lacp
##
## VLAN configuration
##
vlan 101
vlan 4094
interface mlag-port-channel 2 switchport access vlan 101
##
## STP configuration
##
no spanning-tree
##
## L3 configuration
##
ip routing vrf default
interface vlan 101
interface vlan 4094
interface vlan 101 ip address 10.0.0.254 255.255.255.0
interface vlan 4094 ip address 10.10.10.1 255.255.255.0
##
## Other IP configuration
##
hostname ufm-switch16
##
## DCBX PFC configuration
##
dcb priority-flow-control enable force
interface ethernet 1/7-1/8 dcb priority-flow-control mode on force
interface port-channel 1 dcb priority-flow-control mode on force
##
## LLDP configuration
##
lldp
##
## MAGP configuration
##
protocol magp
interface vlan 101 magp 102
interface vlan 101 magp 102 ip virtual-router address 10.0.0.252
interface vlan 101 magp 102 ip virtual-router mac-address 00:00:5E:00:01:01
##
## MLAG configurations
##
mlag-vip neo-mlag-vip-4094 ip 192.168.1.1 /24 force
no mlag shutdown
mlag system-mac 00:00:5E:00:01:00
interface port-channel 1 ipl 1
interface vlan 4094 ipl 1 peer-address 10.10.10.2
##
## AAA remote server configuration
##
# ldap bind-password ********
# radius-server key ********
# tacacs-server key ********
##
## Network management configuration
##
# web proxy auth basic password ********
telnet-server enable
##
## X.509 certificates configuration
##
#
# Certificate name system-self-signed, ID 51f545df9722387056f674401f510ff56077800b
# (public-cert config omitted since private-key config is hidden)
##
## Persistent prefix mode setting
##
cli default prefix-modes enable

View file

@ -0,0 +1,3 @@
no cli default prefix-modes enable
interface mlag-port-channel 2

View file

@ -0,0 +1,20 @@
[
{
"Fec": "auto",
"Mac address": "7c:fe:90:e5:ca:3c",
"Actual speed": "100 Gbps",
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
"header": "Eth1/1",
"Admin state": "Enabled",
"Operational state": "Down"
},
{
"Fec": "auto",
"Mac address": "7c:fe:90:e5:ca:3e",
"Actual speed": "100 Gbps",
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
"header": "Eth1/2",
"Admin state": "Enabled",
"Operational state": "Down"
}
]

View file

@ -0,0 +1,7 @@
{
"MGMT": [
{
"Status": "ready"
}
]
}

View file

@ -0,0 +1,19 @@
{
"Uptime": "2d 13h 40m 34.992s",
"Product model": "x86onie",
"Build date": "2017-11-10 18:14:32",
"Target arch": "x86_64",
"Target hw": "x86_64",
"Number of CPUs": "4",
"Build ID": "#1-dev",
"CPU load averages": "0.21 / 0.07 / 0.06",
"Host ID": "248A07B0141C",
"System serial num": "MT1708X07233",
"System UUID": "03d242b6-1a24-11e7-8000-248a07f55400",
"Swap": "0 MB used / 0 MB free / 0 MB total",
"Product name": "MLNX-OS",
"Built by": "jenkins@cc45f26cd083",
"System memory": "2597 MB used / 5213 MB free / 7810 MB total",
"Version summary": "X86_64 3.6.5000 2017-11-10 18:14:32 x86_64",
"Product release": "3.6.5000"
}

View file

@ -0,0 +1,14 @@
[
{
"Report suppression interval": "5 seconds",
"IGMP snooping unregistered multicast": "flood",
"IGMP snooping operationally": "disabled",
"Mrouter timeout": "125 seconds",
"IGMP default version for new VLAN": "V3",
"header": "IGMP snooping global configuration",
"Last member query interval": "1 seconds",
"IGMP snooping globally": "disabled",
"Proxy-reporting globally": "disabled",
"Port purge timeout": "260 seconds"
}
]

View file

@ -0,0 +1,10 @@
{
"Eth1/1": [
{
"ingress rate": "9000 b/s",
"egress pkts/sec": "10",
"egress rate": "10000 b/s",
"ingress pkts/sec": "10"
}
]
}

View file

@ -0,0 +1,74 @@
[
{
"Fec": "auto",
"Mac address": "7c:fe:90:f0:54:fc",
"60 seconds ingress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last clearing of \"show interface\" counters": "Never",
"Actual speed": "40 Gbps",
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
"header": "Eth1/1",
"Telemetry threshold": "Disabled\t TCs: N\\A",
"Telemetry threshold level": "N\\A",
"Flow-control": "receive off send off",
"Forwarding mode": "inherited cut-through",
"60 seconds egress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last change in operational status": "Never",
"Boot delay time": "0 sec",
"Description": "N\\A",
"Admin state": "Enabled",
"Telemetry sampling": "Disabled\t TCs: N\\A",
"Operational state": "Down",
"Width reduction mode": "Not supported",
"Tx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"hoq discard packets": "0",
"broadcast packets": "0"
},
"MAC learning mode": "Enabled",
"Switchport mode": "access",
"Rx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"broadcast packets": "0"
}
},
{
"Icmp redirect": "Enabled",
"Description": "N/A",
"Mac Address": "7C:FE:90:F0:54:C1",
"Autostate": "Enabled",
"Admin state": "Enabled",
"header": "Vlan 10",
"MTU": "1500 bytes",
"DHCP client": "Disabled",
"Operational state": "Up",
"VRF": "default",
"Arp timeout": "1500 seconds",
"Counters": "Disabled"
},
{
"Autostate": "Enabled",
"Icmp redirect": "Enabled",
"Broadcast address": "10.2.2.255",
"Description": "N/A",
"Mac Address": "7C:FE:90:F0:54:C1",
"Internet Address": "10.2.2.3/24",
"Admin state": "Enabled",
"header": "Vlan 1002",
"MTU": "1500 bytes",
"DHCP client": "Disabled",
"Operational state": "Down",
"VRF": "default",
"Arp timeout": "1500 seconds",
"Counters": "Disabled"
}
]

View file

@ -0,0 +1,15 @@
{
"Eth1/1": [
{
"Negotiation": "No-Negotiation",
"Operational state": "Down",
"Speed": "100 Gbps"
}
],
"Vlan 1002": [
{
"State": "Down",
"Description": "N/A"
}
]
}

View file

@ -0,0 +1,12 @@
{
"Eth1/11": {
"Access vlan": "1",
"Allowed vlans": "",
"Mode": "access"
},
"Eth1/10": {
"Access vlan": "1",
"Allowed vlans": "10",
"Mode": "hybrid"
}
}

View file

@ -0,0 +1,89 @@
[
{
"Broadcast address": "172.3.1.255",
"Fec": "auto",
"Tx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"hoq discard packets": "0",
"broadcast packets": "0"
},
"Rx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"broadcast packets": "0"
},
"header": "Eth1/5",
"Arp timeout": "1500 seconds",
"Actual speed": "40 Gbps",
"60 seconds egress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last change in operational status": "Never",
"Boot delay time": "0 sec",
"Description": "N\\A",
"DHCP client": "Disabled",
"VRF": "default",
"Mac address": "24:8A:07:F5:54:01",
"60 seconds ingress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last clearing of \"show interface\" counters": "Never",
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
"Telemetry threshold": "Disabled\t TCs: N\\A",
"Telemetry threshold level": "N\\A",
"Flow-control": "receive off send off",
"Forwarding mode": "inherited cut-through",
"Admin state": "Enabled",
"Telemetry sampling": "Disabled\t TCs: N\\A",
"IP Address": "172.3.12.4 /24",
"Operational state": "Down",
"Width reduction mode": "Not supported"
},
{
"Fec": "auto",
"Mac address": "24:8a:07:f5:54:0c",
"60 seconds ingress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last clearing of \"show interface\" counters": "Never",
"Actual speed": "40 Gbps",
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
"header": "Eth1/6",
"Telemetry threshold": "Disabled\t TCs: N\\A",
"Telemetry threshold level": "N\\A",
"Flow-control": "receive off send off",
"Forwarding mode": "inherited cut-through",
"60 seconds egress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
"Last change in operational status": "Never",
"Boot delay time": "0 sec",
"Description": "N\\A",
"Admin state": "Enabled",
"Telemetry sampling": "Disabled\t TCs: N\\A",
"Operational state": "Down",
"Width reduction mode": "Not supported",
"Tx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"hoq discard packets": "0",
"broadcast packets": "0"
},
"MAC learning mode": "Enabled",
"Switchport mode": "access",
"Rx": {
"error packets": "0",
"packets": "0",
"bytes": "0",
"multicast packets": "0",
"unicast packets": "0",
"discard packets": "0",
"broadcast packets": "0"
}
}
]

View file

@ -0,0 +1,18 @@
[
{
"Autostate": "Enabled",
"Icmp redirect": "Enabled",
"Broadcast address": "172.3.12.255",
"Description": "N/A",
"Mac Address": "7C:FE:90:E5:CA:01",
"Internet Address": "172.3.12.4/24",
"Admin state": "Enabled",
"header": "Vlan 1002",
"MTU": "1500 bytes",
"DHCP client": "Disabled",
"Operational state": "Down",
"VRF": "default",
"Arp timeout": "1500 seconds",
"Counters": "Disabled"
}
]

View file

@ -0,0 +1,16 @@
{
"Eth1/1": [
{
"Receive": "Enabled",
"Transmit": "Enabled",
"TLVs": "PD, SN, SD, SC, MA, PFC, AP, ETS-C, ETS-R"
}
],
"Eth1/2": [
{
"Receive": "Disabled",
"Transmit": "Disabled",
"TLVs": "PD, SN, SD, SC, MA, PFC, AP, ETS-C, ETS-R"
}
]
}

View file

@ -0,0 +1,14 @@
[
{
"LLDP": "enabled"
},
{
"Supported capabilities": "B,R",
"Chassis sub type": "Mac Address",
"header": "Local global configuration",
"System Name": "ufm-switch16",
"Supported capabilities enabled": "B",
"Chassis id": "7c:fe:90:e5:ca:00",
"System Description": "Mellanox MSN2700,MLNX-OS,SWv3.6.5000-04"
}
]

View file

@ -0,0 +1,11 @@
logging trap alert
logging 10.10.10.10
logging 10.10.10.10 filter exclude ".*ERR.*"
logging 10.10.10.10 trap info
logging 10.10.10.12
logging 10.10.10.12 port 80
logging 10.10.10.12 trap override class sx-sdk priority emerg
logging files rotation criteria size-pct 10.000
logging local info
logging receive

View file

@ -0,0 +1,35 @@
[
{
"Log format": "standard",
"Log rotation size threshold": "10.000% of partition (986.46 megabytes)",
"Allow receiving of messages from remote hosts": "yes",
"Override for class debug-module": "notice",
"Local logging level": "info",
"Number of archived log files to keep": "10",
"Default remote logging level": "alert",
"Subsecond timestamp field": "disabled",
"Log rotation frequency": "weekly",
"debug": [
"logging debug-files rotation criteria frequency daily",
"logging debug-files rotation criteria size 20",
"logging debug-files rotation max-num 20"
]
},
{
"Levels at which messages are logged": [
{
"CLI commands": "notice",
"Audit messages": "notice"
}
]
},
{
"Remote syslog servers": [
{
"Lines": [
"No remote syslog servers configured"
]
}
]
}
]

View file

@ -0,0 +1,18 @@
[
{
"Interface vlan": "1243",
"Admin state": "Enabled",
"Virtual IP": "10.0.0.43",
"header": "MAGP 102",
"State": "Init",
"Virtual MAC": "01:02:03:04:05:06"
},
{
"Interface vlan": "1200",
"Admin state": "Disabled",
"Virtual IP": "0.0.0.0",
"header": "MAGP 103",
"State": "Init",
"Virtual MAC": "00:00:00:00:00:00"
}
]

View file

@ -0,0 +1,29 @@
{
"Reload-delay": "30 sec",
"Upgrade-timeout": "60 min",
"System-mac": "00:00:5E:00:01:4E [Mismatched]",
"Admin status": "Disabled",
"MLAG Ports Status Summary": {
"Active-partial": "0",
"Inactive": "0",
"Active-full": "0"
},
"MLAG IPLs Summary": {
"1": [
{
"Local IP address": "10.2.2.3",
"Peer IP address": "10.2.2.2",
"Operational State": "Down",
"Vlan Interface": "1002",
"Group Port-Channel": "Po1"
}
]
},
"Keepalive-interval": "1 sec",
"MLAG Ports Configuration Summary": {
"Disabled": "0",
"Configured": "0",
"Enabled": "0"
},
"Operational status": "Down"
}

View file

@ -0,0 +1,18 @@
{
"MLAG Port-Channel Flags": "D-Down, U-Up, P-Partial UP, S - suspended by MLAG",
"Port Flags": {
"I": "Individual",
"P": "Up in port-channel (members)",
"S": "Suspend in port-channel (members)",
"D": "Down"
},
"MLAG Port-Channel Summary": {
"1 Mpo33(S)": [
{
"Local Ports (D/P/S/I)": "Eth1/8(D)",
"Peer Ports (D/P/S/I)": "N/A",
"Type": "LACP"
}
]
}
}

View file

@ -0,0 +1,18 @@
{
"Reload-delay": "30 sec",
"Upgrade-timeout": "60 min",
"System-mac": "00:00:5E:00:01:4E",
"Admin status": "Disabled",
"MLAG Ports Status Summary": {
"Active-partial": "0",
"Inactive": "0",
"Active-full": "0"
},
"Keepalive-interval": "1 sec",
"MLAG Ports Configuration Summary": {
"Disabled": "0",
"Configured": "0",
"Enabled": "0"
},
"Operational status": "Down"
}

View file

@ -0,0 +1,19 @@
{
"r-neo-sw12": [
{
"IP Address": "10.209.26.55",
"VIP-State": "standby"
}
],
"r-smg-sw14": [
{
"IP Address": "10.209.27.172",
"VIP-State": "master"
}
],
"MLAG-VIP": {
"MLAG VIP address": "10.209.25.107/24",
"MLAG group name": "neo-mlag-vip-500",
"Active nodes": "2"
}
}

View file

@ -0,0 +1,19 @@
[
{
"NTP enabled": "yes",
"NTP Authentication enabled": "no"
},
{
"NTP version": "4",
"Enabled": "yes",
"Key ID": "5",
"header": "NTP peer 1.1.1.1"
},
{
"NTP version": "4",
"Enabled": "no",
"Trusted": "yes",
"Key ID": "99",
"header": "NTP server 2.2.2.2"
}
]

View file

@ -0,0 +1,30 @@
[
[
{
"NTP is administratively": "enabled",
"NTP Authentication administratively": "disabled"
},
{
"Lines": [
"Clock is unsynchronized."
]
},
{
"Active servers and peers": [
{
"Lines": [
"No NTP associations present."
]
}
]
}
] ,
[
{
"header": "NTP Key 22",
"Encryption Type": "sha1",
"Trusted": "no"
}
]
]

View file

@ -0,0 +1,5 @@
OSPF Process ID 2 VRF default
Total number of interface: 1
Interface Id Area Cost State Neighbors Status
Loopback1 0.0.0.0 1 Enabled 0 Up

View file

@ -0,0 +1 @@
Routing Process 2 with ID 10.2.3.4 default

View file

@ -0,0 +1,26 @@
{
"Eth1/1": [
{
"PFC admin": "Auto",
"PFC oper": "Disabled"
}
],
"Eth1/1/2": [
{
"PFC admin": "Auto",
"PFC oper": "Disabled"
}
],
"Po1": [
{
"PFC admin": "Auto",
"PFC oper": "Disabled"
}
],
"Mpo2": [
{
"PFC admin": "Auto",
"PFC oper": "Disabled"
}
]
}

View file

@ -0,0 +1,26 @@
{
"Eth1/1": [
{
"PFC admin": "on",
"PFC oper": "Enabled"
}
],
"Eth1/1/2": [
{
"PFC admin": "on",
"PFC oper": "Enabled"
}
],
"Po1": [
{
"PFC admin": "on",
"PFC oper": "Enabled"
}
],
"Mpo2": [
{
"PFC admin": "on",
"PFC oper": "Enabled"
}
]
}

View file

@ -0,0 +1,15 @@
{
"Flags": {
"I": "Individual",
"P": "Up in port-channel (members)",
"S": "Suspend in port-channel (members)",
"U": "Up",
"D": "Down"
},
"1 Po22(D)": [
{
"Type": "STATIC",
"Member Ports": "Eth1/7(D)"
}
]
}

View file

@ -0,0 +1,27 @@
{
"pim": "disabled",
"dhcp-relay": "disabled",
"igmp-snooping": "disabled",
"lacp": "disabled",
"ptp": "disabled",
"lldp": "disabled",
"isolation-group": "disabled",
"bfd": "disabled",
"openflow": "disabled",
"telemetry": "disabled",
"vrrp": "disabled",
"spanning-tree": "rst",
"mlag": "disabled",
"magp": "disabled",
"nve": "disabled",
"Ethernet": "enabled",
"IP L3": "enabled",
"ets": "enabled",
"sflow": "disabled",
"dhcp-relay(v6)": "disabled",
"dot1x": "disabled",
"bgp": "disabled",
"priority-flow-control": "disabled",
"ospf": "disabled",
"bfd": "disabled"
}

View file

@ -0,0 +1,16 @@
[
{
"Default User": "admin",
"header": "AAA authorization",
"Fallback on server-err": "yes",
"Map Order": "remote-first"
},
{
"header": "Authentication method(s)",
"message": "local"
},
{
"header": "Accounting method(s)",
"message": "No accounting methods configured."
}
]

View file

@ -0,0 +1,14 @@
{
"Lines": [
" protocol bfd",
" ip bfd shutdown vrf default",
" ip bfd vrf 3 interval transmit-rate 55 force",
" ip bfd vrf default interval transmit-rate 55 force",
" ip bfd vrf 3 interval min-rx 50 force",
" ip bfd vrf default interval min-rx 50 force",
" ip bfd vrf 3 interval multiplier 7 force",
" ip bfd vrf default interval multiplier 7 force",
" ip route vrf 3 1.1.1.0/24 3.2.2.2 bfd",
" ip route vrf default 1.1.1.0/24 3.2.2.2 bfd"
]
}

View file

@ -0,0 +1,99 @@
[
{
"Eth1/1": [
{
"Multicast unaware mapping": "disabled",
"Interface Bandwidth Shape [Mbps]": "N/A"
},
{
"Flags": [
{
"S.Mode": "Scheduling Mode [Strict/WRR]",
"Bw.Sh": "Bandwidth Shaper",
"D": "-",
"W": "Weight",
"Bw.Gr": "Bandwidth Guaranteed"
}
]
},
{
"ETS per TC": [
{
"1": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "17",
"BW Gr.(Mbps)": "0",
"W": "13"
}
],
"0": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "17",
"BW Gr.(Mbps)": "0",
"W": "12"
}
],
"3": [
{
"S.Mode": "Strict",
"BW Sh.(Mbps)": "N/A",
"W(%)": "0",
"BW Gr.(Mbps)": "0",
"W": "0"
}
],
"2": [
{
"S.Mode": "Strict",
"BW Sh.(Mbps)": "N/A",
"W(%)": "0",
"BW Gr.(Mbps)": "0",
"W": "0"
}
],
"5": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "17",
"BW Gr.(Mbps)": "0",
"W": "13"
}
],
"4": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "16",
"BW Gr.(Mbps)": "0",
"W": "12"
}
],
"7": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "17",
"BW Gr.(Mbps)": "0",
"W": "13"
}
],
"6": [
{
"S.Mode": "WRR",
"BW Sh.(Mbps)": "N/A",
"W(%)": "16",
"BW Gr.(Mbps)": "0",
"W": "12"
}
]
}
]
}
]
}
]

View file

@ -0,0 +1,162 @@
{
"Eth1/31": [
{
"leave-mode": "Normal"
}
],
"Eth1/11": [
{
"leave-mode": "Normal"
}
],
"Eth1/10": [
{
"leave-mode": "Normal"
}
],
"Eth1/13": [
{
"leave-mode": "Normal"
}
],
"Eth1/12": [
{
"leave-mode": "Normal"
}
],
"Eth1/15": [
{
"leave-mode": "Normal"
}
],
"Eth1/14": [
{
"leave-mode": "Normal"
}
],
"Eth1/17": [
{
"leave-mode": "Normal"
}
],
"Eth1/16": [
{
"leave-mode": "Normal"
}
],
"Eth1/19": [
{
"leave-mode": "Normal"
}
],
"Eth1/18": [
{
"leave-mode": "Normal"
}
],
"Eth1/5": [
{
"leave-mode": "Normal"
}
],
"Eth1/4": [
{
"leave-mode": "Normal"
}
],
"Eth1/7": [
{
"leave-mode": "Normal"
}
],
"Eth1/6": [
{
"leave-mode": "Normal"
}
],
"Eth1/1": [
{
"leave-mode": "Normal"
}
],
"Eth1/3": [
{
"leave-mode": "Fast"
}
],
"Eth1/2": [
{
"leave-mode": "Normal"
}
],
"Eth1/9": [
{
"leave-mode": "Normal"
}
],
"Eth1/8": [
{
"leave-mode": "Normal"
}
],
"Eth1/32": [
{
"leave-mode": "Normal"
}
],
"Eth1/24": [
{
"leave-mode": "Normal"
}
],
"Eth1/25": [
{
"leave-mode": "Normal"
}
],
"Eth1/26": [
{
"leave-mode": "Normal"
}
],
"Eth1/27": [
{
"leave-mode": "Normal"
}
],
"Eth1/20": [
{
"leave-mode": "Normal"
}
],
"Eth1/21": [
{
"leave-mode": "Normal"
}
],
"Eth1/22": [
{
"leave-mode": "Normal"
}
],
"Eth1/23": [
{
"leave-mode": "Normal"
}
],
"Eth1/30": [
{
"leave-mode": "Normal"
}
],
"Eth1/28": [
{
"leave-mode": "Normal"
}
],
"Eth1/29": [
{
"leave-mode": "Normal"
}
]
}

View file

@ -0,0 +1,46 @@
[
{
"Interface ethernet": "1/1",
"ECN marked packets": "0"
},
{
"header": "TC-0",
"Mode": "none"
},
{
"header": "TC-1",
"Mode": "none"
},
{
"Threshold mode": "relative",
"RED dropped packets": "0",
"header": "TC-2",
"Mode": "RED",
"Maximum threshold": "90%",
"Minimum threshold": "9%"
},
{
"Threshold mode": "absolute",
"RED dropped packets": "0",
"header": "TC-3",
"Mode": "ECN",
"Maximum threshold": "1550 KB",
"Minimum threshold": "500 KB"
},
{
"header": "TC-4",
"Mode": "none"
},
{
"header": "TC-5",
"Mode": "none"
},
{
"header": "TC-6",
"Mode": "none"
},
{
"header": "TC-7",
"Mode": "none"
}
]

View file

@ -0,0 +1,18 @@
[
{
"Mlag tunnel IP": "192.10.10.1",
"Effective tunnel IP": "(not exist)",
"NVE member interfaces": "(not configured)",
"Admin state": "up",
"Source interface": "loopback 1 (ip 0.0.0.0)",
"header": "Interface NVE 1 status",
"Controller mode": "BGP",
"Global Neigh-Suppression": "Enable",
"Counters": {
"dropped NVE-encapsulated packets": "0",
"decapsulated (Rx) NVE packets": "0",
"encapsulated (Tx) NVE packets": "0",
"NVE-encapsulated packets with errors": "0"
}
}
]

View file

@ -0,0 +1,16 @@
[
{
"10":[
{
"Neigh Suppression":"Enable",
"VNI":"10010"
}
],
"6":[
{
"Neigh Suppression":"Enable",
"VNI":"10060"
}
]
}
]

View file

@ -0,0 +1,10 @@
[
{
"mrouter static port list": "none",
"mrouter dynamic port list": "none",
"header": "Vlan 10 configuration parameters",
"message 1": "IGMP snooping is disabled",
"message 2": "IGMP version is V3",
"message 3": "Snooping switch is acting as Non-Querier"
}
]

View file

@ -0,0 +1,30 @@
[
{
"Snooping group information for VLAN 10 and group 224.5.5.1": [
{
"Group flag": "St",
"Filter Mode": "EXCLUDE",
"V1/V2 Receiver Ports": "eth1/1, eth1/2",
"Exclude sources": "None"
},
{
"V3 Receiver Ports": [
{
"Exclude sources": [
"None",
"None"
],
"Include sources": [
"1.1.1.1, 1.1.1.2",
"1.1.1.3"
],
"Port Number": [
"eth1/1",
"eth1/2"
]
}
]
}
]
}
]

View file

@ -0,0 +1,20 @@
[
{
"Snooping querier information for VLAN 10": [
{
"Lines": [
"IGMP Querier Not Present"
]
},
{
"Response interval": "100",
"Elected querier IP address": "0.0.0.0",
"Group membership interval": "1",
"Robustness": "2",
"Configured querier IP address": "-",
"Query interval": "125",
"Version": "3"
}
]
}
]

View file

@ -0,0 +1,8 @@
[
{
"message 2": "No NTP servers configured.",
"message 1": "No NTP peers configured.",
"NTP enabled": "no",
"NTP Authentication enabled": "no"
}
]

View file

@ -0,0 +1,7 @@
{
"Priority1": "128",
"Number of PTP ports": "0",
"Domain": "127",
"Priority2": "128",
"Local clock time": "04:50:24 Etc/UTC 2018/09/04"
}

View file

@ -0,0 +1,15 @@
[
{
"Transport protocol": "UDP IPv4",
"PTP interface state": "NONE",
"Forced Master": "no",
"Port Clock identity": "N/A",
"Announce interval(log mean)": "-2",
"PTP Port number": "0",
"header": "Interface name: Eth1/1",
"Delay Mechanism": "End to End",
"Sync interval(log mean)": "-3",
"Announce receipt time out": "3",
"Delay request interval(log mean)": "0"
}
]

View file

@ -0,0 +1,38 @@
[
{
"Default notification port": "162",
"Default notification community": "public",
"Notifications enabled": "yes"
},
{
"Notification sinks": [
{
"1.1.1.1": [
{
"Enabled": "yes",
"Port": "3",
"Notification type": "SNMP v3 inform",
"Remote engine ID": ""
},
{
"Username": "sara",
"Authentication password": "(set)",
"Privacy password": "(set)",
"Privacy type": "3des",
"Authentication type": "md5"
}
]
},
{
"2.2.2.2": [
{
"Community": "public (default)",
"Enabled": "yes",
"Port": "5",
"Notification type": "SNMP v2c trap"
}
]
}
]
}
]

View file

@ -0,0 +1,22 @@
[
{
"User name sara": [
{
"Privacy password": "(NOT SET; user disabled)",
"Enabled overall": "yes",
"Authentication password": "(NOT SET; user disabled)",
"Authentication type": "sha",
"Require privacy": "no",
"Privacy type": "aes-128"
},
{
"SET access": [
{
"Capability level": "admin",
"Enabled": "yes"
}
]
}
]
}
]

View file

@ -0,0 +1,52 @@
[
[
{
"SNMP port": "161",
"System contact": "sara",
"System location": "Jordan",
"SNMP enabled": "yes"
},
{
"Read-only communities": [
{
"Lines": [
"community_1",
"public"
]
}
]
},
{
"Read-write communities": [
{
"Lines": [
"community_2"
]
}
]
},
{
"Interface listen enabled": "yes"
},
{
"Listen Interfaces": [
{
"Lines": [
"No Listen Interfaces."
]
}
]
}
],
{
"Lines": [
" snmp-server community community_1 ro",
" snmp-server community community_2 rw",
" snmp-server contact sara",
" snmp-server location Jordan",
" snmp-server notify port 1",
" snmp-server notify community community_1"
]
}
]

View file

@ -0,0 +1,51 @@
{
"xmladmin": [
{
"CAPABILITY": "admin",
"ACCOUNT STATUS": "Password set (SHA512)",
"FULL NAME": "XML Admin User"
}
],
"monitor": [
{
"CAPABILITY": "monitor",
"ACCOUNT STATUS": "Password set (SHA512)",
"FULL NAME": "System Monitor"
}
],
"admin": [
{
"CAPABILITY": "admin",
"ACCOUNT STATUS": "No password required for login",
"FULL NAME": "System Administrator"
}
],
"anass": [
{
"CAPABILITY": "admin",
"ACCOUNT STATUS": "Password set (SHA512)",
"FULL NAME": ""
}
],
"root": [
{
"CAPABILITY": "admin",
"ACCOUNT STATUS": "No password required for login",
"FULL NAME": "Root User"
}
],
"anassh": [
{
"CAPABILITY": "admin",
"ACCOUNT STATUS": "Account disabled",
"FULL NAME": ""
}
],
"xmluser": [
{
"CAPABILITY": "monitor",
"ACCOUNT STATUS": "Password set (SHA512)",
"FULL NAME": "XML Monitor User"
}
]
}

View file

@ -0,0 +1,14 @@
{
"1": {
"Name": "default",
"Ports": "Eth1/1, Eth1/2, Eth1/3, Eth1/4, Eth1/5,\nEth1/6, Eth1/7, Eth1/8, Eth1/9, Eth1/10,\nEth1/11, Eth1/12, Eth1/13, Eth1/14, Eth1/15,\nEth1/16"
},
"10": {
"Name": "test 10",
"Ports": ""
},
"20": {
"Name": "test 20",
"Ports": ""
}
}

View file

@ -0,0 +1,3 @@
no what-just-happened auto-export forwarding enable
no what-just-happened forwarding enable

View file

@ -0,0 +1,134 @@
[
{
"Eth1/1": [
{
"PCP,DEI rewrite": "enabled",
"Default switch-priority": "0",
"IP PCP;DEI rewrite": "enable",
"Default DEI": "0",
"Default PCP": "0",
"Trust mode": "both",
"DSCP rewrite": "disabled"
},
{
"PCP(DEI); DSCP to switch-priority mapping": [
{
"2(0) 2(1)": [
{
"switch-priority": "2",
"DSCP": "16 17 18 19 20 21 22 23"
}
],
"3(0) 3(1)": [
{
"switch-priority": "3",
"DSCP": "24 25 26 27 28 29 30 31"
}
],
"5(0) 5(1)": [
{
"switch-priority": "5",
"DSCP": "40 41 42 43 44 45 46 47"
}
],
"0(0) 0(1)": [
{
"switch-priority": "0",
"DSCP": "0 1 2 3 4 5 6 7"
}
],
"7(0) 7(1)": [
{
"switch-priority": "7",
"DSCP": "56 57 58 59 60 61 62 63"
}
],
"4(0) 4(1)": [
{
"switch-priority": "4",
"DSCP": "32 33 34 35 36 37 38 39"
}
],
"6(0) 6(1)": [
{
"switch-priority": "6",
"DSCP": "48 49 50 51 52 53 54 55"
}
],
"1(0) 1(1)": [
{
"switch-priority": "1",
"DSCP": "8 9 10 11 12 13 14 15"
}
]
}
]
},
{
"PCP(DEI); DSCP rewrite mapping (switch-priority to PCP(DEI); DSCP; traffic-class)": [
{
"Egress Interface": "Eth1/1"
},
{
"1": [
{
"PCP(DEI)": "1(0)",
"TC": "1",
"DSCP": "8"
}
],
"0": [
{
"PCP(DEI)": "0(0)",
"TC": "0",
"DSCP": "0"
}
],
"3": [
{
"PCP(DEI)": "3(0)",
"TC": "3",
"DSCP": "24"
}
],
"2": [
{
"PCP(DEI)": "2(0)",
"TC": "2",
"DSCP": "16"
}
],
"5": [
{
"PCP(DEI)": "5(0)",
"TC": "5",
"DSCP": "40"
}
],
"4": [
{
"PCP(DEI)": "4(0)",
"TC": "4",
"DSCP": "32"
}
],
"7": [
{
"PCP(DEI)": "7(0)",
"TC": "7",
"DSCP": "56"
}
],
"6": [
{
"PCP(DEI)": "6(0)",
"TC": "6",
"DSCP": "48"
}
]
}
]
}
]
}
]

View file

@ -0,0 +1,91 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
import os
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 TestOnyxModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, commands=None, is_updates=False, sort=True, transport='cli'):
self.load_fixtures(commands, transport=transport)
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 is_updates:
commands_res = result.get('updates')
else:
commands_res = result.get('commands')
if sort:
self.assertEqual(sorted(commands), sorted(commands_res), commands_res)
else:
self.assertEqual(commands, commands_res, commands_res)
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, transport='cli'):
pass

View file

@ -0,0 +1,74 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_aaa
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxAAAModule(TestOnyxModule):
module = onyx_aaa
def setUp(self):
self.enabled = False
super(TestOnyxAAAModule, self).setUp()
self.mock_get_config = patch.object(
onyx_aaa.OnyxAAAModule, "_show_aaa_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxAAAModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_aaa.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_aaa_accounting_no_change(self):
set_module_args(dict(tacacs_accounting_enabled=False))
self.execute_module(changed=False)
def test_aaa_accounting_with_change(self):
set_module_args(dict(tacacs_accounting_enabled=True))
commands = ['aaa accounting changes default stop-only tacacs+']
self.execute_module(changed=True, commands=commands)
def test_aaa_auth_default_user_no_change(self):
set_module_args(dict(auth_default_user='admin'))
self.execute_module(changed=False)
def test_aaa_auth_default_user_with_change(self):
set_module_args(dict(auth_default_user='monitor'))
commands = ['aaa authorization map default-user monitor']
self.execute_module(changed=True, commands=commands)
def test_aaa_auth_order_no_change(self):
set_module_args(dict(auth_order='remote-first'))
self.execute_module(changed=False)
def test_aaa_auth_order_with_change(self):
set_module_args(dict(auth_order='local-only'))
commands = ['aaa authorization map order local-only']
self.execute_module(changed=True, commands=commands)
def test_aaa_fallback_no_change(self):
set_module_args(dict(auth_fallback_enabled=True))
self.execute_module(changed=False)
def test_aaa_fallback_with_change(self):
set_module_args(dict(auth_fallback_enabled=False))
commands = ['no aaa authorization map fallback server-err']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,114 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_bfd
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxBFDModule(TestOnyxModule):
module = onyx_bfd
def setUp(self):
self.enabled = False
super(TestOnyxBFDModule, self).setUp()
self.mock_get_config = patch.object(
onyx_bfd.OnyxBFDModule, "_show_bfd_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxBFDModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_bfd.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_bfd_shutdown_no_change(self):
set_module_args(dict(shutdown=True))
self.execute_module(changed=False)
def test_bfd_shutdown_with_change(self):
set_module_args(dict(shutdown=False))
commands = ['no ip bfd shutdown']
self.execute_module(changed=True, commands=commands)
def test_vrf_bfd_shutdown_no_change(self):
set_module_args(dict(shutdown=False,
vrf='3'))
self.execute_module(changed=False)
def test_vrf_bfd_shutdown_with_change(self):
set_module_args(dict(shutdown=True,
vrf='3'))
commands = ['ip bfd shutdown vrf 3']
self.execute_module(changed=True, commands=commands)
def test_bfd_interval_no_change(self):
set_module_args(dict(interval_min_rx=50,
interval_multiplier=7,
interval_transmit_rate=55))
self.execute_module(changed=False)
def test_bfd_interval_with_change(self):
set_module_args(dict(interval_min_rx=55,
interval_multiplier=7,
interval_transmit_rate=100))
commands = ['ip bfd interval min-rx 55 multiplier 7 transmit-rate 100 force']
self.execute_module(changed=True, commands=commands)
def test_vrf_bfd_interval_no_change(self):
set_module_args(dict(interval_min_rx=50,
interval_multiplier=7,
interval_transmit_rate=55,
vrf='3'))
self.execute_module(changed=False)
def test_vrf_bfd_interval_with_change(self):
set_module_args(dict(interval_min_rx=55,
interval_multiplier=7,
interval_transmit_rate=100,
vrf='3'))
commands = ['ip bfd vrf 3 interval min-rx 55 multiplier 7 transmit-rate 100 force']
self.execute_module(changed=True, commands=commands)
def test_bfd_iproute_no_change(self):
set_module_args(dict(iproute_network_prefix='1.1.1.0',
iproute_mask_length=24,
iproute_next_hop='3.2.2.2'))
self.execute_module(changed=False)
def test_bfd_iproute_with_change(self):
set_module_args(dict(iproute_network_prefix='1.1.1.0',
iproute_mask_length=24,
iproute_next_hop='3.2.2.3'))
commands = ['ip route 1.1.1.0 /24 3.2.2.3 bfd']
self.execute_module(changed=True, commands=commands)
def test_vrf_bfd_iproute_no_change(self):
set_module_args(dict(iproute_network_prefix='1.1.1.0',
iproute_mask_length=24,
iproute_next_hop='3.2.2.2',
vrf='3'))
self.execute_module(changed=False)
def test_vrf_bfd_iproute_with_change(self):
set_module_args(dict(iproute_network_prefix='1.1.1.0',
iproute_mask_length=24,
iproute_next_hop='3.2.2.3',
vrf='3'))
commands = ['ip route vrf 3 1.1.1.0 /24 3.2.2.3 bfd']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,111 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_bgp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxBgpModule(TestOnyxModule):
module = onyx_bgp
def setUp(self):
super(TestOnyxBgpModule, self).setUp()
self.mock_get_config = patch.object(
onyx_bgp.OnyxBgpModule, "_get_bgp_summary")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxBgpModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_bgp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_bgp_no_change(self):
neighbor = dict(remote_as=322, neighbor='10.2.3.5', multihop=255)
set_module_args(dict(as_number=172, router_id='1.2.3.4',
neighbors=[neighbor],
networks=['172.16.1.0/24'],
evpn=True, fast_external_fallover=True,
max_paths=31, ecmp_bestpath=True,
))
self.execute_module(changed=False)
def test_bgp_remove(self):
set_module_args(dict(as_number=172, state='absent'))
commands = ['no router bgp 172']
self.execute_module(changed=True, commands=commands)
def test_bgp_with_vrf_changed(self):
set_module_args(dict(as_number=173, vrf='new_vrf'))
commands = ['no router bgp 172 vrf default', 'router bgp 173 vrf new_vrf', 'exit']
self.execute_module(changed=True, commands=commands)
def test_bgp_change(self):
neighbor = dict(remote_as=173, neighbor='10.2.3.4')
set_module_args(dict(as_number=174, router_id='1.2.3.4',
neighbors=[neighbor],
evpn=False, fast_external_fallover=False,
max_paths=32, ecmp_bestpath=False,
))
commands = ['no router bgp 172 vrf default', 'router bgp 174 vrf default', 'exit',
'router bgp 174 vrf default router-id 1.2.3.4 force',
'router bgp 174 vrf default neighbor 10.2.3.4 remote-as 173',
'no router bgp 174 vrf default neighbor evpn peer-group',
'no router bgp 174 vrf default address-family l2vpn-evpn auto-create',
'router bgp 174 vrf default no bgp fast-external-fallover',
'router bgp 174 vrf default maximum-paths 32',
'router bgp 174 vrf default no bestpath as-path multipath-relax force']
self.execute_module(changed=True, commands=commands)
def test_bgp_add_neighbor(self):
neighbors = [dict(remote_as=173, neighbor='10.2.3.4'),
dict(remote_as=175, neighbor='10.2.3.5'),
dict(remote_as=175, neighbor='10.2.3.6', multihop=250)]
set_module_args(dict(as_number=172, router_id='1.2.3.4',
neighbors=neighbors,
networks=['172.16.1.0/24'],
evpn=True))
commands = ['router bgp 172 vrf default neighbor 10.2.3.5 remote-as 175',
'router bgp 172 vrf default neighbor 10.2.3.6 remote-as 175',
'router bgp 172 vrf default neighbor 10.2.3.6 ebgp-multihop 250',
'router bgp 172 vrf default neighbor 10.2.3.6 peer-group evpn',
'router bgp 172 vrf default neighbor 10.2.3.4 peer-group evpn']
self.execute_module(changed=True, commands=commands)
def test_bgp_del_neighbor(self):
set_module_args(dict(as_number=172,
networks=['172.16.1.0/24'],
purge=True))
commands = ['router bgp 172 vrf default no neighbor 10.2.3.4 remote-as 173',
'router bgp 172 vrf default no neighbor 10.2.3.5 remote-as 322']
self.execute_module(changed=True, commands=commands)
def test_bgp_add_network(self):
neighbors = [dict(remote_as=173, neighbor='10.2.3.4')]
set_module_args(dict(as_number=172, router_id='1.2.3.4',
neighbors=neighbors,
networks=['172.16.1.0/24', '172.16.2.0/24']))
commands = ['router bgp 172 vrf default network 172.16.2.0 /24']
self.execute_module(changed=True, commands=commands)
def test_bgp_del_network(self):
neighbors = [dict(remote_as=173, neighbor='10.2.3.4')]
set_module_args(dict(as_number=172, neighbors=neighbors))
commands = ['router bgp 172 no network 172.16.1.0 /24']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,78 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_buffer_pool
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxBufferPoolModule(TestOnyxModule):
module = onyx_buffer_pool
buffer_pool_configured = False
def setUp(self):
super(TestOnyxBufferPoolModule, self).setUp()
self.mock_get_buffer_pool_config = patch.object(
onyx_buffer_pool.OnyxBufferPoolModule, "_show_traffic_pool")
self.get_buffer_pool_config = self.mock_get_buffer_pool_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxBufferPoolModule, self).tearDown()
self.mock_get_buffer_pool_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
buffer_pool_config_file = 'onyx_buffer_pool.cfg'
self.get_buffer_pool_config.return_value = None
if self.buffer_pool_configured is True:
buffer_pool_data = load_fixture(buffer_pool_config_file)
self.get_buffer_pool_config.return_value = buffer_pool_data
self.load_config.return_value = None
def test_buffer_pool_no_change(self):
self.buffer_pool_configured = True
set_module_args(dict(name="roce", pool_type="lossless",
memory_percent=50.0, switch_priority=3))
self.execute_module(changed=False)
def test_buffer_pool_with_change(self):
set_module_args(dict(name="roce", pool_type="lossless",
memory_percent=50.0, switch_priority=3))
commands = ["traffic pool roce type lossless",
"traffic pool roce memory percent 50.0",
"traffic pool roce map switch-priority 3"
]
self.execute_module(changed=True, commands=commands)
def test_memory_percent_with_change(self):
self.buffer_pool_configured = True
set_module_args(dict(name="roce", pool_type="lossless",
memory_percent=60.0, switch_priority=3))
commands = ["traffic pool roce memory percent 60.0"]
self.execute_module(changed=True, commands=commands)
def test_switch_priority_with_change(self):
self.buffer_pool_configured = True
set_module_args(dict(name="roce", pool_type="lossless",
memory_percent=50.0, switch_priority=5))
commands = ["traffic pool roce map switch-priority 5"]
self.execute_module(changed=True, commands=commands)
def test_pool_type_with_change(self):
self.buffer_pool_configured = True
set_module_args(dict(name="roce", memory_percent=50.0, switch_priority=3))
commands = ["traffic pool roce type lossy"]
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,114 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_command
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxCommandModule(TestOnyxModule):
module = onyx_command
def setUp(self):
super(TestOnyxCommandModule, self).setUp()
self.mock_run_commands = patch(
'ansible_collections.community.general.plugins.modules.network.onyx.onyx_command.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestOnyxCommandModule, self).tearDown()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, transport='cli'):
def load_from_file(*args, **kwargs):
module, commands = args
output = list()
for item in commands:
try:
obj = json.loads(item['command'])
command = obj['command']
except ValueError:
command = item['command']
filename = str(command).replace(' ', '_')
filename = 'onyx_command_%s.txt' % filename
output.append(load_fixture(filename))
return output
self.run_commands.side_effect = load_from_file
def test_onyx_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('Product name'))
def test_onyx_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('Product name'))
def test_onyx_command_wait_for(self):
wait_for = 'result[0] contains "MLNX"'
set_module_args(dict(commands=['show version'], wait_for=wait_for))
self.execute_module()
def test_onyx_command_wait_for_fails(self):
wait_for = 'result[0] contains "test string"'
set_module_args(dict(commands=['show version'], wait_for=wait_for))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 10)
def test_onyx_command_retries(self):
wait_for = 'result[0] contains "test string"'
set_module_args(
dict(commands=['show version'], wait_for=wait_for, retries=2))
self.execute_module(failed=True)
self.assertEqual(self.run_commands.call_count, 2)
def test_onyx_command_match_any(self):
wait_for = ['result[0] contains "MLNX"',
'result[0] contains "test string"']
set_module_args(dict(
commands=['show version'],
wait_for=wait_for,
match='any'))
self.execute_module()
def test_onyx_command_match_all(self):
wait_for = ['result[0] contains "MLNX"',
'result[0] contains "Version summary"']
set_module_args(
dict(commands=['show version'], wait_for=wait_for, match='all'))
self.execute_module()
def test_onyx_command_match_all_failure(self):
wait_for = ['result[0] contains "MLNX"',
'result[0] contains "test string"']
commands = ['show version', 'show version']
set_module_args(
dict(commands=commands, wait_for=wait_for, match='all'))
self.execute_module(failed=True)

View file

@ -0,0 +1,113 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_config
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxConfigModule(TestOnyxModule):
module = onyx_config
def setUp(self):
super(TestOnyxConfigModule, self).setUp()
self.mock_get_config = patch('ansible_collections.community.general.plugins.modules.network.onyx.onyx_config.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible_collections.community.general.plugins.modules.network.onyx.onyx_config.load_config')
self.load_config = self.mock_load_config.start()
self.mock_run_commands = patch('ansible_collections.community.general.plugins.modules.network.onyx.onyx_config.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestOnyxConfigModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_config_config.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_onyx_config_unchanged(self):
src = load_fixture('onyx_config_config.cfg')
set_module_args(dict(src=src))
self.execute_module()
def test_onyx_config_src(self):
src = load_fixture('onyx_config_src.cfg')
set_module_args(dict(src=src))
commands = [
'interface mlag-port-channel 2']
self.execute_module(changed=True, commands=commands, is_updates=True)
def test_onyx_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_onyx_config_save(self):
set_module_args(dict(lines=['hostname foo'], save='yes'))
self.execute_module(changed=True)
self.assertEqual(self.run_commands.call_count, 0)
self.assertEqual(self.get_config.call_count, 1)
self.assertEqual(self.load_config.call_count, 1)
args = self.load_config.call_args[0][1]
self.assertIn('configuration write', args)
def test_onyx_config_lines_wo_parents(self):
set_module_args(dict(lines=['hostname foo']))
commands = ['hostname foo']
self.execute_module(changed=True, commands=commands, is_updates=True)
def test_onyx_config_before(self):
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
commands = ['test1', 'test2', 'hostname foo']
self.execute_module(changed=True, commands=commands, sort=False, is_updates=True)
def test_onyx_config_after(self):
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
commands = ['hostname foo', 'test1', 'test2']
self.execute_module(changed=True, commands=commands, sort=False, is_updates=True)
def test_onyx_config_before_after(self):
set_module_args(dict(lines=['hostname foo'],
before=['test1', 'test2'],
after=['test3', 'test4']))
commands = ['test1', 'test2', 'hostname foo', 'test3', 'test4']
self.execute_module(changed=True, commands=commands, sort=False, is_updates=True)
def test_onyx_config_config(self):
config = 'hostname localhost'
set_module_args(dict(lines=['hostname router'], config=config))
commands = ['hostname router']
self.execute_module(changed=True, commands=commands, is_updates=True)
def test_onyx_config_match_none(self):
lines = ['hostname router']
set_module_args(dict(lines=lines, match='none'))
self.execute_module(changed=True, commands=lines, is_updates=True)

View file

@ -0,0 +1,71 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_facts
class TestOnyxFacts(TestOnyxModule):
module = onyx_facts
def setUp(self):
super(TestOnyxFacts, self).setUp()
self.mock_run_command = patch.object(
onyx_facts.FactsBase, "_show_cmd")
self.run_command = self.mock_run_command.start()
def tearDown(self):
super(TestOnyxFacts, self).tearDown()
self.mock_run_command.stop()
def load_fixtures(self, commands=None, transport=None):
def load_from_file(*args, **kwargs):
command = args[0]
filename = "onyx_facts_%s.cfg" % command
filename = filename.replace(' ', '_')
filename = filename.replace('/', '7')
output = load_fixture(filename)
return output
self.run_command.side_effect = load_from_file
def test_onyx_facts_version(self):
set_module_args(dict(gather_subset='version'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 2)
version = facts['ansible_net_version']
self.assertEqual(version['Product name'], 'MLNX-OS')
def test_onyx_facts_modules(self):
set_module_args(dict(gather_subset='modules'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 2)
modules = facts['ansible_net_modules']
self.assertIn("MGMT", modules)
def test_onyx_facts_interfaces(self):
set_module_args(dict(gather_subset='interfaces'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 2)
interfaces = facts['ansible_net_interfaces']
self.assertEqual(len(interfaces), 2)
def test_onyx_facts_all(self):
set_module_args(dict(gather_subset='all'))
result = self.execute_module()
facts = result.get('ansible_facts')
self.assertEqual(len(facts), 4)

View file

@ -0,0 +1,127 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_igmp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxIgmpModule(TestOnyxModule):
module = onyx_igmp
enabled = False
def setUp(self):
self.enabled = False
super(TestOnyxIgmpModule, self).setUp()
self.mock_get_config = patch.object(
onyx_igmp.OnyxIgmpModule, "_show_igmp")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxIgmpModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_igmp_show.cfg'
data = load_fixture(config_file)
if self.enabled:
data[0]['IGMP snooping globally'] = 'enabled'
self.get_config.return_value = data
self.load_config.return_value = None
def test_igmp_no_change(self):
set_module_args(dict(state='disabled'))
self.execute_module(changed=False)
def test_igmp_enable(self):
set_module_args(dict(state='enabled'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_last_member_query_interval(self):
set_module_args(dict(state='enabled',
last_member_query_interval=10))
commands = ['ip igmp snooping',
'ip igmp snooping last-member-query-interval 10']
self.execute_module(changed=True, commands=commands)
def test_igmp_mrouter_timeout(self):
set_module_args(dict(state='enabled',
mrouter_timeout=100))
commands = ['ip igmp snooping',
'ip igmp snooping mrouter-timeout 100']
self.execute_module(changed=True, commands=commands)
def test_igmp_port_purge_timeout(self):
set_module_args(dict(state='enabled',
port_purge_timeout=150))
commands = ['ip igmp snooping',
'ip igmp snooping port-purge-timeout 150']
self.execute_module(changed=True, commands=commands)
def test_igmp_report_suppression_interval(self):
set_module_args(dict(state='enabled',
report_suppression_interval=10))
commands = ['ip igmp snooping',
'ip igmp snooping report-suppression-interval 10']
self.execute_module(changed=True, commands=commands)
def test_igmp_proxy_reporting_disabled(self):
set_module_args(dict(state='enabled',
proxy_reporting='disabled'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_proxy_reporting_enabled(self):
set_module_args(dict(state='enabled',
proxy_reporting='enabled'))
commands = ['ip igmp snooping',
'ip igmp snooping proxy reporting']
self.execute_module(changed=True, commands=commands)
def test_igmp_unregistered_multicast_flood(self):
set_module_args(dict(state='enabled',
unregistered_multicast='flood'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_unregistered_multicast_forward(self):
set_module_args(
dict(state='enabled',
unregistered_multicast='forward-to-mrouter-ports'))
commands = [
'ip igmp snooping',
'ip igmp snooping unregistered multicast forward-to-mrouter-ports'
]
self.execute_module(changed=True, commands=commands)
def test_igmp_version_v2(self):
set_module_args(dict(state='enabled',
default_version='V2'))
commands = ['ip igmp snooping',
'ip igmp snooping version 2']
self.execute_module(changed=True, commands=commands)
def test_igmp_version_v3(self):
set_module_args(dict(state='enabled',
default_version='V3'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_disable(self):
self.enabled = True
set_module_args(dict(state='disabled'))
commands = ['no ip igmp snooping']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,69 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_igmp_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxIgmpInterfaceModule(TestOnyxModule):
module = onyx_igmp_interface
def setUp(self):
super(TestOnyxIgmpInterfaceModule, self).setUp()
self.mock_get_config = patch.object(onyx_igmp_interface.OnyxIgmpInterfaceModule, "_show_igmp_interfaces")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxIgmpInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_igmp_interfaces.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_igmp_interface_enabled_no_change(self):
set_module_args(dict(state='enabled', name='Eth1/3'))
self.execute_module(changed=False)
def test_igmp_interface_enabled_change(self):
set_module_args(dict(state='enabled', name='Eth1/1'))
commands = ['interface ethernet 1/1 ip igmp snooping fast-leave']
self.execute_module(changed=True, commands=commands)
def test_igmp_interface_disabled_no_change(self):
set_module_args(dict(state='disabled', name='Eth1/1'))
self.execute_module(changed=False)
def test_igmp_interface_disabled_change(self):
set_module_args(dict(state='disabled', name='Eth1/3'))
commands = ['interface ethernet 1/3 no ip igmp snooping fast-leave']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,190 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_igmp_vlan
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxIgmpVlan(TestOnyxModule):
module = onyx_igmp_vlan
enabled = False
mrouter_state = False
querier_state = False
static_groups_enabled = False
def setUp(self):
self.enabled = False
super(TestOnyxIgmpVlan, self).setUp()
self.mock_get_igmp_config = patch.object(
onyx_igmp_vlan.OnyxIgmpVlanModule, "_show_igmp_vlan")
self.get_igmp_config = self.mock_get_igmp_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_igmp_guerier_config = patch.object(
onyx_igmp_vlan.OnyxIgmpVlanModule, "_show_igmp_querier_config")
self.get_igmp_guerier_config = self.mock_get_igmp_guerier_config.start()
self.mock_get_igmp_static_groups_config = patch.object(
onyx_igmp_vlan.OnyxIgmpVlanModule, "_show_igmp_snooping_groups_config")
self.get_igmp_static_groups_config = self.mock_get_igmp_static_groups_config.start()
def tearDown(self):
super(TestOnyxIgmpVlan, self).tearDown()
self.mock_get_igmp_config.stop()
self.mock_load_config.stop()
self.mock_get_igmp_guerier_config.stop()
self.mock_get_igmp_static_groups_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
igmp_vlan_config_file = 'onyx_show_ip_igmp_snooping.cfg'
igmp_querier_config_file = 'onyx_show_ip_igmp_snooping_querier.cfg'
igmp_static_groups_file = 'onyx_show_ip_igmp_snooping_groups.cfg'
igmp_vlan_data = load_fixture(igmp_vlan_config_file)
igmp_querier_data = load_fixture(igmp_querier_config_file)
igmp_static_groups_data = None
if self.enabled:
igmp_vlan_data[0]['message 1'] = 'IGMP snooping is enabled'
if self.querier_state:
igmp_vlan_data[0]['message 3'] = 'Snooping switch is acting as Querier'
if self.mrouter_state:
igmp_vlan_data[0]['mrouter static port list'] = 'Eth1/1'
if self.static_groups_enabled:
igmp_static_groups_data = load_fixture(igmp_static_groups_file)
self.get_igmp_config.return_value = igmp_vlan_data
self.get_igmp_guerier_config = igmp_querier_data
self.get_igmp_static_groups_config = igmp_static_groups_data
self.load_config.return_value = None
def test_igmp_disabled_no_change(self):
set_module_args(dict(state='disabled', vlan_id=10))
self.execute_module(changed=False)
def test_igmp_disabled_with_change(self):
self.enabled = True
set_module_args(dict(state='disabled', vlan_id=10))
commands = ['vlan 10 no ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_enabled_no_change(self):
self.enabled = True
set_module_args(dict(state='enabled', vlan_id=10))
self.execute_module(changed=False)
def test_igmp_enabled_with_change(self):
set_module_args(dict(state='enabled', vlan_id=10))
commands = ['vlan 10 ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_mrouter_disabled_no_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, mrouter=dict(state='disabled', name='Eth1/1')))
self.execute_module(changed=False)
def test_igmp_mrouter_disabled_with_change(self):
self.enabled = True
self.mrouter_state = True
set_module_args(dict(vlan_id=10, mrouter=dict(state='disabled', name='Eth1/1')))
commands = ['vlan 10 no ip igmp snooping mrouter interface ethernet 1/1']
self.execute_module(changed=True, commands=commands)
def test_igmp_mrouter_enabled_no_change(self):
self.enabled = True
self.mrouter_state = True
set_module_args(dict(vlan_id=10, mrouter=dict(state='enabled', name='Eth1/1')))
self.execute_module(changed=False)
def test_igmp_mrouter_enabled_with_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, mrouter=dict(state='enabled', name='Eth1/1')))
commands = ['vlan 10 ip igmp snooping mrouter interface ethernet 1/1']
self.execute_module(changed=True, commands=commands)
def test_igmp_mrouter_enabled_withinterface_change(self):
self.enabled = True
self.mrouter_state = True
set_module_args(dict(vlan_id=10, mrouter=dict(state='enabled', name='Eth1/2')))
commands = ['vlan 10 ip igmp snooping mrouter interface ethernet 1/2']
self.execute_module(changed=True, commands=commands)
def test_igmp_querier_disabled_no_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, querier=dict(state='disabled')))
self.execute_module(changed=False)
def test_igmp_querier_disabled_with_change(self):
self.enabled = True
self.querier_state = True
set_module_args(dict(vlan_id=10, querier=dict(state='disabled')))
commands = ['vlan 10 no ip igmp snooping querier']
self.execute_module(changed=True, commands=commands)
def test_igmp_querier_enabled_no_change(self):
self.enabled = True
self.querier_state = True
set_module_args(dict(vlan_id=10, querier=dict(state='enabled')))
self.execute_module(changed=False)
def test_igmp_querier_enabled_with_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, querier=dict(state='enabled')))
commands = ['vlan 10 ip igmp snooping querier']
self.execute_module(changed=True, commands=commands)
def test_igmp_querier_attr_no_change(self):
self.enabled = True
self.querier_state = True
set_module_args(dict(vlan_id=10, querier=dict(state='enabled', interval=125, address='-')))
self.execute_module(changed=True)
def test_igmp_querier_attr_with_change(self):
self.enabled = True
self.querier_state = True
set_module_args(dict(vlan_id=10, querier=dict(state='enabled', interval=127, address='10.10.10.1')))
commands = ['vlan 10 ip igmp snooping querier query-interval 127',
'vlan 10 ip igmp snooping querier address 10.10.10.1']
self.execute_module(changed=True, commands=commands)
def test_igmp_version_no_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, version='V3'))
self.execute_module(changed=False)
def test_igmp_version_with_change(self):
self.enabled = True
set_module_args(dict(vlan_id=10, version='V2'))
commands = ['vlan 10 ip igmp snooping version 2']
self.execute_module(changed=True, commands=commands)
def test_igmp_static_groups_multicast_ip_address_not_configured(self):
self.enabled = True
set_module_args(dict(vlan_id=10, static_groups=[dict(multicast_ip_address='224.5.5.2', name='Eth1/1',
sources=["1.1.1.2", "1.1.1.3"])]))
commands = ['vlan 10 ip igmp snooping static-group 224.5.5.2 interface ethernet 1/1',
'vlan 10 ip igmp snooping static-group 224.5.5.2 interface ethernet 1/1 source 1.1.1.2',
'vlan 10 ip igmp snooping static-group 224.5.5.2 interface ethernet 1/1 source 1.1.1.3']
self.execute_module(changed=True, commands=commands)
def test_igmp_static_groups_multicast_ip_address_configured_with_change(self):
self.enabled = True
self.static_groups_enabled = True
set_module_args(dict(vlan_id=10, static_groups=[dict(multicast_ip_address='224.5.5.1', name='Eth1/3',
sources=["1.1.1.1", "1.1.1.2"])]))
commands = ['vlan 10 ip igmp snooping static-group 224.5.5.1 interface ethernet 1/3',
'vlan 10 ip igmp snooping static-group 224.5.5.1 interface ethernet 1/3 source 1.1.1.1',
'vlan 10 ip igmp snooping static-group 224.5.5.1 interface ethernet 1/3 source 1.1.1.2']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,125 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxInterfaceModule(TestOnyxModule):
module = onyx_interface
def setUp(self):
super(TestOnyxInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_interface.OnyxInterfaceModule, "_get_interfaces_config")
self.get_config = self.mock_get_config.start()
self.mock_get_interfaces_status = patch.object(
onyx_interface.OnyxInterfaceModule, "_get_interfaces_status")
self.get_interfaces_status = self.mock_get_interfaces_status.start()
self.mock_get_interfaces_rates = patch.object(
onyx_interface.OnyxInterfaceModule, "_get_interfaces_rates")
self.get_interfaces_rates = self.mock_get_interfaces_rates.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_interface.OnyxInterfaceModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_interfaces_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def test_mtu_no_change(self):
set_module_args(dict(name='Eth1/1', mtu=1500))
self.execute_module(changed=False)
def test_mtu_change(self):
set_module_args(dict(name='Eth1/1', mtu=1522))
commands = ['interface ethernet 1/1', 'mtu 1522 force', 'exit']
self.execute_module(changed=True, commands=commands)
def test_speed_no_change(self):
set_module_args(dict(name='Eth1/1', speed='40G'))
self.execute_module(changed=False)
def test_speed_change(self):
set_module_args(dict(name='Eth1/1', speed='100G'))
commands = ['interface ethernet 1/1', 'speed 100G force', 'exit']
self.execute_module(changed=True, commands=commands)
def test_mtu_speed_change(self):
set_module_args(dict(name='Eth1/1', speed='100G', mtu=1522))
commands = ['interface ethernet 1/1', 'speed 100G force',
'mtu 1522 force', 'exit']
self.execute_module(changed=True, commands=commands)
def test_admin_state_no_change(self):
set_module_args(dict(name='Eth1/1', enabled=True))
self.execute_module(changed=False)
def test_admin_state_change(self):
set_module_args(dict(name='Eth1/1', enabled=False))
commands = ['interface ethernet 1/1', 'shutdown', 'exit']
self.execute_module(changed=True, commands=commands)
def test_add_loopback_if(self):
set_module_args(dict(name='Loopback 1', description='Loopback test'))
commands = ['interface loopback 1', 'description Loopback test',
'exit']
self.execute_module(changed=True, commands=commands)
def test_add_vlan_if(self):
set_module_args(dict(name='Vlan 101', description='Vlan test',
enabled=True))
commands = ['interface vlan 101', 'description Vlan test',
'no shutdown', 'exit']
self.execute_module(changed=True, commands=commands)
def test_remove_vlan_if(self):
set_module_args(dict(name='Vlan 1002', state='absent'))
commands = ['no interface vlan 1002']
self.execute_module(changed=True, commands=commands)
def test_oper_state_check(self):
set_module_args(dict(name='Eth1/1', enabled=True, state='down'))
config_file = 'onyx_interfaces_status.cfg'
self.get_interfaces_status.return_value = load_fixture(config_file)
self.execute_module(changed=False)
def test_vlan_oper_state_check(self):
set_module_args(dict(name='Vlan 1002', state='down'))
config_file = 'onyx_interfaces_status.cfg'
self.get_interfaces_status.return_value = load_fixture(config_file)
self.execute_module(changed=False)
def test_rx_rate_check(self):
set_module_args(dict(name='Eth1/1', enabled=True, rx_rate='ge(9000)'))
config_file = 'onyx_interfaces_rates.cfg'
self.get_interfaces_rates.return_value = load_fixture(config_file)
self.execute_module(changed=False)
def test_tx_rate_check(self):
set_module_args(dict(name='Eth1/1', enabled=True, tx_rate='ge(10000)'))
config_file = 'onyx_interfaces_rates.cfg'
self.get_interfaces_rates.return_value = load_fixture(config_file)
self.execute_module(changed=False)

View file

@ -0,0 +1,119 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_l2_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxInterfaceModule(TestOnyxModule):
module = onyx_l2_interface
def setUp(self):
super(TestOnyxInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_l2_interface.OnyxL2InterfaceModule, "_get_switchport_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_l2_interface.OnyxL2InterfaceModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_l2_interface_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def test_access_vlan_no_change(self):
set_module_args(dict(name='Eth1/11', access_vlan=1))
self.execute_module(changed=False)
def test_trunk_vlans_no_change(self):
set_module_args(dict(name='Eth1/10', mode='hybrid', access_vlan=1,
trunk_allowed_vlans=[10]))
self.execute_module(changed=False)
def test_access_vlan_change(self):
set_module_args(dict(name='Eth1/11', access_vlan=10))
commands = ['interface ethernet 1/11', 'switchport access vlan 10',
'exit']
self.execute_module(changed=True, commands=commands)
def test_trunk_vlan_change(self):
set_module_args(dict(name='Eth1/10', mode='hybrid', access_vlan=1,
trunk_allowed_vlans=[11]))
commands = ['interface ethernet 1/10',
'switchport hybrid allowed-vlan remove 10',
'switchport hybrid allowed-vlan add 11', 'exit']
self.execute_module(changed=True, commands=commands)
def test_trunk_vlan_add(self):
set_module_args(dict(name='Eth1/10', mode='hybrid', access_vlan=1,
trunk_allowed_vlans=[10, 11]))
commands = ['interface ethernet 1/10',
'switchport hybrid allowed-vlan add 11', 'exit']
self.execute_module(changed=True, commands=commands)
def test_switch_port_access(self):
set_module_args(dict(name='Eth1/12', mode='access', access_vlan=11))
commands = ['interface ethernet 1/12', 'switchport mode access',
'switchport access vlan 11', 'exit']
self.execute_module(changed=True, commands=commands)
def test_switch_port_trunk(self):
set_module_args(dict(name='Eth1/12', mode='trunk',
trunk_allowed_vlans=[11]))
commands = ['interface ethernet 1/12', 'switchport mode trunk',
'switchport trunk allowed-vlan add 11', 'exit']
self.execute_module(changed=True, commands=commands)
def test_switch_port_hybrid(self):
set_module_args(dict(name='Eth1/12', mode='hybrid', access_vlan=10,
trunk_allowed_vlans=[11]))
commands = ['interface ethernet 1/12', 'switchport mode hybrid',
'switchport access vlan 10',
'switchport hybrid allowed-vlan add 11', 'exit']
self.execute_module(changed=True, commands=commands)
def test_aggregate(self):
aggregate = list()
aggregate.append(dict(name='Eth1/10'))
aggregate.append(dict(name='Eth1/12'))
set_module_args(dict(aggregate=aggregate, access_vlan=10))
commands = ['interface ethernet 1/10', 'switchport mode access',
'switchport access vlan 10', 'exit',
'interface ethernet 1/12', 'switchport mode access',
'switchport access vlan 10', 'exit']
self.execute_module(changed=True, commands=commands, sort=False)

View file

@ -0,0 +1,113 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_l3_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxL3InterfaceModule(TestOnyxModule):
module = onyx_l3_interface
def setUp(self):
super(TestOnyxL3InterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_l3_interface.OnyxL3InterfaceModule,
"_get_interfaces_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_l3_interface.OnyxL3InterfaceModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxL3InterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def _execute_module(self, failed=False, changed=False, commands=None, sort=True):
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:
commands_res = result.get('commands')
if sort:
self.assertEqual(sorted(commands), sorted(commands_res), commands_res)
else:
self.assertEqual(commands, commands_res, commands_res)
return result
def load_fixture(self, config_file):
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def load_eth_ifc_fixture(self):
config_file = 'onyx_l3_interface_show.cfg'
self.load_fixture(config_file)
def load_vlan_ifc_fixture(self):
config_file = 'onyx_l3_vlan_interface_show.cfg'
self.load_fixture(config_file)
def test_vlan_ifc_no_change(self):
set_module_args(dict(name='Vlan 1002', state='present',
ipv4='172.3.12.4/24'))
self.load_vlan_ifc_fixture()
self._execute_module(changed=False)
def test_vlan_ifc_remove(self):
set_module_args(dict(name='Vlan 1002', state='absent'))
commands = ['interface vlan 1002 no ip address']
self.load_vlan_ifc_fixture()
self._execute_module(changed=True, commands=commands)
def test_vlan_ifc_update(self):
set_module_args(dict(name='Vlan 1002', state='present',
ipv4='172.3.13.4/24'))
commands = ['interface vlan 1002 ip address 172.3.13.4/24']
self.load_vlan_ifc_fixture()
self._execute_module(changed=True, commands=commands)
def test_eth_ifc_no_change(self):
set_module_args(dict(name='Eth1/5', state='present',
ipv4='172.3.12.4/24'))
self.load_eth_ifc_fixture()
self._execute_module(changed=False)
def test_eth_ifc_remove(self):
set_module_args(dict(name='Eth1/5', state='absent'))
commands = ['interface ethernet 1/5 no ip address']
self.load_eth_ifc_fixture()
self._execute_module(changed=True, commands=commands)
def test_eth_ifc_update(self):
set_module_args(dict(name='Eth1/5', state='present',
ipv4='172.3.13.4/24'))
commands = ['interface ethernet 1/5 ip address 172.3.13.4/24']
self.load_eth_ifc_fixture()
self._execute_module(changed=True, commands=commands)
def test_eth_ifc_add_ip(self):
set_module_args(dict(name='Eth1/6', state='present',
ipv4='172.3.14.4/24'))
commands = ['interface ethernet 1/6 no switchport force',
'interface ethernet 1/6 ip address 172.3.14.4/24']
self.load_eth_ifc_fixture()
self._execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,116 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_linkagg
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxLinkaggModule(TestOnyxModule):
module = onyx_linkagg
def setUp(self):
super(TestOnyxLinkaggModule, self).setUp()
self.mock_get_config = patch.object(
onyx_linkagg.OnyxLinkAggModule,
"_get_port_channels")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_linkagg.OnyxLinkAggModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxLinkaggModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()
def load_fixture(self, config_file):
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def load_port_channel_fixture(self):
config_file = 'onyx_port_channel_show.cfg'
self.load_fixture(config_file)
def load_mlag_port_channel_fixture(self):
config_file = 'onyx_mlag_port_channel_show.cfg'
self.load_fixture(config_file)
def test_port_channel_no_change(self):
set_module_args(dict(name='Po22', state='present',
members=['Eth1/7']))
self.load_port_channel_fixture()
self.execute_module(changed=False)
def test_port_channel_remove(self):
set_module_args(dict(name='Po22', state='absent'))
self.load_port_channel_fixture()
commands = ['no interface port-channel 22']
self.execute_module(changed=True, commands=commands)
def test_port_channel_add(self):
set_module_args(dict(name='Po23', state='present',
members=['Eth1/8']))
self.load_port_channel_fixture()
commands = ['interface port-channel 23', 'exit',
'interface ethernet 1/8 channel-group 23 mode on']
self.execute_module(changed=True, commands=commands)
def test_port_channel_add_member(self):
set_module_args(dict(name='Po22', state='present',
members=['Eth1/7', 'Eth1/8']))
self.load_port_channel_fixture()
commands = ['interface ethernet 1/8 channel-group 22 mode on']
self.execute_module(changed=True, commands=commands)
def test_port_channel_remove_member(self):
set_module_args(dict(name='Po22', state='present'))
self.load_port_channel_fixture()
commands = ['interface ethernet 1/7 no channel-group']
self.execute_module(changed=True, commands=commands)
def test_mlag_port_channel_no_change(self):
set_module_args(dict(name='Mpo33', state='present',
members=['Eth1/8']))
self.load_mlag_port_channel_fixture()
self.execute_module(changed=False)
def test_mlag_port_channel_remove(self):
set_module_args(dict(name='Mpo33', state='absent'))
self.load_mlag_port_channel_fixture()
commands = ['no interface mlag-port-channel 33']
self.execute_module(changed=True, commands=commands)
def test_mlag_port_channel_add(self):
set_module_args(dict(name='Mpo34', state='present',
members=['Eth1/9']))
self.load_mlag_port_channel_fixture()
commands = ['interface mlag-port-channel 34', 'exit',
'interface ethernet 1/9 mlag-channel-group 34 mode on']
self.execute_module(changed=True, commands=commands)
def test_mlag_port_channel_add_member(self):
set_module_args(dict(name='Mpo33', state='present',
members=['Eth1/8', 'Eth1/9']))
self.load_mlag_port_channel_fixture()
commands = ['interface ethernet 1/9 mlag-channel-group 33 mode on']
self.execute_module(changed=True, commands=commands)
def test_mlag_port_channel_remove_member(self):
set_module_args(dict(name='Mpo33', state='present'))
self.load_mlag_port_channel_fixture()
commands = ['interface ethernet 1/8 no mlag-channel-group']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,68 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_lldp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxInterfaceModule(TestOnyxModule):
module = onyx_lldp
def setUp(self):
super(TestOnyxInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_lldp.OnyxLldpModule, "_get_lldp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if commands == ['lldp']:
self.get_config.return_value = None
else:
config_file = 'onyx_lldp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_lldp_no_change(self):
set_module_args(dict())
self.execute_module(changed=False)
def test_lldp_disable(self):
set_module_args(dict(state='absent'))
commands = ['no lldp']
self.execute_module(changed=True, commands=commands)
def test_lldp_enable(self):
set_module_args(dict(state='present'))
commands = ['lldp']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,76 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_lldp_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxLldpInterfaceModule(TestOnyxModule):
module = onyx_lldp_interface
def setUp(self):
super(TestOnyxLldpInterfaceModule, self).setUp()
self.mock_get_config = patch.object(
onyx_lldp_interface.OnyxLldpInterfaceModule,
"_get_lldp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxLldpInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_lldp_interface_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_lldp_no_change(self):
set_module_args(dict(name='Eth1/1', state='present'))
self.execute_module(changed=False)
def test_no_lldp_no_change(self):
set_module_args(dict(name='Eth1/2', state='absent'))
self.execute_module(changed=False)
def test_no_lldp_change(self):
set_module_args(dict(name='Eth1/2', state='present'))
commands = ['interface ethernet 1/2 lldp receive',
'interface ethernet 1/2 lldp transmit']
self.execute_module(changed=True, commands=commands)
def test_lldp_change(self):
set_module_args(dict(name='Eth1/1', state='absent'))
commands = ['interface ethernet 1/1 no lldp receive',
'interface ethernet 1/1 no lldp transmit']
self.execute_module(changed=True, commands=commands)
def test_lldp_aggregate(self):
aggregate = [dict(name='Eth1/1'), dict(name='Eth1/2')]
set_module_args(dict(aggregate=aggregate, state='present'))
commands = ['interface ethernet 1/2 lldp receive',
'interface ethernet 1/2 lldp transmit']
self.execute_module(changed=True, commands=commands)
def test_lldp_aggregate_purge(self):
aggregate = [dict(name='Eth1/3'), dict(name='Eth1/2')]
set_module_args(dict(aggregate=aggregate, state='present', purge=True))
commands = ['interface ethernet 1/2 lldp receive',
'interface ethernet 1/2 lldp transmit',
'interface ethernet 1/3 lldp receive',
'interface ethernet 1/3 lldp transmit',
'interface ethernet 1/1 no lldp receive',
'interface ethernet 1/1 no lldp transmit']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,110 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_magp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxMagpModule(TestOnyxModule):
module = onyx_magp
def setUp(self):
super(TestOnyxMagpModule, self).setUp()
self.mock_get_config = patch.object(
onyx_magp.OnyxMagpModule,
"_get_magp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(onyx_magp.OnyxMagpModule,
"_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxMagpModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_magp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def test_magp_absent_no_change(self):
set_module_args(dict(interface='Vlan 1002', magp_id=110,
state='absent'))
self.execute_module(changed=False)
def test_magp_no_change(self):
set_module_args(dict(interface='Vlan 1200', magp_id=103,
state='disabled'))
self.execute_module(changed=False)
def test_magp_present_no_change(self):
set_module_args(dict(interface='Vlan 1200', magp_id=103))
self.execute_module(changed=False)
def test_magp_enable(self):
set_module_args(dict(interface='Vlan 1200', magp_id=103,
state='enabled'))
commands = ['interface vlan 1200 magp 103 no shutdown']
self.execute_module(changed=True, commands=commands)
def test_magp_disable(self):
set_module_args(dict(interface='Vlan 1243', magp_id=102,
state='disabled', router_ip='10.0.0.43',
router_mac='01:02:03:04:05:06'))
commands = ['interface vlan 1243 magp 102 shutdown']
self.execute_module(changed=True, commands=commands)
def test_magp_change_address(self):
set_module_args(dict(interface='Vlan 1243', magp_id=102,
router_ip='10.0.0.44',
router_mac='01:02:03:04:05:07'))
commands = [
'interface vlan 1243 magp 102 ip virtual-router address 10.0.0.44',
'interface vlan 1243 magp 102 ip virtual-router mac-address 01:02:03:04:05:07']
self.execute_module(changed=True, commands=commands)
def test_magp_remove_address(self):
set_module_args(dict(interface='Vlan 1243', magp_id=102))
commands = [
'interface vlan 1243 magp 102 no ip virtual-router address',
'interface vlan 1243 magp 102 no ip virtual-router mac-address']
self.execute_module(changed=True, commands=commands)
def test_magp_add(self):
set_module_args(dict(interface='Vlan 1244', magp_id=104,
router_ip='10.0.0.44',
router_mac='01:02:03:04:05:07'))
commands = [
'interface vlan 1244 magp 104',
'exit',
'interface vlan 1244 magp 104 ip virtual-router address 10.0.0.44',
'interface vlan 1244 magp 104 ip virtual-router mac-address 01:02:03:04:05:07']
self.execute_module(changed=True, commands=commands, sort=False)
def test_magp_change_vlan(self):
set_module_args(dict(interface='Vlan 1244', magp_id=102,
router_ip='10.0.0.43',
router_mac='01:02:03:04:05:06'))
commands = [
'interface vlan 1243 no magp 102',
'interface vlan 1244 magp 102',
'exit',
'interface vlan 1244 magp 102 ip virtual-router address 10.0.0.43',
'interface vlan 1244 magp 102 ip virtual-router mac-address 01:02:03:04:05:06']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,86 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_mlag_ipl
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxMlagIplModule(TestOnyxModule):
module = onyx_mlag_ipl
def setUp(self):
super(TestOnyxMlagIplModule, self).setUp()
self._mlag_enabled = True
self.mock_get_config = patch.object(
onyx_mlag_ipl.OnyxMlagIplModule,
"_show_mlag_data")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxMlagIplModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._mlag_enabled:
config_file = 'onyx_mlag_ipl_show.cfg'
self.get_config.return_value = load_fixture(config_file)
else:
self.get_config.return_value = None
self.load_config.return_value = None
def test_no_ipl_no_change(self):
self._mlag_enabled = False
set_module_args(dict(name="Po1", state='absent'))
self.execute_module(changed=False)
def test_ipl_no_change(self):
self._mlag_enabled = True
set_module_args(dict(name="Po1", state='present',
vlan_interface='Vlan 1002',
peer_address='10.2.2.2'))
self.execute_module(changed=False)
def test_ipl_add(self):
self._mlag_enabled = False
set_module_args(dict(name="Po1", state='present',
vlan_interface='Vlan 1002',
peer_address='10.2.2.2'))
commands = ['interface port-channel 1 ipl 1',
'interface vlan 1002 ipl 1 peer-address 10.2.2.2']
self.execute_module(changed=True, commands=commands)
def test_ipl_add_peer(self):
self._mlag_enabled = True
set_module_args(dict(name="Po1", state='present',
vlan_interface='Vlan 1002',
peer_address='10.2.2.4'))
commands = ['interface vlan 1002 ipl 1 peer-address 10.2.2.4']
self.execute_module(changed=True, commands=commands)
def test_ipl_remove(self):
self._mlag_enabled = True
set_module_args(dict(name="Po1", state='absent'))
commands = ['interface port-channel 1 no ipl 1']
self.execute_module(changed=True, commands=commands)
def test_ipl_change_vlan(self):
self._mlag_enabled = True
set_module_args(dict(name="Po1", state='present',
vlan_interface='Vlan 1003',
peer_address='10.2.2.4'))
commands = ['interface vlan 1002 no ipl 1',
'interface vlan 1003 ipl 1 peer-address 10.2.2.4']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,84 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_mlag_vip
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxMlagVipModule(TestOnyxModule):
module = onyx_mlag_vip
def setUp(self):
super(TestOnyxMlagVipModule, self).setUp()
self._mlag_enabled = True
self.mock_show_mlag = patch.object(
onyx_mlag_vip.OnyxMLagVipModule,
"_show_mlag")
self.show_mlag = self.mock_show_mlag.start()
self.mock_show_mlag_vip = patch.object(
onyx_mlag_vip.OnyxMLagVipModule,
"_show_mlag_vip")
self.show_mlag_vip = self.mock_show_mlag_vip.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxMlagVipModule, self).tearDown()
self.mock_show_mlag.stop()
self.mock_show_mlag_vip.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._mlag_enabled:
config_file = 'onyx_mlag_vip_show.cfg'
self.show_mlag_vip.return_value = load_fixture(config_file)
config_file = 'onyx_mlag_show.cfg'
self.show_mlag.return_value = load_fixture(config_file)
else:
self.show_mlag_vip.return_value = None
self.show_mlag.return_value = None
self.load_config.return_value = None
def test_mlag_no_change(self):
set_module_args(dict(ipaddress='10.209.25.107/24',
group_name='neo-mlag-vip-500',
mac_address='00:00:5E:00:01:4E'))
self.execute_module(changed=False)
def test_mlag_change(self):
self._mlag_enabled = False
set_module_args(dict(ipaddress='10.209.25.107/24',
group_name='neo-mlag-vip-500',
mac_address='00:00:5E:00:01:4E',
delay=0))
commands = ['mlag-vip neo-mlag-vip-500 ip 10.209.25.107 /24 force',
'mlag system-mac 00:00:5e:00:01:4e', 'no mlag shutdown']
self.execute_module(changed=True, commands=commands)
def test_mlag_send_group_name_only_change(self):
self._mlag_enabled = False
set_module_args(dict(group_name='neo-mlag-vip-500',
delay=0))
commands = ['mlag-vip neo-mlag-vip-500',
'no mlag shutdown']
self.execute_module(changed=True, commands=commands)
def test_mlag_absent_no_change(self):
self._mlag_enabled = False
set_module_args(dict(state='absent'))
self.execute_module(changed=False)
def test_mlag_absent_change(self):
set_module_args(dict(state='absent', delay=0))
commands = ['no mlag-vip']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,76 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_ntp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxNTP(TestOnyxModule):
module = onyx_ntp
enabled = False
def setUp(self):
self.enabled = False
super(TestOnyxNTP, self).setUp()
self.mock_get_config = patch.object(
onyx_ntp.OnyxNTPModule, "_show_ntp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxNTP, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_ntp_show.cfg'
data = load_fixture(config_file)
self.get_config.return_value = data
self.load_config.return_value = None
def test_ntp_state_no_change(self):
set_module_args(dict(state='enabled'))
self.execute_module(changed=False)
def test_ntp_state_with_change(self):
set_module_args(dict(state='disabled'))
commands = ['no ntp enable']
self.execute_module(changed=True, commands=commands)
def test_ntp_authenticate_state_no_change(self):
set_module_args(dict(authenticate_state='disabled'))
self.execute_module(changed=False)
def test_ntp_authenticate_state_with_change(self):
set_module_args(dict(authenticate_state='enabled'))
commands = ['ntp authenticate']
self.execute_module(changed=True, commands=commands)
def test_ntp_authentication_key_no_change(self):
set_module_args(dict(ntp_authentication_keys=[dict(auth_key_id='22',
auth_key_encrypt_type='sha1',
auth_key_password='12345')]))
self.execute_module(changed=False)
def test_ntp_authentication_key_with_change(self):
set_module_args(dict(ntp_authentication_keys=[dict(auth_key_id='22',
auth_key_encrypt_type='md5',
auth_key_password='12345')]))
commands = ['ntp authentication-key 22 md5 12345']
self.execute_module(changed=True, commands=commands)
def test_ntp_trusted_keys_with_change(self):
set_module_args(dict(trusted_keys='22'))
commands = ['ntp trusted-key 22']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,134 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_ntp_servers_peers
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxNtpServersPeersModule(TestOnyxModule):
module = onyx_ntp_servers_peers
enabled = False
def setUp(self):
self.enabled = False
super(TestOnyxNtpServersPeersModule, self).setUp()
self.mock_get_config = patch.object(
onyx_ntp_servers_peers.OnyxNTPServersPeersModule, "_show_peers_servers_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxNtpServersPeersModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_ntp_servers_peers_show.cfg'
data = load_fixture(config_file)
self.get_config.return_value = data
self.load_config.return_value = None
def test_ntp_peer_state_no_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
enabled='yes')]))
self.execute_module(changed=False)
def test_ntp_peer_state_with_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
enabled='no')]))
commands = ['ntp peer 1.1.1.1 disable']
self.execute_module(changed=True, commands=commands)
def test_ntp_peer_version_no_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
version='4')]))
self.execute_module(changed=False)
def test_ntp_peer_version_with_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
version='3')]))
commands = ['ntp peer 1.1.1.1 version 3']
self.execute_module(changed=True, commands=commands)
def test_ntp_peer_key_id_no_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
key_id='5')]))
self.execute_module(changed=False)
def test_ntp_peer_key_id_with_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
key_id='6')]))
commands = ['ntp peer 1.1.1.1 keyID 6']
self.execute_module(changed=True, commands=commands)
def test_ntp_peer_delete_with_change(self):
set_module_args(dict(peer=[dict(ip_or_name='1.1.1.1',
state='absent')]))
commands = ['no ntp peer 1.1.1.1']
self.execute_module(changed=True, commands=commands)
def test_ntp_server_state_no_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
enabled='no')]))
self.execute_module(changed=False)
def test_ntp_server_state_with_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
enabled='yes')]))
commands = ['no ntp server 2.2.2.2 disable']
self.execute_module(changed=True, commands=commands)
def test_ntp_server_version_no_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
version='4')]))
self.execute_module(changed=False)
def test_ntp_server_version_with_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
version='3')]))
commands = ['ntp server 2.2.2.2 version 3']
self.execute_module(changed=True, commands=commands)
def test_ntp_server_keyID_no_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
key_id='99')]))
self.execute_module(changed=False)
def test_ntp_server_keyID_with_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
key_id='8')]))
commands = ['ntp server 2.2.2.2 keyID 8']
self.execute_module(changed=True, commands=commands)
def test_ntp_server_trusted_state_no_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
trusted_enable='yes')]))
self.execute_module(changed=False)
def test_ntp_server_trusted_state_with_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
trusted_enable='no')]))
commands = ['no ntp server 2.2.2.2 trusted-enable']
self.execute_module(changed=True, commands=commands)
def test_ntp_server_delete_with_change(self):
set_module_args(dict(server=[dict(ip_or_name='2.2.2.2',
state='absent')]))
commands = ['no ntp server 2.2.2.2']
self.execute_module(changed=True, commands=commands)
def test_ntpdate_with_change(self):
set_module_args(dict(ntpdate='192.22.1.66'))
commands = ['ntpdate 192.22.1.66']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,106 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_ospf
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxOspfModule(TestOnyxModule):
module = onyx_ospf
def setUp(self):
super(TestOnyxOspfModule, self).setUp()
self._ospf_exists = True
self.mock_get_config = patch.object(
onyx_ospf.OnyxOspfModule,
"_get_ospf_config")
self.get_config = self.mock_get_config.start()
self.mock_get_interfaces_config = patch.object(
onyx_ospf.OnyxOspfModule,
"_get_ospf_interfaces_config")
self.get_interfaces_config = self.mock_get_interfaces_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxOspfModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._ospf_exists:
config_file = 'onyx_ospf_show.cfg'
self.get_config.return_value = load_fixture(config_file)
config_file = 'onyx_ospf_interfaces_show.cfg'
self.get_interfaces_config.return_value = load_fixture(config_file)
else:
self.get_config.return_value = None
self.get_interfaces_config.return_value = None
self.load_config.return_value = None
def test_ospf_absent_no_change(self):
set_module_args(dict(ospf=3, state='absent'))
self.execute_module(changed=False)
def test_ospf_present_no_change(self):
interface = dict(name='Loopback 1', area='0.0.0.0')
set_module_args(dict(ospf=2, router_id='10.2.3.4',
interfaces=[interface]))
self.execute_module(changed=False)
def test_ospf_present_remove(self):
set_module_args(dict(ospf=2, state='absent'))
commands = ['no router ospf 2']
self.execute_module(changed=True, commands=commands)
def test_ospf_change_router(self):
interface = dict(name='Loopback 1', area='0.0.0.0')
set_module_args(dict(ospf=2, router_id='10.2.3.5',
interfaces=[interface]))
commands = ['router ospf 2', 'router-id 10.2.3.5', 'exit']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ospf_remove_router(self):
interface = dict(name='Loopback 1', area='0.0.0.0')
set_module_args(dict(ospf=2, interfaces=[interface]))
commands = ['router ospf 2', 'no router-id', 'exit']
self.execute_module(changed=True, commands=commands, sort=False)
def test_ospf_add_interface(self):
interfaces = [dict(name='Loopback 1', area='0.0.0.0'),
dict(name='Loopback 2', area='0.0.0.0')]
set_module_args(dict(ospf=2, router_id='10.2.3.4',
interfaces=interfaces))
commands = ['interface loopback 2 ip ospf area 0.0.0.0']
self.execute_module(changed=True, commands=commands)
def test_ospf_remove_interface(self):
set_module_args(dict(ospf=2, router_id='10.2.3.4'))
commands = ['interface loopback 1 no ip ospf area']
self.execute_module(changed=True, commands=commands)
def test_ospf_add(self):
self._ospf_exists = False
interfaces = [dict(name='Loopback 1', area='0.0.0.0'),
dict(name='Vlan 210', area='0.0.0.0'),
dict(name='Eth1/1', area='0.0.0.0'),
dict(name='Po1', area='0.0.0.0')]
set_module_args(dict(ospf=2, router_id='10.2.3.4',
interfaces=interfaces))
commands = ['router ospf 2', 'router-id 10.2.3.4', 'exit',
'interface loopback 1 ip ospf area 0.0.0.0',
'interface vlan 210 ip ospf area 0.0.0.0',
'interface ethernet 1/1 ip ospf area 0.0.0.0',
'interface port-channel 1 ip ospf area 0.0.0.0']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,114 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_pfc_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxPfcInterfaceModule(TestOnyxModule):
module = onyx_pfc_interface
def setUp(self):
super(TestOnyxPfcInterfaceModule, self).setUp()
self._pfc_enabled = True
self.mock_get_config = patch.object(
onyx_pfc_interface.OnyxPfcInterfaceModule,
"_get_pfc_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_pfc_interface.OnyxPfcInterfaceModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxPfcInterfaceModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._pfc_enabled:
suffix = 'enabled'
else:
suffix = 'disabled'
config_file = 'onyx_pfc_interface_%s.cfg' % suffix
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def _test_pfc_if(self, if_name, enabled, changed, commands):
state = 'enabled' if enabled else 'disabled'
set_module_args(dict(name=if_name, state=state))
self.execute_module(changed=changed, commands=commands)
def _test_pfc_no_change(self, enabled):
interfaces = ('Eth1/1', 'Eth1/1/2', 'Po1', 'Mpo2')
changed = False
commands = None
for ifc in interfaces:
self._test_pfc_if(ifc, enabled, changed, commands)
def test_pfc_enabled_no_change(self):
self._pfc_enabled = True
enabled = True
self._test_pfc_no_change(enabled)
def test_pfc_disabled_no_change(self):
self._pfc_enabled = False
enabled = False
self._test_pfc_no_change(enabled)
def _test_pfc_change(self, enabled):
cmd_list = [
('Eth1/1', 'interface ethernet 1/1'),
('Eth1/1/2', 'interface ethernet 1/1/2'),
('Po1', 'interface port-channel 1'),
('Mpo2', 'interface mlag-port-channel 2'),
]
changed = True
suffix = ' dcb priority-flow-control mode on force'
if not enabled:
suffix = ' no dcb priority-flow-control mode force'
for (if_name, cmd) in cmd_list:
commands = [cmd + suffix]
self._test_pfc_if(if_name, enabled, changed, commands)
def test_pfc_disabled_change(self):
self._pfc_enabled = False
enabled = True
self._test_pfc_change(enabled)
def test_pfc_enabled_change(self):
self._pfc_enabled = True
enabled = False
self._test_pfc_change(enabled)
def test_pfc_aggregate(self):
self._pfc_enabled = False
aggregate = [dict(name='Eth1/1'), dict(name='Eth1/1/2')]
set_module_args(dict(aggregate=aggregate, state='enabled'))
commands = [
'interface ethernet 1/1 dcb priority-flow-control mode on force',
'interface ethernet 1/1/2 dcb priority-flow-control mode on force']
self.execute_module(changed=True, commands=commands)
def test_pfc_aggregate_purge(self):
self._pfc_enabled = True
aggregate = [dict(name='Po1'), dict(name='Mpo2')]
set_module_args(dict(aggregate=aggregate, state='enabled', purge=True))
commands = [
'interface ethernet 1/1 no dcb priority-flow-control mode force',
'interface ethernet 1/1/2 no dcb priority-flow-control mode force']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,152 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_protocol
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxProtocolModule(TestOnyxModule):
module = onyx_protocol
def setUp(self):
super(TestOnyxProtocolModule, self).setUp()
self.mock_get_config = patch.object(
onyx_protocol.OnyxProtocolModule,
"_get_protocols")
self.get_config = self.mock_get_config.start()
self.mock_get_ip_config = patch.object(
onyx_protocol.OnyxProtocolModule,
"_get_ip_routing")
self.get_ip_config = self.mock_get_ip_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxProtocolModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_protocols_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_ip_config.return_value = "IP routing: enabled"
def test_mlag_enable(self):
set_module_args(dict(mlag='enabled'))
commands = ['protocol mlag']
self.execute_module(changed=True, commands=commands)
def test_mlag_disable(self):
set_module_args(dict(mlag='disabled'))
self.execute_module(changed=False)
def test_magp_enable(self):
set_module_args(dict(magp='enabled'))
commands = ['protocol magp']
self.execute_module(changed=True, commands=commands)
def test_magp_disable(self):
set_module_args(dict(magp='disabled'))
self.execute_module(changed=False)
def test_spanning_tree_enable(self):
set_module_args(dict(spanning_tree='enabled'))
self.execute_module(changed=False)
def test_spanning_tree_disable(self):
set_module_args(dict(spanning_tree='disabled'))
commands = ['no spanning-tree']
self.execute_module(changed=True, commands=commands)
def test_dcb_pfc_enable(self):
set_module_args(dict(dcb_pfc='enabled'))
commands = ['dcb priority-flow-control enable force']
self.execute_module(changed=True, commands=commands)
def test_dcb_pfc_disable(self):
set_module_args(dict(dcb_pfc='disabled'))
self.execute_module(changed=False)
def test_igmp_snooping_enable(self):
set_module_args(dict(igmp_snooping='enabled'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_snooping_disable(self):
set_module_args(dict(igmp_snooping='disabled'))
self.execute_module(changed=False)
def test_lacp_enable(self):
set_module_args(dict(lacp='enabled'))
commands = ['lacp']
self.execute_module(changed=True, commands=commands)
def test_lacp_disable(self):
set_module_args(dict(lacp='disabled'))
self.execute_module(changed=False)
def test_ip_routing_enable(self):
set_module_args(dict(ip_routing='enabled'))
self.execute_module(changed=False)
def test_ip_routing_disable(self):
set_module_args(dict(ip_routing='disabled'))
commands = ['no ip routing']
self.execute_module(changed=True, commands=commands)
def test_lldp_enable(self):
set_module_args(dict(lldp='enabled'))
commands = ['lldp']
self.execute_module(changed=True, commands=commands)
def test_lldp_disable(self):
set_module_args(dict(lldp='disabled'))
self.execute_module(changed=False)
def test_bgp_enable(self):
set_module_args(dict(bgp='enabled'))
commands = ['protocol bgp']
self.execute_module(changed=True, commands=commands)
def test_bgp_disable(self):
set_module_args(dict(bgp='disabled'))
self.execute_module(changed=False)
def test_ospf_enable(self):
set_module_args(dict(ospf='enabled'))
commands = ['protocol ospf']
self.execute_module(changed=True, commands=commands)
def test_ospf_disable(self):
set_module_args(dict(ospf='disabled'))
self.execute_module(changed=False)
def test_nve_enable(self):
set_module_args(dict(nve='enabled'))
commands = ['protocol nve']
self.execute_module(changed=True, commands=commands)
def test_nve_disabled(self):
set_module_args(dict(nve='disabled'))
self.execute_module(changed=False)
def test_bfd_enable(self):
set_module_args(dict(bfd='enabled'))
commands = ['protocol bfd']
self.execute_module(changed=True, commands=commands)
def test_bfd_disabled(self):
set_module_args(dict(bfd='disabled'))
self.execute_module(changed=False)

View file

@ -0,0 +1,138 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_ptp_global
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxPtpModule(TestOnyxModule):
module = onyx_ptp_global
def setUp(self):
self._ptp_enabled = True
self._ntp_enabled = True
super(TestOnyxPtpModule, self).setUp()
self.mock_get_ptp_config = patch.object(onyx_ptp_global.OnyxPtpGlobalModule, "_show_ptp_config")
self.get_ptp_config = self.mock_get_ptp_config.start()
self.mock_get_ntp_config = patch.object(onyx_ptp_global.OnyxPtpGlobalModule, "_show_ntp_config")
self.get_ntp_config = self.mock_get_ntp_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxPtpModule, self).tearDown()
self.mock_get_ptp_config.stop()
self.mock_get_ntp_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
if self._ptp_enabled:
config_file = 'onyx_show_ptp_clock.cfg'
self.get_ptp_config.return_value = load_fixture(config_file)
else:
self.get_ptp_config.return_value = None
config_file = 'onyx_show_ntp_configured.cfg'
ret_val = load_fixture(config_file)
if self._ntp_enabled:
ret_val[0]['NTP enabled'] = 'yes'
self.get_ntp_config.return_value = ret_val
self.load_config.return_value = None
def test_ptp_enabled_no_change(self):
set_module_args(dict(ptp_state='enabled'))
self.execute_module(changed=False)
def test_ptp_enabled_with_change(self):
self._ptp_enabled = False
set_module_args(dict(ptp_state='enabled'))
commands = ['protocol ptp']
self.execute_module(changed=True, commands=commands)
def test_ptp_disabled_no_change(self):
self._ptp_enabled = False
set_module_args(dict(ptp_state='disabled'))
self.execute_module(changed=False)
def test_ptp_disabled_with_change(self):
set_module_args(dict(ptp_state='disabled'))
commands = ['no protocol ptp']
self.execute_module(changed=True, commands=commands)
def test_ntp_enabled_no_change(self):
self._ptp_enabled = False
set_module_args(dict(ntp_state='enabled',
ptp_state='disabled'))
self.execute_module(changed=False)
def test_ntp_enabled_with_change(self):
self._ptp_enabled = False
self._ntp_enabled = False
set_module_args(dict(ntp_state='enabled',
ptp_state='disabled'))
commands = ['ntp enable']
self.execute_module(changed=True, commands=commands)
def test_ntp_disabled_no_change(self):
self._ntp_enabled = False
set_module_args(dict(ntp_state='disabled'))
self.execute_module(changed=False)
def test_ntp_disabled_with_change(self):
set_module_args(dict(ntp_state='disabled'))
commands = ['no ntp enable']
self.execute_module(changed=True, commands=commands)
def test_set_domain_no_change(self):
self._ntp_enabled = False
set_module_args(dict(ntp_state='disabled',
domain=127))
self.execute_module(changed=False)
def test_set_domain_with_change(self):
set_module_args(dict(domain=100))
commands = ['ptp domain 100']
self.execute_module(changed=True, commands=commands)
def test_set_primary_priority_no_change(self):
set_module_args(dict(primary_priority=128))
self.execute_module(changed=False)
def test_set_primary_priority_with_change(self):
set_module_args(dict(primary_priority=250))
commands = ['ptp priority1 250']
self.execute_module(changed=True, commands=commands)
def test_set_secondary_priority_no_change(self):
set_module_args(dict(secondary_priority=128))
self.execute_module(changed=False)
def test_set_secondary_priority_with_change(self):
set_module_args(dict(secondary_priority=190))
commands = ['ptp priority2 190']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,91 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_ptp_interface
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxPtpInterface(TestOnyxModule):
module = onyx_ptp_interface
enabled = False
interfaces = {'Eth1/1': ('ethernet', '1/1'), 'Vlan 1': ('vlan', '1')}
def setUp(self):
self.enabled = False
super(TestOnyxPtpInterface, self).setUp()
self.mock_get_config = patch.object(
onyx_ptp_interface.OnyxPtpInterfaceModule, "_show_ptp_interface_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxPtpInterface, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_ptp_interface.cfg'
data = None
if self.enabled:
data = load_fixture(config_file)
self.get_config.return_value = data
self.load_config.return_value = None
def test_ptp_disabled_no_change(self):
for interface in self.interfaces:
set_module_args(dict(state='disabled', name=interface))
self.execute_module(changed=False)
def test_ptp_disabled_with_change(self):
self.enabled = True
for interface in self.interfaces:
set_module_args(dict(state='disabled', name=interface))
interface_type, interface_id = self.interfaces.get(interface)
commands = ['no interface %s %s ptp enable' % (interface_type, interface_id)]
self.execute_module(changed=True, commands=commands)
def test_ptp_enabled_no_change(self):
self.enabled = True
for interface in self.interfaces:
set_module_args(dict(state='enabled', name=interface))
self.execute_module(changed=False)
def test_ptp_enabled_with_change(self):
for interface in self.interfaces:
set_module_args(dict(state='disabled', name=interface))
interface_type, interface_id = self.interfaces.get(interface)
set_module_args(dict(state='enabled', name=interface))
commands = ['interface %s %s ptp enable' % (interface_type, interface_id)]
self.execute_module(changed=True, commands=commands)
def test_ptp_attributs_no_change(self):
self.enabled = True
for interface in self.interfaces:
set_module_args(dict(state='enabled', name=interface, delay_request=0,
announce_interval=-2, announce_timeout=3,
sync_interval=-3))
self.execute_module(changed=False)
def test_ptp_attributs_with_change(self):
self.enabled = True
for interface in self.interfaces:
set_module_args(dict(state='enabled', name=interface, delay_request=2,
announce_interval=-1, announce_timeout=5, sync_interval=-1))
interface_type, interface_id = self.interfaces.get(interface)
commands = ['interface %s %s ptp delay-req interval 2' % (interface_type, interface_id),
'interface %s %s ptp announce interval -1' % (interface_type, interface_id),
'interface %s %s ptp announce timeout 5' % (interface_type, interface_id),
'interface %s %s ptp sync interval -1' % (interface_type, interface_id)]
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,52 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_qos
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxQosModule(TestOnyxModule):
module = onyx_qos
def setUp(self):
super(TestOnyxQosModule, self).setUp()
self.mock_get_if_qos_config = patch.object(
onyx_qos.OnyxQosModule, "_show_interface_qos")
self.get_if_qos_config = self.mock_get_if_qos_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxQosModule, self).tearDown()
self.mock_get_if_qos_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
qos_interface_ethernet_config_file = 'show_qos_interface_ethernet.cfg'
qos_interface_ethernet_data = load_fixture(qos_interface_ethernet_config_file)
self.get_if_qos_config.return_value = qos_interface_ethernet_data
self.load_config.return_value = None
def test_qos_interface_ethernet_no_change(self):
set_module_args(dict(interfaces=["Eth1/1"], trust="both", rewrite_pcp="enabled",
rewrite_dscp="disabled"))
self.execute_module(changed=False)
def test_qos_interface_ethernet_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], trust="L2", rewrite_pcp="disabled",
rewrite_dscp="enabled"))
commands = ["interface ethernet 1/1 no qos rewrite pcp",
"interface ethernet 1/1 qos trust L2",
"interface ethernet 1/1 qos rewrite dscp"
]
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,150 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_snmp
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxSNMPModule(TestOnyxModule):
module = onyx_snmp
enabled = False
def setUp(self):
self.enabled = False
super(TestOnyxSNMPModule, self).setUp()
self.mock_get_config = patch.object(
onyx_snmp.OnyxSNMPModule, "_show_snmp_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxSNMPModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_snmp_show.cfg'
data = load_fixture(config_file)
self.get_config.return_value = data
self.load_config.return_value = None
def test_snmp_state_no_change(self):
set_module_args(dict(state_enabled=True))
self.execute_module(changed=False)
def test_snmp_state_with_change(self):
set_module_args(dict(state_enabled=False))
commands = ['no snmp-server enable']
self.execute_module(changed=True, commands=commands)
def test_snmp_contact_no_change(self):
set_module_args(dict(contact_name='sara'))
self.execute_module(changed=False)
def test_snmp_contact_with_change(self):
set_module_args(dict(contact_name='Omar'))
commands = ['snmp-server contact Omar']
self.execute_module(changed=True, commands=commands)
def test_snmp_location_no_change(self):
set_module_args(dict(location='Jordan'))
self.execute_module(changed=False)
def test_snmp_location_with_change(self):
set_module_args(dict(location='London'))
commands = ['snmp-server location London']
self.execute_module(changed=True, commands=commands)
def test_snmp_communities_state_no_change(self):
set_module_args(dict(communities_enabled=True))
self.execute_module(changed=False)
def test_snmp_communities_state_with_change(self):
set_module_args(dict(communities_enabled=False))
commands = ['no snmp-server enable communities']
self.execute_module(changed=True, commands=commands)
def test_snmp_multi_communities_state_with_no_change(self):
set_module_args(dict(multi_communities_enabled=True))
self.execute_module(changed=False)
def test_snmp_multi_communities_state_with_change(self):
set_module_args(dict(multi_communities_enabled=False))
commands = ['no snmp-server enable mult-communities']
self.execute_module(changed=True, commands=commands)
def test_snmp_communities_no_change(self):
set_module_args(dict(snmp_communities=[dict(community_name='community_2',
community_type='read-write')]))
self.execute_module(changed=False)
def test_snmp_communities_with_change(self):
set_module_args(dict(snmp_communities=[dict(community_name='community_2',
community_type='read-only')]))
commands = ['snmp-server community community_2 ro']
self.execute_module(changed=True, commands=commands)
def test_snmp_communities_delete_with_change(self):
set_module_args(dict(snmp_communities=[dict(community_name='community_1',
state='absent')]))
commands = ['no snmp-server community community_1']
self.execute_module(changed=True, commands=commands)
def test_snmp_notify_state_no_change(self):
set_module_args(dict(notify_enabled=True))
self.execute_module(changed=False)
def test_snmp_notify_state_with_change(self):
set_module_args(dict(notify_enabled=False))
commands = ['no snmp-server enable notify']
self.execute_module(changed=True, commands=commands)
def test_snmp_notify_port_no_change(self):
set_module_args(dict(notify_port='1'))
self.execute_module(changed=False)
def test_snmp_notify_port_with_change(self):
set_module_args(dict(notify_port='2'))
commands = ['snmp-server notify port 2']
self.execute_module(changed=True, commands=commands)
def test_snmp_notify_community_no_change(self):
set_module_args(dict(notify_community='community_1'))
self.execute_module(changed=False)
def test_snmp_notify_community_with_change(self):
set_module_args(dict(notify_community='community_2'))
commands = ['snmp-server notify community community_2']
self.execute_module(changed=True, commands=commands)
def test_snmp_notify_send_test_with_change(self):
set_module_args(dict(notify_send_test='yes'))
commands = ['snmp-server notify send-test']
self.execute_module(changed=True, commands=commands)
def test_snmp_notify_event_with_change(self):
set_module_args(dict(notify_event='interface-up'))
commands = ['snmp-server notify event interface-up']
self.execute_module(changed=True, commands=commands)
def test_snmp_permissions_with_change(self):
set_module_args(dict(snmp_permissions=[dict(state_enabled=True,
permission_type='RFC1213-MIB')]))
commands = ['snmp-server enable set-permission RFC1213-MIB']
self.execute_module(changed=True, commands=commands)
def test_snmp_engine_id_reset_with_change(self):
set_module_args(dict(engine_id_reset='yes'))
commands = ['snmp-server engineID reset']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,170 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_snmp_hosts
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxSNMPHostsModule(TestOnyxModule):
module = onyx_snmp_hosts
def setUp(self):
self.enabled = False
super(TestOnyxSNMPHostsModule, self).setUp()
self.mock_get_config = patch.object(
onyx_snmp_hosts.OnyxSNMPHostsModule, "_show_hosts_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxSNMPHostsModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_snmp_hosts.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_snmp_host_enabled_state_no_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
enabled=True)]))
self.execute_module(changed=False)
def test_snmp_host_enabled_state_with_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
enabled=False)]))
commands = ['snmp-server host 1.1.1.1 disable']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_notification_type_no_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='2c',
port='5')]))
self.execute_module(changed=False)
def test_snmp_host_notification_type_with_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='inform',
version='2c',
port='5')]))
commands = ['snmp-server host 2.2.2.2 informs port 5 version 2c']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_version_no_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='2c',
port='5')]))
self.execute_module(changed=False)
def test_snmp_host_version_with_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='1',
port='5')]))
commands = ['snmp-server host 2.2.2.2 traps port 5 version 1']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_port_no_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='2c',
port='5')]))
self.execute_module(changed=False)
def test_snmp_host_port_with_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='2c',
port='3')]))
commands = ['snmp-server host 2.2.2.2 traps port 3 version 2c']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_user_name_no_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='sara',
auth_type='md5',
auth_password='sara123saea1234678')]))
self.execute_module(changed=False)
def test_snmp_host_user_name_with_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='masa',
auth_type='md5',
auth_password='sara123saea1234678')]))
commands = ['snmp-server host 1.1.1.1 informs port 3 version 3 user masa auth md5 sara123saea1234678']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_auth_type_no_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='sara',
auth_type='md5',
auth_password='sara123saea1234678')]))
self.execute_module(changed=False)
def test_snmp_host_auth_type_with_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='sara',
auth_type='sha',
auth_password='sara123saea1234678')]))
commands = ['snmp-server host 1.1.1.1 informs port 3 version 3 user sara auth sha sara123saea1234678']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_privacy_type_no_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='sara',
auth_type='md5',
auth_password='sara123saea1234678',
privacy_type='3des',
privacy_password='pjqriuewjhksjmdoiws')]))
self.execute_module(changed=False)
def test_snmp_host_privacy_type_with_change(self):
set_module_args(dict(hosts=[dict(name='1.1.1.1',
notification_type='inform',
version='3',
port='3',
user_name='sara',
auth_type='md5',
auth_password='sara123saea1234678',
privacy_type='aes-192',
privacy_password='pjqriuewjhksjmdoiws')]))
commands = ['snmp-server host 1.1.1.1 informs port 3 version 3 user sara auth md5 sara123saea1234678 priv aes-192 pjqriuewjhksjmdoiws']
self.execute_module(changed=True, commands=commands)
def test_snmp_host_state_with_change(self):
set_module_args(dict(hosts=[dict(name='2.2.2.2',
notification_type='trap',
version='2c',
port='5',
state='absent')]))
commands = ['no snmp-server host 2.2.2.2']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,95 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_snmp_users
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxSNMPUsersModule(TestOnyxModule):
module = onyx_snmp_users
def setUp(self):
self.enabled = False
super(TestOnyxSNMPUsersModule, self).setUp()
self.mock_get_config = patch.object(
onyx_snmp_users.OnyxSNMPUsersModule, "_show_users")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxSNMPUsersModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_show_snmp_users.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_snmp_user_state_no_change(self):
set_module_args(dict(users=[dict(name='sara',
enabled='true')]))
self.execute_module(changed=False)
def test_snmp_user_state_with_change(self):
set_module_args(dict(users=[dict(name='sara',
enabled='false')]))
commands = ['no snmp-server user sara v3 enable']
self.execute_module(changed=True, commands=commands)
def test_snmp_user_set_access_state_no_change(self):
set_module_args(dict(users=[dict(name='sara',
set_access_enabled='true')]))
self.execute_module(changed=False)
def test_snmp_user_set_access_state_with_change(self):
set_module_args(dict(users=[dict(name='sara',
set_access_enabled='false')]))
commands = ['no snmp-server user sara v3 enable sets']
self.execute_module(changed=True, commands=commands)
def test_snmp_user_require_privacy_state_no_change(self):
set_module_args(dict(users=[dict(name='sara',
require_privacy='false')]))
self.execute_module(changed=False)
def test_snmp_user_require_privacy_state_with_change(self):
set_module_args(dict(users=[dict(name='sara',
require_privacy='yes')]))
commands = ['snmp-server user sara v3 require-privacy']
self.execute_module(changed=True, commands=commands)
def test_snmp_user_auth_type_no_change(self):
set_module_args(dict(users=[dict(name='sara',
auth_type='sha',
auth_password='12sara123456')]))
self.execute_module(changed=False)
def test_snmp_user_auth_type_with_change(self):
set_module_args(dict(users=[dict(name='sara',
auth_type='md5',
auth_password='12sara123456')]))
commands = ['snmp-server user sara v3 auth md5 12sara123456']
self.execute_module(changed=True, commands=commands)
def test_snmp_user_capability_level_no_change(self):
set_module_args(dict(users=[dict(name='sara',
capability_level='admin')]))
self.execute_module(changed=False)
def test_snmp_user_capability_level_with_change(self):
set_module_args(dict(users=[dict(name='sara',
capability_level='monitor')]))
commands = ['snmp-server user sara v3 capability monitor']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,113 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_syslog_files
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxSyslogFilesModule(TestOnyxModule):
module = onyx_syslog_files
def setUp(self):
self.enabled = False
super(TestOnyxSyslogFilesModule, self).setUp()
self.mock_get_config = patch.object(
onyx_syslog_files.OnyxSyslogFilesModule, "show_logging")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxSyslogFilesModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_logging_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_syslog_files_force_rotate(self):
set_module_args(dict(rotation=dict(force=True)))
commands = ["logging files rotation force"]
self.execute_module(changed=True, commands=commands)
def test_syslog_files_max_num(self):
set_module_args(dict(rotation=dict(max_num=30)))
commands = ["logging files rotation max-num 30"]
self.execute_module(changed=True, commands=commands)
def test_syslog_files_freq(self):
set_module_args(dict(rotation=dict(frequency="daily")))
commands = ["logging files rotation criteria frequency daily"]
self.execute_module(changed=True, commands=commands)
def test_syslog_files_size(self):
set_module_args(dict(rotation=dict(size=10.5)))
commands = ["logging files rotation criteria size 10.5"]
self.execute_module(changed=True, commands=commands)
def test_syslog_files_delete(self):
set_module_args(dict(delete_group="oldest"))
commands = ["logging files delete oldest"]
self.execute_module(changed=True, commands=commands)
def test_syslog_debug_files_force_rotate(self):
set_module_args(dict(rotation=dict(force=True), debug=True))
commands = ["logging debug-files rotation force"]
self.execute_module(changed=True, commands=commands)
def test_syslog_debug_files_max_num(self):
set_module_args(dict(rotation=dict(max_num=30), debug=True))
commands = ["logging debug-files rotation max-num 30"]
self.execute_module(changed=True, commands=commands)
def test_syslog_debug_files_freq(self):
set_module_args(dict(rotation=dict(frequency="weekly"), debug=True))
commands = ["logging debug-files rotation criteria frequency weekly"]
self.execute_module(changed=True, commands=commands)
def test_syslog_debug_files_size(self):
set_module_args(dict(rotation=dict(size=10.5), debug=True))
commands = ["logging debug-files rotation criteria size 10.5"]
self.execute_module(changed=True, commands=commands)
def test_syslog_debug_files_delete(self):
set_module_args(dict(delete_group="oldest", debug=True))
commands = ["logging debug-files delete oldest"]
self.execute_module(changed=True, commands=commands)
''' nochange '''
def test_syslog_files_max_num_no_change(self):
set_module_args(dict(rotation=dict(max_num=10)))
self.execute_module(changed=False)
def test_syslog_files_freq_no_change(self):
set_module_args(dict(rotation=dict(frequency="weekly")))
self.execute_module(changed=False)
def test_syslog_files_size_no_change(self):
set_module_args(dict(rotation=dict(size_pct=10)))
self.execute_module(changed=False)
def test_syslog_debug_files_max_num_no_change(self):
set_module_args(dict(rotation=dict(max_num=20), debug=True))
self.execute_module(changed=False)
def test_syslog_debug_files_freq_no_change(self):
set_module_args(dict(rotation=dict(frequency="daily"), debug=True))
self.execute_module(changed=False)
def test_syslog_debug_files_size_no_change(self):
set_module_args(dict(rotation=dict(size=20), debug=True))
self.execute_module(changed=False)

View file

@ -0,0 +1,91 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_syslog_remote
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxSysLogRemoteModule(TestOnyxModule):
module = onyx_syslog_remote
def setUp(self):
self.enabled = False
super(TestOnyxSysLogRemoteModule, self).setUp()
self.mock_get_config = patch.object(
onyx_syslog_remote.OnyxSyslogRemoteModule, "show_logging")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxSysLogRemoteModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_logging_config_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_syslog_new_host(self):
set_module_args(dict(host="10.10.20.20"))
commands = ["logging 10.10.20.20"]
self.execute_module(changed=True, commands=commands)
def test_syslog_new_host_port(self):
set_module_args(dict(host="10.10.20.20", port=8080))
commands = ['logging 10.10.20.20', 'logging 10.10.20.20 port 8080']
self.execute_module(changed=True, commands=commands)
def test_syslog_override(self):
set_module_args(dict(host="10.10.10.12", trap_override=[dict(override_class="sx-sdk", override_priority='emerg'),
dict(override_class="mgmt-back", override_priority='emerg')]))
commands = ["logging 10.10.10.12 trap override class mgmt-back priority emerg"] # no sx-sdk its already configured
self.execute_module(changed=True, commands=commands)
def test_syslog_trap(self):
set_module_args(dict(host="10.10.10.10", trap="notice"))
commands = ["logging 10.10.10.10 trap notice"]
self.execute_module(changed=True, commands=commands)
def test_syslog_include_filter(self):
set_module_args(dict(host="10.10.10.10", filter="include", filter_str=".*ERR.*"))
commands = ['logging 10.10.10.10 filter include .*ERR.*']
self.execute_module(changed=True, commands=commands)
def test_syslog_no_override(self):
set_module_args(dict(host="10.10.10.12", trap_override=[dict(override_class="sx-sdk", override_enabled=False),
dict(override_class="mgmt-front", override_enabled=False)]))
commands = ['no logging 10.10.10.12 trap override class sx-sdk'] # no mgmt-front because doesn't configured
self.execute_module(changed=True, commands=commands)
def test_syslog_no_port(self):
set_module_args(dict(host="10.10.10.12", enabled=False))
commands = ['no logging 10.10.10.12']
self.execute_module(changed=True, commands=commands)
def test_syslog_filter_no_change(self):
set_module_args(dict(host="10.10.10.10", filter="exclude", filter_str=".*ERR.*"))
self.execute_module(changed=False)
def test_syslog_trap_no_change(self):
set_module_args(dict(host="10.10.10.10", trap="info"))
self.execute_module(changed=False)
def test_syslog_add_port_no_change(self):
set_module_args(dict(host="10.10.10.12", port=80))
self.execute_module(changed=False)
def test_syslog_override_no_change(self):
set_module_args(dict(host="10.10.10.12", trap_override=[dict(override_priority="emerg", override_class="sx-sdk")]))
self.execute_module(changed=False)

View file

@ -0,0 +1,108 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_traffic_class
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxTrafficClassModule(TestOnyxModule):
module = onyx_traffic_class
arp_suppression = True
def setUp(self):
super(TestOnyxTrafficClassModule, self).setUp()
self.mock_get_congestion_control_config = patch.object(
onyx_traffic_class.OnyxTrafficClassModule, "_show_interface_congestion_control")
self.get_congestion_control_config = self.mock_get_congestion_control_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_dcb_config = patch.object(
onyx_traffic_class.OnyxTrafficClassModule, "_show_interface_dcb_ets")
self.get_dcb_config = self.mock_get_dcb_config.start()
def tearDown(self):
super(TestOnyxTrafficClassModule, self).tearDown()
self.mock_get_congestion_control_config.stop()
self.mock_load_config.stop()
self.mock_get_dcb_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
interfaces_congestion_control_config_file = 'onyx_show_interface_congestion_control.cfg'
interfaces_dcb_config_file = 'onyx_show_dcb_ets_interface.cfg'
interfaces_congestion_control_data = load_fixture(interfaces_congestion_control_config_file)
interfaces_dcb_config_data = load_fixture(interfaces_dcb_config_file)
self.get_congestion_control_config.return_value = interfaces_congestion_control_data
self.get_dcb_config.return_value = interfaces_dcb_config_data
self.load_config.return_value = None
def test_configure_congestion_control_disabled_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=1,
congestion_control=dict(control="ecn", threshold_mode="absolute",
min_threshold=500, max_threshold=1500)))
commands = [
"interface ethernet 1/1 traffic-class 1 congestion-control ecn minimum-absolute 500 maximum-absolute 1500"
]
self.execute_module(changed=True, commands=commands)
def test_configure_congestion_control_disabled_with_no_change(self):
set_module_args(dict(state="disabled", interfaces=["Eth1/1"], tc=0))
self.execute_module(changed=False)
def test_configure_congestion_control_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=2,
congestion_control=dict(control="ecn", threshold_mode="relative",
min_threshold=9, max_threshold=88)))
commands = [
"interface ethernet 1/1 traffic-class 2 congestion-control ecn minimum-relative 9 maximum-relative 88"
]
self.execute_module(changed=True, commands=commands)
def test_configure_congestion_control_absolute_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=3,
congestion_control=dict(control="ecn", threshold_mode="absolute",
min_threshold=500, max_threshold=1500)))
commands = [
"interface ethernet 1/1 traffic-class 3 congestion-control ecn minimum-absolute 500 maximum-absolute 1500"
]
self.execute_module(changed=True, commands=commands)
def test_configure_congestion_control_with_no_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=3,
congestion_control=dict(control="ecn", threshold_mode="absolute",
min_threshold=500, max_threshold=1550)))
self.execute_module(changed=False)
def test_configure_dcb_mode_with_no_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=3, dcb=dict(mode="strict")))
self.execute_module(changed=False)
def test_configure_dcb_strict_mode_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=1, dcb=dict(mode="strict")))
commands = [
"interface ethernet 1/1 traffic-class 1 dcb ets strict"
]
self.execute_module(changed=True, commands=commands)
def test_configure_dcb_wrr_mode_with_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=0, dcb=dict(mode="wrr", weight=10)))
commands = [
"interface ethernet 1/1 traffic-class 0 dcb ets wrr 10"
]
self.execute_module(changed=True, commands=commands)
def test_configure_dcb_wrr_mode_with_no_change(self):
set_module_args(dict(interfaces=["Eth1/1"], tc=0, dcb=dict(mode="wrr", weight=12)))
self.execute_module(changed=False)

View file

@ -0,0 +1,99 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_username
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxUsernameModule(TestOnyxModule):
module = onyx_username
def setUp(self):
self.enabled = False
super(TestOnyxUsernameModule, self).setUp()
self.mock_get_config = patch.object(
onyx_username.OnyxUsernameModule, "_get_username_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxUsernameModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_username_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_new_username(self):
set_module_args(dict(username='test'))
commands = ['username test']
self.execute_module(changed=True, commands=commands)
def test_change_full_username(self):
set_module_args(dict(username='anass', full_name="anasshami"))
commands = ['username anass full-name anasshami']
self.execute_module(changed=True, commands=commands)
def test_change_username_password(self):
set_module_args(dict(username='anass', password="12345"))
commands = ['username anass password 12345']
self.execute_module(changed=True, commands=commands)
def test_change_username_password_encrypted(self):
set_module_args(dict(username='anass', password="12345", encrypted_password=True))
commands = ['username anass password 7 12345']
self.execute_module(changed=True, commands=commands)
def test_disable_username(self):
set_module_args(dict(username='anass', disabled="all"))
commands = ['username anass disable']
self.execute_module(changed=True, commands=commands)
def test_disable_username_login(self):
set_module_args(dict(username='anass', disabled="login"))
commands = ['username anass disable login']
self.execute_module(changed=True, commands=commands)
def test_disable_username_password(self):
set_module_args(dict(username='anass', disabled="password"))
commands = ['username anass disable password']
self.execute_module(changed=True, commands=commands)
def test_change_username_capability(self):
set_module_args(dict(username='anass', capability="monitor"))
commands = ['username anass capability monitor']
self.execute_module(changed=True, commands=commands)
def test_disconnect_username(self):
set_module_args(dict(username='anass', disconnected=True))
commands = ['username anass disconnect']
self.execute_module(changed=True, commands=commands)
def test_no_change_username_capability(self):
set_module_args(dict(username='anass', capability="admin"))
self.execute_module(changed=False)
def test_no_change_username_disabled(self):
set_module_args(dict(username='anassh', disabled="all"))
self.execute_module(changed=False)
def test_no_change_username_nopass(self):
set_module_args(dict(username='admin', nopassword=True))
self.execute_module(changed=False)
def test_no_change_full_username(self):
set_module_args(dict(username='admin', full_name="System Administrator"))
self.execute_module(changed=False)

View file

@ -0,0 +1,106 @@
#
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_vlan
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxVlanModule(TestOnyxModule):
module = onyx_vlan
def setUp(self):
super(TestOnyxVlanModule, self).setUp()
self.mock_get_config = patch.object(
onyx_vlan.OnyxVlanModule, "_get_vlan_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(
onyx_vlan.OnyxVlanModule, "_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxVlanModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_vlan_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def test_vlan_no_change(self):
set_module_args(dict(vlan_id=20))
self.execute_module(changed=False)
def test_vlan_remove_name(self):
set_module_args(dict(vlan_id=10, name=''))
commands = ['vlan 10 no name']
self.execute_module(changed=True, commands=commands)
def test_vlan_change_name(self):
set_module_args(dict(vlan_id=10, name='test-test'))
commands = ['vlan 10 name test-test']
self.execute_module(changed=True, commands=commands)
def test_vlan_create(self):
set_module_args(dict(vlan_id=30))
commands = ['vlan 30', 'exit']
self.execute_module(changed=True, commands=commands)
def test_vlan_create_with_name(self):
set_module_args(dict(vlan_id=30, name='test-test'))
commands = ['vlan 30', 'exit', 'vlan 30 name test-test']
self.execute_module(changed=True, commands=commands)
def test_vlan_remove(self):
set_module_args(dict(vlan_id=20, state='absent'))
commands = ['no vlan 20']
self.execute_module(changed=True, commands=commands)
def test_vlan_remove_not_exist(self):
set_module_args(dict(vlan_id=30, state='absent'))
self.execute_module(changed=False)
def test_vlan_aggregate(self):
aggregate = list()
aggregate.append(dict(vlan_id=30))
aggregate.append(dict(vlan_id=20))
set_module_args(dict(aggregate=aggregate))
commands = ['vlan 30', 'exit']
self.execute_module(changed=True, commands=commands)
def test_vlan_aggregate_purge(self):
aggregate = list()
aggregate.append(dict(vlan_id=30))
aggregate.append(dict(vlan_id=20))
set_module_args(dict(aggregate=aggregate, purge=True))
commands = ['vlan 30', 'exit', 'no vlan 10', 'no vlan 1']
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,101 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_vxlan
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxVxlanModule(TestOnyxModule):
module = onyx_vxlan
arp_suppression = True
def setUp(self):
super(TestOnyxVxlanModule, self).setUp()
self.mock_get_vxlan_config = patch.object(
onyx_vxlan.OnyxVxlanModule, "_show_vxlan_config")
self.get_vxlan_config = self.mock_get_vxlan_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_nve_detail = patch.object(
onyx_vxlan.OnyxVxlanModule, "_show_nve_detail")
self.get_nve_detail = self.mock_get_nve_detail.start()
def tearDown(self):
super(TestOnyxVxlanModule, self).tearDown()
self.mock_get_vxlan_config.stop()
self.mock_load_config.stop()
self.mock_get_nve_detail.stop()
def load_fixtures(self, commands=None, transport='cli'):
interfaces_nve_config_file = 'onyx_show_interfaces_nve.cfg'
interfaces_nve_detail_config_file = 'onyx_show_interfaces_nve_detail.cfg'
self.get_nve_detail.return_value = None
interfaces_nve_detail_data = load_fixture(interfaces_nve_detail_config_file)
interfaces_nv_data = load_fixture(interfaces_nve_config_file)
self.get_nve_detail.return_value = interfaces_nve_detail_data
if self.arp_suppression is False:
interfaces_nve_detail_data[0]["10"][0]["Neigh Suppression"] = "Disable"
interfaces_nve_detail_data[0]["6"][0]["Neigh Suppression"] = "Disable"
self.get_nve_detail.return_value = interfaces_nve_detail_data
self.get_vxlan_config.return_value = interfaces_nv_data
self.load_config.return_value = None
def test_configure_vxlan_no_change(self):
set_module_args(dict(nve_id=1, loopback_id=1, bgp=True, mlag_tunnel_ip='192.10.10.1',
vni_vlan_list=[dict(vlan_id=10, vni_id=10010), dict(vlan_id=6, vni_id=10060)],
arp_suppression=True))
self.execute_module(changed=False)
def test_configure_vxlan_with_change(self):
set_module_args(dict(nve_id=2, loopback_id=1, bgp=True, mlag_tunnel_ip='192.10.10.1',
vni_vlan_list=[dict(vlan_id=10, vni_id=10010), dict(vlan_id=6, vni_id=10060)],
arp_suppression=True))
commands = [
"no interface nve 1", "interface nve 2", "exit",
"interface nve 2 vxlan source interface loopback 1 ",
"interface nve 2 nve controller bgp", "interface nve 2 vxlan mlag-tunnel-ip 192.10.10.1",
"interface nve 2 nve neigh-suppression", "interface nve 2 nve vni 10010 vlan 10",
"interface vlan 10", "exit", "interface nve 2 nve vni 10060 vlan 6", "interface vlan 6", "exit"
]
self.execute_module(changed=True, commands=commands)
def test_loopback_id_with_change(self):
set_module_args(dict(nve_id=1, loopback_id=2, bgp=True, mlag_tunnel_ip='192.10.10.1',
vni_vlan_list=[dict(vlan_id=10, vni_id=10010), dict(vlan_id=6, vni_id=10060)],
arp_suppression=True))
commands = ["interface nve 1 vxlan source interface loopback 2 "]
self.execute_module(changed=True, commands=commands)
def test_mlag_tunnel_ip_with_change(self):
set_module_args(dict(nve_id=1, loopback_id=1, bgp=True, mlag_tunnel_ip='192.10.10.10',
vni_vlan_list=[dict(vlan_id=10, vni_id=10010), dict(vlan_id=6, vni_id=10060)],
arp_suppression=True))
commands = ["interface nve 1 vxlan mlag-tunnel-ip 192.10.10.10"]
self.execute_module(changed=True, commands=commands)
def test_vni_vlan_list_with_change(self):
set_module_args(dict(nve_id=1, loopback_id=1, bgp=True, mlag_tunnel_ip='192.10.10.1',
vni_vlan_list=[dict(vlan_id=11, vni_id=10011), dict(vlan_id=7, vni_id=10061)],
arp_suppression=False))
commands = ["interface nve 1 nve vni 10011 vlan 11", "interface nve 1 nve vni 10061 vlan 7"]
self.execute_module(changed=True, commands=commands)
def test_arp_suppression_with_change(self):
self.arp_suppression = False
set_module_args(dict(nve_id=1, loopback_id=1, bgp=True, mlag_tunnel_ip='192.10.10.1',
vni_vlan_list=[dict(vlan_id=10, vni_id=10010), dict(vlan_id=6, vni_id=10060)],
arp_suppression=True))
commands = ["interface vlan 10", "exit", "interface vlan 6", "exit"]
self.execute_module(changed=True, commands=commands)

View file

@ -0,0 +1,66 @@
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.onyx import onyx_wjh
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .onyx_module import TestOnyxModule, load_fixture
class TestOnyxWJHModule(TestOnyxModule):
module = onyx_wjh
def setUp(self):
self.enabled = False
super(TestOnyxWJHModule, self).setUp()
self.mock_get_config = patch.object(
onyx_wjh.OnyxWJHModule, "_get_wjh_config")
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch(
'ansible_collections.community.general.plugins.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
super(TestOnyxWJHModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_wjh_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
def test_wjh_no_change(self):
set_module_args(dict(group='forwarding', enabled=False))
self.execute_module(changed=False)
def test_wjh_enable(self):
set_module_args(dict(group='forwarding', enabled=True))
commands = ['what-just-happened forwarding enable']
self.execute_module(changed=True, commands=commands)
def test_wjh_export_no_change(self):
set_module_args(dict(export_group='forwarding', auto_export=False))
self.execute_module(changed=False)
def test_wjh_export_enable(self):
set_module_args(dict(export_group='forwarding', auto_export=True))
commands = ['what-just-happened auto-export forwarding enable']
self.execute_module(changed=True, commands=commands)
def test_wjh_export_disable(self):
set_module_args(dict(export_group='all', auto_export=False))
commands = ['no what-just-happened auto-export all enable']
self.execute_module(changed=True, commands=commands)
def test_wjh_clear(self):
set_module_args(dict(clear_group='all'))
commands = ['clear what-just-happened pcap-files all']
self.execute_module(changed=True, commands=commands)