diff options
Diffstat (limited to 'ansible_collections/cisco/ios/tests')
124 files changed, 5158 insertions, 1329 deletions
diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg index 166af7ee7..b76fdcae3 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/tests/cli/_parsed.cfg @@ -1,10 +1,53 @@ -Extended IP access list 110 - 10 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 -Extended IP access list 123 - 10 deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos 12 - 20 deny tcp 192.0.3.0 0.0.0.255 192.0.4.0 0.0.0.255 eq www ack dscp ef ttl lt 20 -Extended IP access list test_acl - 10 deny tcp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 eq www fin option traceroute ttl eq 10 -IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 -access-list 110 remark test a remark. +ip access-list extended NET-MGMT-VTY + 10 permit tcp 10.57.66.243 0.0.0.7 any eq 22 + 20 permit tcp host 10.160.114.111 any eq 22 + 30 permit tcp host 10.160.115.22 any eq 22 + 40 deny ip any any log +ip access-list extended TEST + 10 remark FIRST REMARK BEFORE LINE 10 + 10 remark ============ + 10 remark ALLOW HOST FROM BUILDING 10 + 10 permit ip host 1.1.1.1 any + 20 remark FIRST REMARK BEFORE LINE 20 + 20 remark ============ + 20 remark ALLOW HOST FROM BUILDING 20 + 20 permit ip host 2.2.2.2 any + 30 remark FIRST REMARK BEFORE LINE 30 + 30 remark ============ + 30 remark ALLOW NEW HOST FROM BUILDING 10 + 30 permit ip host 3.3.3.3 any + remark FIRST REMARK AT END OF ACL + remark SECOND REMARK AT END OF ACL +ip access-list extended empty_ip_ex_acl + remark empty remark 1 + remark empty remark 2 + remark empty remark never ends +ip access-list extended mytest + 100 remark I am a test ace + 100 remark I am right after the test ace + 100 remark I third the test ace + 100 permit ip host 100.100.100.100 any + 110 remark I am the next test ace + 110 remark I am the next ace to the next ace + 110 permit ip host 10.40.150.0 any + remark I am the peace ace + remark Peace out +ip access-list standard 42 + 10 permit 10.182.250.0 0.0.0.255 +ip access-list extended 199 + 10 permit ip 10.40.150.0 0.0.0.255 any + 20 permit ip any 10.40.150.0 0.0.0.255 +ipv6 access-list R1_TRAFFIC + sequence 10 permit ipv6 2001:ABAD:BEEF:1221::/64 any + sequence 20 deny tcp host 2001:ABAD:BEEF:2345::1 host 2001:ABAD:BEEF:1212::1 eq www +ipv6 access-list empty_ipv6_acl + sequence 10 remark empty remark 1 + sequence 20 remark empty remark 2 + sequence 30 remark empty remark never ends +ipv6 access-list ipv6_acl + sequence 10 remark I am a ipv6 ace + sequence 20 remark I am test + sequence 30 permit tcp any any + sequence 40 permit udp any any + sequence 50 remark I am new set of ipv6 ace + sequence 60 permit icmp any any diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml index 799b166a3..2d324ebe1 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_acls/vars/main.yaml @@ -154,100 +154,207 @@ parsed: - acls: - aces: - destination: - address: 192.0.3.0 - wildcard_bits: 0.0.0.255 - dscp: ef - grant: deny - protocol: icmp - protocol_options: - icmp: - echo: true + any: true + grant: permit + protocol: ip sequence: 10 source: - address: 192.0.2.0 + address: 10.40.150.0 wildcard_bits: 0.0.0.255 - ttl: - eq: 10 - - remarks: - - "test a remark." + - destination: + address: 10.40.150.0 + wildcard_bits: 0.0.0.255 + grant: permit + protocol: ip + sequence: 20 + source: + any: true acl_type: extended - name: "110" + name: "199" + - aces: + - grant: permit + sequence: 10 + source: + address: 10.182.250.0 + wildcard_bits: 0.0.0.255 + acl_type: standard + name: "42" - aces: - destination: - address: 198.51.101.0 + any: true port_protocol: - eq: telnet - wildcard_bits: 0.0.0.255 - grant: deny + eq: "22" + grant: permit protocol: tcp - protocol_options: - tcp: - ack: true sequence: 10 source: - address: 198.51.100.0 - wildcard_bits: 0.0.0.255 - tos: - service_value: 12 + address: 10.57.66.243 + wildcard_bits: 0.0.0.7 - destination: - address: 192.0.4.0 + any: true port_protocol: - eq: www - wildcard_bits: 0.0.0.255 - dscp: ef - grant: deny + eq: "22" + grant: permit protocol: tcp - protocol_options: - tcp: - ack: true sequence: 20 source: - address: 192.0.3.0 - wildcard_bits: 0.0.0.255 - ttl: - lt: 20 - acl_type: extended - name: "123" - - aces: + host: 10.160.114.111 - destination: - address: 192.0.3.0 + any: true port_protocol: - eq: www - wildcard_bits: 0.0.0.255 - grant: deny - option: - traceroute: true + eq: "22" + grant: permit protocol: tcp - protocol_options: - tcp: - fin: true + sequence: 30 + source: + host: 10.160.115.22 + - destination: + any: true + grant: deny + log: + set: true + protocol: ip + sequence: 40 + source: + any: true + acl_type: extended + name: NET-MGMT-VTY + - aces: + - destination: + any: true + grant: permit + protocol: ip + remarks: + - FIRST REMARK BEFORE LINE 10 + - "============" + - ALLOW HOST FROM BUILDING 10 sequence: 10 source: - address: 192.0.2.0 - wildcard_bits: 0.0.0.255 - ttl: - eq: 10 + host: 1.1.1.1 + - destination: + any: true + grant: permit + protocol: ip + remarks: + - FIRST REMARK BEFORE LINE 20 + - "============" + - ALLOW HOST FROM BUILDING 20 + sequence: 20 + source: + host: 2.2.2.2 + - destination: + any: true + grant: permit + protocol: ip + remarks: + - FIRST REMARK BEFORE LINE 30 + - "============" + - ALLOW NEW HOST FROM BUILDING 10 + sequence: 30 + source: + host: 3.3.3.3 + - remarks: + - FIRST REMARK AT END OF ACL + - SECOND REMARK AT END OF ACL acl_type: extended - name: test_acl + name: TEST + - aces: + - remarks: + - empty remark 1 + - empty remark 2 + - empty remark never ends + acl_type: extended + name: empty_ip_ex_acl + - aces: + - destination: + any: true + grant: permit + protocol: ip + remarks: + - I am a test ace + - I am right after the test ace + - I third the test ace + sequence: 100 + source: + host: 100.100.100.100 + - destination: + any: true + grant: permit + protocol: ip + remarks: + - I am the next test ace + - I am the next ace to the next ace + sequence: 110 + source: + host: 10.40.150.0 + - remarks: + - I am the peace ace + - Peace out + acl_type: extended + name: mytest afi: ipv4 - acls: - aces: - destination: any: true + grant: permit + protocol: ipv6 + sequence: 10 + source: + address: 2001:ABAD:BEEF:1221::/64 + - destination: + host: 2001:ABAD:BEEF:1212::1 port_protocol: - eq: telnet - dscp: af11 + eq: www grant: deny protocol: tcp - protocol_options: - tcp: - ack: true + sequence: 20 + source: + host: 2001:ABAD:BEEF:2345::1 + name: R1_TRAFFIC + - aces: + - remarks: + - empty remark 1 sequence: 10 + - remarks: + - empty remark 2 + sequence: 20 + - remarks: + - empty remark never ends + sequence: 30 + name: empty_ipv6_acl + - aces: + - remarks: + - I am a ipv6 ace + sequence: 10 + - remarks: + - I am test + sequence: 20 + - destination: + any: true + grant: permit + protocol: tcp + sequence: 30 source: any: true - port_protocol: - eq: www - name: R1_TRAFFIC + - destination: + any: true + grant: permit + protocol: udp + sequence: 40 + source: + any: true + - remarks: + - I am new set of ipv6 ace + sequence: 50 + - destination: + any: true + grant: permit + protocol: icmp + sequence: 60 + source: + any: true + name: ipv6_acl afi: ipv6 rendered: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/_populate_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/_populate_config.yaml index 4ac501796..843fc15bc 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/_populate_config.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/_populate_config.yaml @@ -1,6 +1,13 @@ --- - ansible.builtin.include_tasks: _initial_vrf_setup.yaml - ansible.builtin.include_tasks: _ospf_proc_setup.yaml + +- name: Enable routing + cisco.ios.ios_config: + lines: + - ip routing + - ipv6 unicast-routing + - name: Populate BGP address family configuration cisco.ios.ios_bgp_address_family: config: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml index c09e95661..81aa0512d 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/tests/cli/merged.yaml @@ -11,6 +11,22 @@ cisco.ios.ios_bgp_address_family: &id001 config: address_family: + - afi: l2vpn + safi: evpn + neighbor: + - address: 198.51.100.1 + activate: true + inherit: LEAF-EVPN-PEER-POLICY + - afi: ipv4 + vrf: green + redistribute: + - static: + set: true + - connected: + set: true + advertise: + afi: l2vpn + safi: evpn - afi: ipv4 redistribute: - connected: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/vars/main.yaml index 293bbe67a..e22a90dc0 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/vars/main.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_bgp_address_family/vars/main.yaml @@ -4,6 +4,13 @@ merged: commands: - router bgp 65000 + - address-family l2vpn evpn + - neighbor 198.51.100.1 activate + - neighbor 198.51.100.1 inherit peer-policy LEAF-EVPN-PEER-POLICY + - address-family ipv4 vrf green + - advertise l2vpn evpn + - redistribute connected + - redistribute static - address-family ipv4 multicast - default-metric 12 - distance bgp 10 10 100 @@ -24,6 +31,22 @@ merged: after: address_family: + - afi: l2vpn + safi: evpn + neighbor: + - address: 198.51.100.1 + activate: true + inherit: LEAF-EVPN-PEER-POLICY + - afi: ipv4 + vrf: green + advertise: + afi: l2vpn + safi: evpn + redistribute: + - static: + set: true + - connected: + set: true - afi: ipv4 redistribute: - connected: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml index 1578073cf..290765cbc 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_command/tests/cli/error_regex.yaml @@ -31,11 +31,6 @@ commands: - show logging - - name: Ensure task fails due to mismatched regex - ansible.builtin.assert: - that: - - result.failed == true - - name: Pause to avoid rate limiting-2 ansible.builtin.pause: seconds: 20 diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/acl_config.j2 b/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/acl_config.j2 new file mode 100644 index 000000000..ec4ee46b7 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_config/templates/basic/acl_config.j2 @@ -0,0 +1,4 @@ +ip access-list extended test + permit ip host 192.0.2.1 any log + permit ip host 192.0.2.2 any log + permit ip host 192.0.2.3 any log diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/replace_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/replace_config.yaml new file mode 100644 index 000000000..18f62808f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_config/tests/cli/replace_config.yaml @@ -0,0 +1,28 @@ +--- +- ansible.builtin.debug: msg="START cli/replace_block.yaml on connection={{ ansible_connection }}" + +- name: "setup" + cisco.ios.ios_config: + lines: + - "no ip access-list extended test" + +- name: "Populate ios acls configuration with replace block and lines options" + register: result1 + cisco.ios.ios_config: + lines: "{{ lookup('template', 'basic/acl_config.j2') }}" + replace: block + +- ansible.builtin.assert: + that: + - result1.changed == true + +- name: "Populate acl configuration with replace block and src options" + register: result2 + cisco.ios.ios_config: + src: basic/acl_config.j2 + replace: block + +- ansible.builtin.assert: + that: + - result2.changed == true + - result1.commands == result2.commands diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/defaults/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/meta/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/meta/main.yaml new file mode 100644 index 000000000..23d65c7ef --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/cli.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml index cd8c04990..6f505600c 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/cli.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tasks/cli.yaml @@ -3,16 +3,19 @@ ansible.builtin.find: paths: "{{ role_path }}/tests/cli" patterns: "{{ testcase }}.yaml" + use_regex: true register: test_cases delegate_to: localhost - name: Set test_items ansible.builtin.set_fact: test_items: "{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost -- name: Run test cases (connection=ansible.netcommon.network_cli) +- name: Run test case (connection=ansible.netcommon.network_cli) ansible.builtin.include_tasks: "{{ test_case_to_run }}" + vars: + ansible_connection: ansible.netcommon.network_cli with_items: "{{ test_items }}" loop_control: loop_var: test_case_to_run - tags: network_cli diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tasks/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tasks/main.yaml new file mode 100644 index 000000000..39c4567e9 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Main task for EVPN EVI module + ansible.builtin.include_tasks: cli.yaml + tags: + - network_cli diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_parsed.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_parsed.cfg new file mode 100644 index 000000000..b2df4cb25 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_parsed.cfg @@ -0,0 +1,9 @@ +l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable +! +l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress +! diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_populate_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_populate_config.yaml new file mode 100644 index 000000000..07d1d93c3 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_populate_config.yaml @@ -0,0 +1,13 @@ +--- +- name: Populate configuration + cisco.ios.ios_evpn_evi: + config: + - evi: 101 + replication_type: static + - evi: 102 + replication_type: ingress + - evi: 201 + replication_type: static + - evi: 202 + replication_type: ingress + state: merged diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_remove_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_remove_config.yaml new file mode 100644 index 000000000..b0892f314 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/_remove_config.yaml @@ -0,0 +1,15 @@ +--- +- name: Remove VLAN config + ansible.netcommon.cli_config: + config: | + no vlan configuration 101 + no vlan configuration 102 + no vlan configuration 201 + no vlan configuration 202 + no vlan configuration 901 + no vlan configuration 902 + +- name: Remove all configuration evpn_evi + cisco.ios.ios_evpn_evi: + config: + state: deleted diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/deleted.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/deleted.yaml new file mode 100644 index 000000000..4192f1844 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/deleted.yaml @@ -0,0 +1,32 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for ios_evpn_evi ansible_connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete attributes of all configured EVPN EVI + register: result + cisco.ios.ios_evpn_evi: + config: + - evi: 101 + state: deleted + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - deleted['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - deleted['after'] == result['after'] + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/empty_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/empty_config.yaml new file mode 100644 index 000000000..b5b7be66d --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/empty_config.yaml @@ -0,0 +1,58 @@ +--- +- ansible.builtin.debug: + msg: START ios_evpn_evi empty_config.yaml integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_evi: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_evi: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_evi: + config: + state: overridden + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Rendered with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_evi: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_evi: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/gathered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/gathered.yaml new file mode 100644 index 000000000..553cb862f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: START ios_evpn_evi gathered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Ios_evpn_evi gather - play + register: result + cisco.ios.ios_evpn_evi: + config: + state: gathered + + - name: Ios_evpn_evi gather - assert + ansible.builtin.assert: + that: + - result.changed == false + - gathered['after'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/merged.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/merged.yaml new file mode 100644 index 000000000..c4b485cce --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/merged.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: START Merged ios_evpn_evi state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_evpn_evi: &id001 + config: + - evi: 101 + replication_type: ingress + route_distinguisher: "1:1" + default_gateway: + advertise: + enable: false + ip: + local_learning: + enable: true + - evi: 202 + replication_type: static + default_gateway: + advertise: + enable: true + ip: + local_learning: + disable: true + state: merged + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.ios.ios_evpn_evi: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/overridden.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/overridden.yaml new file mode 100644 index 000000000..c33417f3e --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/overridden.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: START Overridden ios_evpn_evi state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Override device configuration of all EVPN EVI with provided configuration + register: result + cisco.ios.ios_evpn_evi: &id001 + config: + - evi: 101 + replication_type: ingress + default_gateway: + advertise: + enable: true + - evi: 202 + replication_type: static + default_gateway: + advertise: + enable: true + state: overridden + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - overridden['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - overridden['after'] == result['after'] + + - name: Override device configuration of all EVPN EVI with provided configuration (idempotent) + register: result + cisco.ios.ios_evpn_evi: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/parsed.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/parsed.yaml new file mode 100644 index 000000000..fec21d532 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/parsed.yaml @@ -0,0 +1,19 @@ +--- +- ansible.builtin.debug: + msg: START Parsed ios_evpn_evi state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_evpn_evi parsed - play + register: result + cisco.ios.ios_evpn_evi: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - name: Ios_evpn_evi parsed - assert config + ansible.builtin.assert: + that: + - result.changed == false + - parsed['after'] == result['parsed'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/rendered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/rendered.yaml new file mode 100644 index 000000000..8b2fd0dd9 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/rendered.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: START Rendered ios_evpn_evi state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_evpn_evi rendered - play + register: result + cisco.ios.ios_evpn_evi: + config: + - evi: 101 + replication_type: ingress + default_gateway: + advertise: + enable: true + - evi: 202 + replication_type: ingress + state: rendered + + - name: Ios_evpn_evi rendered - assert commands + ansible.builtin.assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) | length == 0 }}" + - result['changed'] == false diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/replaced.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/replaced.yaml new file mode 100644 index 000000000..656cb23ef --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/tests/cli/replaced.yaml @@ -0,0 +1,46 @@ +--- +- ansible.builtin.debug: + msg: START Replaced ios_evpn_evi state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Replaces device configuration of listed EVPN EVI with provided configuration + register: result + cisco.ios.ios_evpn_evi: &id001 + config: + - evi: 101 + replication_type: ingress + default_gateway: + advertise: + enable: true + - evi: 202 + replication_type: ingress + state: replaced + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - replaced['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] + + - name: Replaces device configuration of listed EVPN EVI with provided configuration (idempotent) + register: result + cisco.ios.ios_evpn_evi: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/vars/main.yaml new file mode 100644 index 000000000..4818d9828 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_evi/vars/main.yaml @@ -0,0 +1,183 @@ +--- +merged: + before: + - evi: 101 + encapsulation: vxlan + replication_type: static + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + commands: + - l2vpn evpn instance 202 vlan-based + - default-gateway advertise enable + - ip local-learning disable + - replication-type static + - l2vpn evpn instance 101 vlan-based + - ip local-learning enable + - replication-type ingress + - rd 1:1 + after: + - evi: 101 + encapsulation: vxlan + replication_type: ingress + ip: + local_learning: + enable: true + route_distinguisher: "1:1" + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: static + ip: + local_learning: + disable: true + default_gateway: + advertise: + enable: true + +replaced: + before: + - evi: 101 + encapsulation: vxlan + replication_type: static + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + commands: + - l2vpn evpn instance 101 vlan-based + - replication-type ingress + - default-gateway advertise enable + after: + - evi: 101 + default_gateway: + advertise: + enable: true + encapsulation: vxlan + replication_type: ingress + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + +overridden: + before: + - evi: 101 + encapsulation: vxlan + replication_type: static + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + commands: + - no l2vpn evpn instance 102 vlan-based + - no l2vpn evpn instance 201 vlan-based + - l2vpn evpn instance 101 vlan-based + - default-gateway advertise enable + - replication-type ingress + - l2vpn evpn instance 202 vlan-based + - default-gateway advertise enable + - replication-type static + after: + - evi: 101 + encapsulation: vxlan + replication_type: ingress + default_gateway: + advertise: + enable: true + - evi: 202 + encapsulation: vxlan + replication_type: static + default_gateway: + advertise: + enable: true + +deleted: + before: + - evi: 101 + encapsulation: vxlan + replication_type: static + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + commands: + - no l2vpn evpn instance 101 vlan-based + after: + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + +rendered: + commands: + - l2vpn evpn instance 101 vlan-based + - default-gateway advertise enable + - encapsulation vxlan + - replication-type ingress + - l2vpn evpn instance 202 vlan-based + - encapsulation vxlan + - replication-type ingress + +gathered: + after: + - evi: 101 + encapsulation: vxlan + replication_type: static + - evi: 102 + encapsulation: vxlan + replication_type: ingress + - evi: 201 + encapsulation: vxlan + replication_type: static + - evi: 202 + encapsulation: vxlan + replication_type: ingress + +parsed: + after: + - evi: 101 + encapsulation: vxlan + replication_type: ingress + default_gateway: + advertise: + enable: true + - evi: 102 + encapsulation: vxlan + replication_type: ingress diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/defaults/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/meta/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/meta/main.yaml new file mode 100644 index 000000000..23d65c7ef --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/cli.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/cli.yaml new file mode 100644 index 000000000..6f505600c --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/cli.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all CLI test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/main.yaml new file mode 100644 index 000000000..83b543a3f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Main task for evpn_global module + ansible.builtin.include_tasks: cli.yaml + tags: + - network_cli diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_parsed.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_parsed.cfg new file mode 100644 index 000000000..c43065fd2 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_parsed.cfg @@ -0,0 +1,5 @@ +l2vpn evpn + replication-type ingress + router-id Loopback1 + default-gateway advertise + route-target auto vni diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_populate_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_populate_config.yaml new file mode 100644 index 000000000..89c6d4ee8 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_populate_config.yaml @@ -0,0 +1,19 @@ +--- +- name: Configure Loopback1 + vars: + lines: "interface Loopback 1\nip address 172.16.254.4 255.255.255.255\nip pim sparse-mode\n" + ansible.netcommon.cli_config: + config: "{{ lines }}" + +- name: Populate configuration evpn_global + cisco.ios.ios_evpn_global: + config: + replication_type: ingress + route_target: + auto: + vni: true + router_id: Loopback1 + ip: + local_learning: + disable: true + state: merged diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_remove_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_remove_config.yaml new file mode 100644 index 000000000..8e07ea809 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/_remove_config.yaml @@ -0,0 +1,5 @@ +--- +- name: Remove all configuration evpn_global + cisco.ios.ios_evpn_global: + config: + state: deleted diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml new file mode 100644 index 000000000..6ed823307 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/deleted.yaml @@ -0,0 +1,38 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for ios_evpn_global ansible_connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Ios_evpn_global deleted - play + register: result + cisco.ios.ios_evpn_global: &id001 + config: + state: deleted + + - name: Ios_evpn_global deleted - assert commands + ansible.builtin.assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Ios_evpn_global deleted - assert before + ansible.builtin.assert: + that: + - deleted['before'] == result['before'] + + - name: Ios_evpn_global deleted - assert after + ansible.builtin.assert: + that: + - deleted['after'] == result['after'] + + - name: Ios_evpn_global deleted - play (idempotent) + register: result + cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global deleted - assert above task was idempotent + ansible.builtin.assert: + that: + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/empty_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/empty_config.yaml new file mode 100644 index 000000000..8625feaa5 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/empty_config.yaml @@ -0,0 +1,25 @@ +--- +- ansible.builtin.debug: + msg: START ios_evpn_global empty_config.yaml integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_global: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_evpn_global: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/gathered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/gathered.yaml new file mode 100644 index 000000000..51bf9bc3d --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/gathered.yaml @@ -0,0 +1,22 @@ +--- +- ansible.builtin.debug: + msg: START Gathered ios_evpn_global state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Ios_evpn_global gathered - play + register: result + cisco.ios.ios_evpn_global: + config: + state: gathered + + - name: Ios_evpn_global gathered - assert config + ansible.builtin.assert: + that: + - result.changed == false + - gathered['after'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml new file mode 100644 index 000000000..485c85778 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/merged.yaml @@ -0,0 +1,50 @@ +--- +- ansible.builtin.debug: + msg: START Merged ios_evpn_global state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml + +- block: + - name: Ios_evpn_global merged - play + register: result + cisco.ios.ios_evpn_global: &id001 + config: + router_id: Loopback1 + replication_type: ingress + route_target: + auto: + vni: true + default_gateway: + advertise: false + ip: + local_learning: + disable: true + flooding_suppression: + address_resolution: + disable: false + state: merged + + - name: Ios_evpn_global merged - assert commands + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Ios_evpn_global merged - assert before + ansible.builtin.assert: + that: + - merged['before'] == result['before'] + + - name: Ios_evpn_global merged - assert after + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Ios_evpn_global merged - play (idempotent) + register: result + cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global merged - assert above task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/parsed.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/parsed.yaml new file mode 100644 index 000000000..2d582cab9 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/parsed.yaml @@ -0,0 +1,19 @@ +--- +- ansible.builtin.debug: + msg: START Parsed ios_evpn_global state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_evpn_global parsed - play + register: result + cisco.ios.ios_evpn_global: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - name: Ios_evpn_global parsed - assert config + ansible.builtin.assert: + that: + - result.changed == false + - parsed['after'] == result['parsed'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/rendered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/rendered.yaml new file mode 100644 index 000000000..e1fb538d0 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/rendered.yaml @@ -0,0 +1,20 @@ +--- +- ansible.builtin.debug: + msg: START Rendered ios_evpn_global state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_evpn_global rendered - play + register: result + cisco.ios.ios_evpn_global: + config: + replication_type: static + route_target: + auto: + vni: true + state: rendered + + - name: Ios_evpn_global rendered - assert commands + ansible.builtin.assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) | length == 0 }}" + - result['changed'] == false diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml new file mode 100644 index 000000000..47a9bb62f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/tests/cli/replaced.yaml @@ -0,0 +1,45 @@ +--- +- ansible.builtin.debug: + msg: START Replaced ios_evpn_global state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Ios_evpn_global replaced - play + register: result + cisco.ios.ios_evpn_global: &id001 + config: + replication_type: static + router_id: Loopback1 + default_gateway: + advertise: true + flooding_suppression: + address_resolution: + disable: true + state: replaced + + - name: Ios_evpn_global replaced - assert commands + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Ios_evpn_global replaced - assert before + ansible.builtin.assert: + that: + - replaced['before'] == result['before'] + + - name: Ios_evpn_global replaced - assert after + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] + + - name: Ios_evpn_global replaced - play (idempotent) + register: result + cisco.ios.ios_evpn_global: *id001 + - name: Ios_evpn_global replaced - assert above task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/vars/main.yaml new file mode 100644 index 000000000..7840aef0d --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_evpn_global/vars/main.yaml @@ -0,0 +1,85 @@ +--- +merged: + before: {} + commands: + - l2vpn evpn + - ip local-learning disable + - replication-type ingress + - route-target auto vni + - router-id Loopback1 + after: + replication_type: ingress + route_target: + auto: + vni: true + router_id: Loopback1 + ip: + local_learning: + disable: true + +replaced: + before: + router_id: Loopback1 + ip: + local_learning: + disable: true + replication_type: ingress + route_target: + auto: + vni: true + commands: + - l2vpn evpn + - default-gateway advertise + - flooding-suppression address-resolution disable + - no ip local-learning disable + - replication-type static + - no route-target auto vni + after: + default_gateway: + advertise: true + flooding_suppression: + address_resolution: + disable: true + replication_type: static + router_id: Loopback1 + +deleted: + before: + replication_type: ingress + route_target: + auto: + vni: true + router_id: Loopback1 + ip: + local_learning: + disable: true + commands: + - no l2vpn evpn + after: {} + +rendered: + commands: + - l2vpn evpn + - replication-type static + - route-target auto vni + +gathered: + after: + ip: + local_learning: + disable: true + replication_type: ingress + route_target: + auto: + vni: true + router_id: Loopback1 + +parsed: + after: + replication_type: ingress + route_target: + auto: + vni: true + router_id: Loopback1 + default_gateway: + advertise: true diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml index 1358a9ad2..ba8a1fd23 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_facts/tests/cli/all_facts.yaml @@ -1,13 +1,14 @@ --- - ansible.builtin.debug: msg="START cli/all_facts.yaml on connection={{ ansible_connection }}" -- name: Test getting all facts +- name: Test fetching all facts register: result cisco.ios.ios_facts: gather_subset: - all -- ansible.builtin.assert: +- name: Assert output of all facts + ansible.builtin.assert: that: - result.changed == false - "'config' in result.ansible_facts.ansible_net_gather_subset" diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml deleted file mode 100644 index 5f709c5aa..000000000 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/defaults/main.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -testcase: "*" diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml deleted file mode 100644 index ab3ad91bc..000000000 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/meta/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -dependencies: - - prepare_ios_tests diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml deleted file mode 100644 index 5e6448cf7..000000000 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tasks/main.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -- name: Main task for logging module - ansible.builtin.include_tasks: cli.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml deleted file mode 100644 index d14396195..000000000 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging/tests/cli/basic.yaml +++ /dev/null @@ -1,134 +0,0 @@ ---- -- name: Remove host logging - cisco.ios.ios_logging: &id001 - dest: host - name: 172.16.0.1 - state: absent - -- name: Remove console - cisco.ios.ios_logging: - dest: console - level: warnings - state: absent - -- name: Remove buffer - cisco.ios.ios_logging: - dest: buffered - size: 8000 - state: absent - -- name: Set up host logging - register: result - cisco.ios.ios_logging: - dest: host - name: 172.16.0.1 - facility: local7 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging host 172.16.0.1" in result.commands' - - '"logging facility local7" in result.commands' - -- name: Set up host logging again (idempotent) - register: result - cisco.ios.ios_logging: - dest: host - name: 172.16.0.1 - state: present - -- ansible.builtin.assert: &id002 - that: - - result.changed == false - -- name: Delete/disable host logging - register: result - cisco.ios.ios_logging: *id001 -- ansible.builtin.assert: - that: - - result.changed == true - - '"no logging host 172.16.0.1" in result.commands' - -- name: Delete/disable host logging (idempotent) - register: result - cisco.ios.ios_logging: *id001 -- ansible.builtin.assert: *id002 -- name: Console logging with level warnings - register: result - cisco.ios.ios_logging: - dest: console - level: warnings - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging console warnings" in result.commands' - -- name: Configure buffer size - register: result - cisco.ios.ios_logging: - dest: buffered - size: 8000 - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging buffered 8000" in result.commands' - -- name: Change logging parameters using aggregate - register: result - cisco.ios.ios_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 9000 - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging buffered 9000" in result.commands' - - '"logging console notifications" in result.commands' - -- name: Set both logging destination and facility - register: result - cisco.ios.ios_logging: &id003 - dest: buffered - facility: uucp - level: alerts - size: 4096 - state: present - -- ansible.builtin.assert: - that: - - result.changed == true - - '"logging buffered 4096 alerts" in result.commands' - - '"logging facility uucp" in result.commands' - -- name: Set both logging destination and facility (idempotent) - register: result - cisco.ios.ios_logging: *id003 -- ansible.builtin.assert: *id002 -- name: Remove logging as collection teardown - register: result - cisco.ios.ios_logging: - aggregate: - - dest: console - level: notifications - - - dest: buffered - size: 4096 - level: alerts - - - facility: uucp - state: absent - -- ansible.builtin.assert: - that: - - result.changed == true - - '"no logging console" in result.commands' - - '"no logging buffered" in result.commands' - - '"no logging facility uucp" in result.commands' diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging_global/tests/cli/deleted.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging_global/tests/cli/deleted.yaml index c0690ed59..75cefbe36 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_logging_global/tests/cli/deleted.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_logging_global/tests/cli/deleted.yaml @@ -1,6 +1,6 @@ --- - ansible.builtin.debug: - msg: Start Deleted integration state for ios_logging ansible_connection={{ ansible_connection }} + msg: Start Deleted integration state for ios_logging_global ansible_connection={{ ansible_connection }} - ansible.builtin.include_tasks: _remove_config.yaml - ansible.builtin.include_tasks: _populate_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml index 9c2298d9c..8439fa2f2 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_initial_vrf_setup.yaml @@ -1,6 +1,9 @@ --- - name: Create and setup VRF configuration - vars: - lines: "vrf definition ospf_vrf\naddress-family ipv4\nvrf definition blue\naddress-family ipv4\n" - ansible.netcommon.cli_config: - config: "{{ lines }}" + cisco.ios.ios_config: + lines: + - rd 100:1 + - route-target export 100:1 + - route-target import 100:1 + parents: + - ip vrf blue diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg index c3b4affb1..cbf17bf16 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/_parsed.cfg @@ -9,11 +9,10 @@ router ospf 1 default-information originate max-metric router-lsa on-startup 110 network 198.51.100.0 0.0.0.255 area 5 + area 5 capability default-exclusion area 10 authentication message-digest area 10 default-cost 10 area 10 nssa translate type7 suppress-fa area 10 nssa default-information-originate metric 10 area 10 filter-list prefix test_prefix_in in area 10 filter-list prefix test_prefix_out out - area 5 authentication - area 5 capability default-exclusion diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml index 439a1ff5f..27f07c04b 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml @@ -19,8 +19,6 @@ areas: - area_id: "5" capability: true - authentication: - enable: true - area_id: "10" authentication: message_digest: true diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml index b6c739efc..d045ef058 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/overridden.yaml @@ -30,12 +30,13 @@ authentication: message_digest: true - process_id: 100 - vrf: ospf_vrf + vrf: blue domain_id: ip_address: address: 192.0.5.1 auto_cost: reference_bandwidth: 5 + set: true areas: - area_id: "5" authentication: @@ -62,11 +63,12 @@ - "{{ overridden['after']['processes'] | symmetric_difference(result['after']['processes']) | length == 0 }}" - name: Override provided OSPF v2 configuration (idempotent) - register: result + register: result_id cisco.ios.ios_ospfv2: *id001 + - name: Assert that task was idempotent ansible.builtin.assert: that: - - result['changed'] == false + - result_id['changed'] == false always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml index b1bdade55..b2bff79a0 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/replaced.yaml @@ -30,12 +30,13 @@ authentication: message_digest: true - process_id: 100 - vrf: ospf_vrf + vrf: blue domain_id: ip_address: address: 192.0.5.1 auto_cost: reference_bandwidth: 5 + set: true areas: - area_id: "5" authentication: @@ -62,11 +63,12 @@ - "{{ replaced['after']['processes'] | symmetric_difference(result['after']['processes']) | length == 0 }}" - name: Replaced provided OSPF v2 configuration (idempotent) - register: result + register: result_id cisco.ios.ios_ospfv2: *id001 + - name: Assert that task was idempotent ansible.builtin.assert: that: - - result['changed'] == false + - result_id['changed'] == false always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml index b87da54b9..87a5694cb 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/tests/cli/rtt.yaml @@ -93,7 +93,7 @@ authentication: message_digest: true - process_id: 100 - vrf: ospf_vrf + vrf: blue domain_id: ip_address: address: 192.0.5.1 @@ -121,9 +121,14 @@ config: "{{ ansible_facts['network_resources']['ospfv2'] }}" state: overridden - - ansible.builtin.assert: + - name: Commands output + ansible.builtin.debug: + msg: "{{ revert }}" + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: that: - - revert.commands|length == 24 + - revert.commands|length == 23 - revert.changed == true - revert.commands|symmetric_difference(rtt.commands) == [] always: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml index 307b591e2..417cc5c9e 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ospfv2/vars/main.yaml @@ -20,15 +20,33 @@ merged: - area 10 nssa default-information-originate metric 10 - area 10 filter-list prefix test_prefix_out out - area 10 filter-list prefix test_prefix_in in - - area 5 authentication - area 5 capability default-exclusion after: processes: - areas: + - area_id: "10" + capability: true + auto_cost: + reference_bandwidth: 4 + set: true + distribute_list: + acls: + - direction: out + name: "10" + - direction: in + name: "123" + domain_id: + ip_address: + address: 192.0.3.1 + max_metric: + on_startup: + time: 100 + router_lsa: true + process_id: 200 + vrf: blue + - areas: - area_id: "5" - authentication: - enable: true capability: true - area_id: "10" authentication: @@ -54,30 +72,10 @@ merged: area: "5" wildcard_bits: 0.0.0.255 process_id: 1 - - areas: - - area_id: "10" - capability: true - auto_cost: - reference_bandwidth: 4 - distribute_list: - acls: - - direction: out - name: "10" - - direction: in - name: "123" - domain_id: - ip_address: - address: 192.0.3.1 - max_metric: - on_startup: - time: 100 - router_lsa: true - process_id: 200 - vrf: blue replaced: commands: - - router ospf 100 vrf ospf_vrf + - router ospf 100 vrf blue - auto-cost reference-bandwidth 5 - domain-id 192.0.5.1 - area 5 authentication message-digest @@ -98,9 +96,24 @@ replaced: after: processes: - areas: - - area_id: "5" + - area_id: "10" authentication: - enable: true + message_digest: true + default_cost: 10 + domain_id: + ip_address: + address: 192.0.4.1 + max_metric: + on_startup: + time: 200 + router_lsa: true + maximum_paths: 15 + process_id: 200 + ttl_security: + hops: 7 + vrf: blue + - areas: + - area_id: "5" capability: true - area_id: "10" authentication: @@ -136,33 +149,17 @@ replaced: translate: suppress-fa auto_cost: reference_bandwidth: 5 + set: true domain_id: ip_address: address: 192.0.5.1 process_id: 100 - vrf: ospf_vrf - - areas: - - area_id: "10" - authentication: - message_digest: true - default_cost: 10 - domain_id: - ip_address: - address: 192.0.4.1 - max_metric: - on_startup: - time: 200 - router_lsa: true - maximum_paths: 15 - process_id: 200 - ttl_security: - hops: 7 vrf: blue overridden: commands: - no router ospf 1 - - router ospf 100 vrf ospf_vrf + - router ospf 100 vrf blue - auto-cost reference-bandwidth 5 - domain-id 192.0.5.1 - area 5 authentication message-digest @@ -183,21 +180,6 @@ overridden: after: processes: - areas: - - area_id: "5" - authentication: - message_digest: true - nssa: - default_information_originate: - metric: 10 - translate: suppress-fa - auto_cost: - reference_bandwidth: 5 - domain_id: - ip_address: - address: 192.0.5.1 - process_id: 100 - vrf: ospf_vrf - - areas: - area_id: "10" authentication: message_digest: true @@ -214,6 +196,22 @@ overridden: ttl_security: hops: 7 vrf: blue + - areas: + - area_id: "5" + authentication: + message_digest: true + nssa: + default_information_originate: + metric: 10 + translate: suppress-fa + auto_cost: + reference_bandwidth: 5 + set: true + domain_id: + ip_address: + address: 192.0.5.1 + process_id: 100 + vrf: blue deleted: commands: @@ -224,7 +222,7 @@ deleted: rtt: commands: - - no router ospf 100 vrf ospf_vrf + - no router ospf 100 vrf blue - router ospf 200 vrf blue - auto-cost reference-bandwidth 4 - distribute-list 10 out @@ -246,5 +244,4 @@ rtt: - area 10 nssa default-information-originate metric 10 - area 10 filter-list prefix test_prefix_out out - area 10 filter-list prefix test_prefix_in in - - area 5 authentication - area 5 capability default-exclusion diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml index bc52e5ea8..71eda7ecb 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_ping/tests/cli/ping.yaml @@ -25,6 +25,12 @@ cisco.ios.ios_ping: dest: "{{ management_ip }}" +- name: Expected successful ping with size + register: esp + cisco.ios.ios_ping: + dest: "{{ management_ip }}" + size: 500 + - name: Unexpected unsuccessful ping register: uup ignore_errors: true diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/overridden.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/overridden.yaml index 901bd9524..e0a1ffd6b 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/overridden.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/overridden.yaml @@ -12,35 +12,34 @@ config: - afi: ipv4 prefix_lists: - - name: 10 - description: this is override test + - description: this is override test entries: - action: deny - prefix: 12.0.0.0/8 ge: 15 + prefix: 12.0.0.0/8 sequence: 15 - action: deny - prefix: 14.0.0.0/8 ge: 20 le: 21 + prefix: 14.0.0.0/8 sequence: 20 - - name: test_override - description: this is override test + name: "10" + - description: this is override test entries: - action: deny - prefix: 35.0.0.0/8 ge: 20 + prefix: 35.0.0.0/8 sequence: 10 + name: test_override - afi: ipv6 prefix_lists: - - name: test_ipv6 - description: this is ipv6 override test - entries: + - entries: - action: deny - prefix: 2001:DB8:0:4::/64 ge: 80 le: 100 + prefix: 2001:DB8:0:4::/64 sequence: 10 + name: test_ipv6 state: overridden - name: Assert that correct set of commands were generated @@ -56,6 +55,7 @@ - name: Override provided prefix lists configuration (idempotent) register: result cisco.ios.ios_prefix_lists: *id001 + - name: Assert that task was idempotent ansible.builtin.assert: that: diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/replaced.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/replaced.yaml index cbd519d9c..2ac0d2d71 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/replaced.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/tests/cli/replaced.yaml @@ -33,7 +33,6 @@ - afi: ipv6 prefix_lists: - name: test_ipv6 - description: this is ipv6 replace test entries: - action: deny prefix: 2001:DB8:0:4::/64 diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/vars/main.yaml index 78136adc0..c42ebac6c 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/vars/main.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_prefix_lists/vars/main.yaml @@ -70,16 +70,16 @@ merged: overridden: commands: - - no ip prefix-list test - - no ip prefix-list test_prefix - ip prefix-list 10 description this is override test - - no ip prefix-list 10 seq 10 deny 35.0.0.0/8 ge 10 - no ip prefix-list 10 seq 5 deny 1.0.0.0/8 le 15 - - ip prefix-list test_override seq 10 deny 35.0.0.0/8 ge 20 + - no ip prefix-list 10 seq 10 deny 35.0.0.0/8 ge 10 - ip prefix-list test_override description this is override test + - ip prefix-list test_override seq 10 deny 35.0.0.0/8 ge 20 + - no ip prefix-list test + - no ip prefix-list test_prefix + - no ipv6 prefix-list test_ipv6 description this is ipv6 prefix-list - no ipv6 prefix-list test_ipv6 seq 10 deny 2001:DB8:0:4::/64 ge 80 - ipv6 prefix-list test_ipv6 seq 10 deny 2001:DB8:0:4::/64 ge 80 le 100 - - ipv6 prefix-list test_ipv6 description this is ipv6 override test after: - afi: ipv4 @@ -105,8 +105,7 @@ overridden: name: test_override - afi: ipv6 prefix_lists: - - description: this is ipv6 override test - entries: + - entries: - action: deny ge: 80 le: 100 @@ -117,13 +116,13 @@ overridden: replaced: commands: - ip prefix-list 10 description this is replace test - - no ip prefix-list 10 seq 10 deny 35.0.0.0/8 ge 10 - no ip prefix-list 10 seq 5 deny 1.0.0.0/8 le 15 - - ip prefix-list test_replace seq 10 deny 35.0.0.0/8 ge 20 + - no ip prefix-list 10 seq 10 deny 35.0.0.0/8 ge 10 - ip prefix-list test_replace description this is replace test + - ip prefix-list test_replace seq 10 deny 35.0.0.0/8 ge 20 + - no ipv6 prefix-list test_ipv6 description this is ipv6 prefix-list - no ipv6 prefix-list test_ipv6 seq 10 deny 2001:DB8:0:4::/64 ge 80 - ipv6 prefix-list test_ipv6 seq 10 deny 2001:DB8:0:4::/64 ge 80 le 100 - - ipv6 prefix-list test_ipv6 description this is ipv6 replace test after: - afi: ipv4 @@ -168,8 +167,7 @@ replaced: name: test_replace - afi: ipv6 prefix_lists: - - description: this is ipv6 replace test - entries: + - entries: - action: deny ge: 80 le: 100 diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml index 5d42f498e..3cb732e7f 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_user/tests/cli/auth.yaml @@ -37,6 +37,17 @@ ansible.builtin.assert: that: - results.failed + + - name: Test long password fails + cisco.ios.ios_user: + name: auth_user + privilege: 15 + role: network-operator + state: present + configured_password: "{{ 'a' * 128 }}" + register: result_fail + failed_when: "'Invalid Password length' not in result_fail.msg" + always: - name: Reset connection with {{ ansible_user }} ansible.builtin.meta: reset_connection diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg new file mode 100644 index 000000000..0c81de124 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_parsed_vlan_config.cfg @@ -0,0 +1,12 @@ +vlan configuration 101 + member evpn-instance 101 vni 10101 +vlan configuration 102 + member evpn-instance 102 vni 10102 +vlan configuration 201 + member evpn-instance 201 vni 10201 +vlan configuration 202 + member evpn-instance 202 vni 10202 +vlan configuration 901 + member vni 50901 +vlan configuration 902 + member vni 50902 diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml new file mode 100644 index 000000000..d1c517a03 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_populate_config_vlan_config.yaml @@ -0,0 +1,17 @@ +--- +- name: Populate configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: true + state: merged diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml new file mode 100644 index 000000000..f78bb0c56 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/_remove_config_vlan_config.yaml @@ -0,0 +1,12 @@ +--- +- name: Remove configuration + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + - vlan_id: 102 + - vlan_id: 201 + - vlan_id: 202 + - vlan_id: 901 + - vlan_id: 902 + configuration: true + state: deleted diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml new file mode 100644 index 000000000..21249d763 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/deleted_vlan_config.yaml @@ -0,0 +1,39 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for ios_vlans ansible_connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Delete vlans attributes for all configured vlans + register: result + cisco.ios.ios_vlans: &id001 + configuration: true + state: deleted + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ deleted_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - deleted_vlan_config['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - deleted_vlan_config['after'] == result['after'] + + - name: Delete vlans attributes for all configured vlans (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result.changed == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml new file mode 100644 index 000000000..576adee2f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/gathered_vlan_config.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: START ios_vlans gathered integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Gather the provided configuration with the existing running configuration + register: result + cisco.ios.ios_vlans: + config: + configuration: true + state: gathered + + - name: Assert + ansible.builtin.assert: + that: + - gathered_vlan_config.config == result.gathered + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml new file mode 100644 index 000000000..6efce0fc0 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/merged_vlan_config.yaml @@ -0,0 +1,46 @@ +--- +- ansible.builtin.debug: + msg: START Merged ios_vlans state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config_vlan_config.yaml +- ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 201 + member: + vni: 10201 + evi: 201 + - vlan_id: 902 + member: + vni: 50902 + configuration: true + state: merged + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged_vlan_config['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - merged_vlan_config['after'] == result['after'] + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml new file mode 100644 index 000000000..52944e5ce --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/overridden_vlan_config.yaml @@ -0,0 +1,48 @@ +--- +- ansible.builtin.debug: + msg: START Overridden ios_vlans state for integration tests on connection={{ ansible_connection }} + +- block: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml + - ansible.builtin.include_tasks: _populate_config_vlan_config.yaml + +- block: + - name: Override device configuration of all vlans with provided configuration + register: result + cisco.ios.ios_vlans: &id001 + config: + - vlan_id: 101 + member: + vni: 10102 + evi: 102 + - vlan_id: 102 + member: + vni: 10101 + evi: 101 + configuration: true + state: overridden + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden_vlan_config['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - overridden_vlan_config['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - overridden_vlan_config['after'] == result['after'] + + - name: Override device configuration of all interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vlans: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config_vlan_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml new file mode 100644 index 000000000..7d8311711 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/parsed_vlan_config.yaml @@ -0,0 +1,17 @@ +--- +- ansible.builtin.debug: + msg: START ios_vlans parsed integration tests on connection={{ ansible_connection }} + +- block: + - name: Parse the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + running_config: "{{ lookup('file', '_parsed_vlan_config.cfg') }}" + configuration: true + state: parsed + + - ansible.builtin.assert: + that: + - result.changed == false + - parsed_vlan_config.config == result.parsed diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml new file mode 100644 index 000000000..63cc24a29 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/tests/cli/rendered_vlan_config.yaml @@ -0,0 +1,28 @@ +--- +- ansible.builtin.debug: + msg: Start ios_vlans rendered integration tests ansible_connection={{ ansible_connection }} + +- block: + - name: Render the commands for provided configuration + become: true + register: result + cisco.ios.ios_vlans: + config: + - vlan_id: 101 + member: + vni: 10101 + evi: 101 + - vlan_id: 102 + member: + vni: 10102 + evi: 102 + - vlan_id: 901 + member: + vni: 50901 + configuration: true + state: rendered + + - ansible.builtin.assert: + that: + - result.changed == false + - result.rendered|symmetric_difference(rendered_vlan_config.commands) == [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml index 72400621d..6092684a9 100644 --- a/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vlans/vars/main.yaml @@ -93,6 +93,43 @@ merged: shutdown: enabled state: active vlan_id: 1005 +merged_vlan_config: + before: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - vlan configuration 201 + - member evpn-instance 201 vni 10201 + - vlan configuration 902 + - member vni 50902 + after: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 replaced: before: - mtu: 1500 @@ -278,6 +315,36 @@ overridden: shutdown: enabled state: active vlan_id: 1005 +overridden_vlan_config: + before: + - vlan_id: 101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - vlan configuration 101 + - no member evpn-instance 101 vni 10101 + - vlan configuration 102 + - no member evpn-instance 102 vni 10102 + - vlan configuration 101 + - member evpn-instance 102 vni 10102 + - vlan configuration 102 + - member evpn-instance 101 vni 10101 + - no vlan configuration 901 + + after: + - vlan_id: 101 + member: + evi: 102 + vni: 10102 + - vlan_id: 102 + member: + evi: 101 + vni: 10101 deleted: before: - mtu: 1500 @@ -350,6 +417,26 @@ deleted: shutdown: enabled state: active vlan_id: 1005 +deleted_vlan_config: + before: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + commands: + - no vlan configuration 101 + - no vlan configuration 102 + - no vlan configuration 901 + + after: [] + gathered: config: - mtu: 1500 @@ -392,6 +479,21 @@ gathered: shutdown: enabled state: active vlan_id: 1005 + +gathered_vlan_config: + config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 901 + member: + vni: 50901 + parsed: config: - mtu: 1500 @@ -435,6 +537,31 @@ parsed: state: active vlan_id: 1005 +parsed_vlan_config: + config: + - vlan_id: 101 + member: + evi: 101 + vni: 10101 + - vlan_id: 102 + member: + evi: 102 + vni: 10102 + - vlan_id: 201 + member: + evi: 201 + vni: 10201 + - vlan_id: 202 + member: + evi: 202 + vni: 10202 + - vlan_id: 901 + member: + vni: 50901 + - vlan_id: 902 + member: + vni: 50902 + rendered: commands: - vlan 10 @@ -452,6 +579,15 @@ rendered: - state suspend - shutdown +rendered_vlan_config: + commands: + - vlan configuration 101 + - member evpn-instance 101 vni 10101 + - vlan configuration 102 + - member evpn-instance 102 vni 10102 + - vlan configuration 901 + - member vni 50901 + rtt: commands: - vlan 10 diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/defaults/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/defaults/main.yaml new file mode 100644 index 000000000..164afead2 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/meta/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/meta/main.yaml new file mode 100644 index 000000000..23d65c7ef --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/meta/main.yaml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml new file mode 100644 index 000000000..6f505600c --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/cli.yaml @@ -0,0 +1,21 @@ +--- +- name: Collect all CLI test cases + ansible.builtin.find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + use_regex: true + register: test_cases + delegate_to: localhost + +- name: Set test_items + ansible.builtin.set_fact: + test_items: "{{ test_cases.files | map(attribute='path') | list }}" + delegate_to: localhost + +- name: Run test case (connection=ansible.netcommon.network_cli) + ansible.builtin.include_tasks: "{{ test_case_to_run }}" + vars: + ansible_connection: ansible.netcommon.network_cli + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml new file mode 100644 index 000000000..d80ee1ae2 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Main task for VXLAN VTEP module + ansible.builtin.include_tasks: cli.yaml + tags: + - network_cli diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_parsed.cfg b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_parsed.cfg new file mode 100644 index 000000000..46ecf2e1d --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_parsed.cfg @@ -0,0 +1,7 @@ +interface nve1 + source-interface Loopback1 + host-reachability protocol bgp + member vni 10101 ingress-replication + member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + member vni 50901 vrf green + member vni 50902 vrf blue diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_config.yaml new file mode 100644 index 000000000..1587cb9bc --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_config.yaml @@ -0,0 +1,34 @@ +--- +- name: Populate VXLAN VTEP configuration + cisco.ios.ios_vxlan_vtep: + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + state: merged diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_vlan_vrf_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_vlan_vrf_config.yaml new file mode 100644 index 000000000..c6d5dee3e --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_populate_vlan_vrf_config.yaml @@ -0,0 +1,61 @@ +--- +- name: Configure VLANs and VRFs + ansible.netcommon.cli_config: + config: | + vlan 101 + name Access_VLAN_101 + vlan 102 + name Access_VLAN_102 + vlan 201 + name Access_VLAN_201 + vlan 202 + name Access_VLAN_202 + vlan 901 + name Core_VLAN_VRF_green + vlan 902 + name Core_VLAN_VRF_blue + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + vrf definition blue + description blue VRF defn + rd 2:2 + ! + address-family ipv4 + route-target export 2:2 + route-target import 2:2 + route-target export 2:2 stitching + route-target import 2:2 stitching + exit-address-family + ! + address-family ipv6 + route-target export 2:2 + route-target import 2:2 + route-target import 2:2 stitching + exit-address-family + vrf definition green + description green VRF defn + rd 1:1 + ! + address-family ipv4 + route-target export 1:1 + route-target import 1:1 + route-target export 1:1 stitching + route-target import 1:1 stitching + exit-address-family + ! + address-family ipv6 + route-target export 1:1 + route-target import 1:1 + route-target export 1:1 stitching + route-target import 1:1 stitching + exit-address-family diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_remove_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_remove_config.yaml new file mode 100644 index 000000000..52c43242f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/_remove_config.yaml @@ -0,0 +1,6 @@ +--- +- name: Remove VXLAN VTEP configuration + cisco.ios.ios_vxlan_vtep: + config: + - interface: nve1 + state: deleted diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/deleted.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/deleted.yaml new file mode 100644 index 000000000..75d18ddec --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/deleted.yaml @@ -0,0 +1,33 @@ +--- +- ansible.builtin.debug: + msg: Start Deleted integration state for ios_vxlan_vtep ansible_connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_vlan_vrf_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Delete provided VXLAN VTEP interface + register: result + cisco.ios.ios_vxlan_vtep: &id001 + config: + - interface: nve1 + state: deleted + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ deleted['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - "{{ merged['after'] | symmetric_difference(result['before']) | length == 0 }}" + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - "{{ deleted['after'] | symmetric_difference(result['after']) | length == 0 }}" + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/empty_config.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/empty_config.yaml new file mode 100644 index 000000000..4034115e5 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/empty_config.yaml @@ -0,0 +1,58 @@ +--- +- ansible.builtin.debug: + msg: START ios_vxlan_vtep empty_config.yaml integration tests on connection={{ ansible_connection }} + +- name: Merged with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vxlan_vtep: + config: + state: merged + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vxlan_vtep: + config: + state: replaced + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vxlan_vtep: + config: + state: overridden + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' + +- name: Rendered with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vxlan_vtep: + config: + state: rendered + +- ansible.builtin.assert: + that: + - result.msg == 'value of config parameter must not be empty for state rendered' + +- name: Parsed with empty configuration should give appropriate error message + register: result + ignore_errors: true + cisco.ios.ios_vxlan_vtep: + running_config: + state: parsed + +- ansible.builtin.assert: + that: + - result.msg == 'value of running_config parameter must not be empty for state parsed' diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/gathered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/gathered.yaml new file mode 100644 index 000000000..2f334a79f --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/gathered.yaml @@ -0,0 +1,23 @@ +--- +- ansible.builtin.debug: + msg: START ios_vxlan_vtep gathered integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_vlan_vrf_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Ios_vxlan_vtep gather - play + register: result + cisco.ios.ios_vxlan_vtep: + config: + state: gathered + + - name: Ios_vxlan_vtep gather - assert + ansible.builtin.assert: + that: + - result.changed == false + - gathered['config'] == result['gathered'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/merged.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/merged.yaml new file mode 100644 index 000000000..ba004e9db --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/merged.yaml @@ -0,0 +1,67 @@ +--- +- ansible.builtin.debug: + msg: START Merged ios_vxlan_vtep state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_vlan_vrf_config.yaml + +- block: + - name: Merge provided configuration with device configuration + register: result + cisco.ios.ios_vxlan_vtep: &id001 + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + state: merged + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - merged['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - merged['after'] == result['after'] + + - name: Merge provided configuration with device configuration (idempotent) + register: result + cisco.ios.ios_vxlan_vtep: *id001 + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/overridden.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/overridden.yaml new file mode 100644 index 000000000..187d71eae --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/overridden.yaml @@ -0,0 +1,59 @@ +--- +- ansible.builtin.debug: + msg: START Overridden ios_vxlan_vtep state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_vlan_vrf_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Override device configuration of all VTEP interfaces with provided configuration + register: result + cisco.ios.ios_vxlan_vtep: &id001 + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: static + mcast_group: + ipv6: FF0E:225::101 + - vni: 10201 + replication: + type: static + mcast_group: + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: blue + state: overridden + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ overridden['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - overridden['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - overridden['after'] == result['after'] + + - name: Override device configuration of all VTEP interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vxlan_vtep: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/parsed.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/parsed.yaml new file mode 100644 index 000000000..82d84b037 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/parsed.yaml @@ -0,0 +1,19 @@ +--- +- ansible.builtin.debug: + msg: START Parsed ios_vxlan_vtep state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_vxlan_vtep parsed - play + register: result + cisco.ios.ios_vxlan_vtep: + running_config: "{{ lookup('file', '_parsed.cfg') }}" + state: parsed + + - name: Ios_vxlan_vtep parsed - assert config + ansible.builtin.assert: + that: + - result.changed == false + - parsed['config'] == result['parsed'] + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/rendered.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/rendered.yaml new file mode 100644 index 000000000..9979d6f30 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/rendered.yaml @@ -0,0 +1,34 @@ +--- +- ansible.builtin.debug: + msg: START Rendered ios_vxlan_vtep state for integration tests on connection={{ ansible_connection }} + +- block: + - name: Ios_vxlan_vtep rendered - play + register: result + cisco.ios.ios_vxlan_vtep: &id001 + config: + - interface: nve1 + source_interface: Loopback1 + member: + vni: + l2vni: + - vni: 10101 + replication: + type: static + mcast_group: + ipv6: FF0E:225::101 + - vni: 10201 + replication: + type: static + mcast_group: + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: blue + state: rendered + + - name: Ios_vxlan_vtep rendered - assert commands + ansible.builtin.assert: + that: + - "{{ rendered['commands'] | symmetric_difference(result['rendered']) | length == 0 }}" + - result['changed'] == false diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/replaced.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/replaced.yaml new file mode 100644 index 000000000..5e24f4336 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/tests/cli/replaced.yaml @@ -0,0 +1,56 @@ +--- +- ansible.builtin.debug: + msg: START Replaced ios_vxlan_vtep state for integration tests on connection={{ ansible_connection }} + +- ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _populate_vlan_vrf_config.yaml +- ansible.builtin.include_tasks: _populate_config.yaml + +- block: + - name: Replaces device configuration of listed VTEP interfaces with provided configuration + register: result + cisco.ios.ios_vxlan_vtep: &id001 + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: static + mcast_group: + ipv6: FF0E:225::101 + - vni: 10201 + replication: + type: static + mcast_group: + ipv6: FF0E:225::102 + state: replaced + + - name: Assert that correct set of commands were generated + ansible.builtin.assert: + that: + - "{{ replaced['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + + - name: Assert that before dicts are correctly generated + ansible.builtin.assert: + that: + - replaced['before'] == result['before'] + + - name: Assert that after dict is correctly generated + ansible.builtin.assert: + that: + - replaced['after'] == result['after'] + + - name: Replaces device configuration of listed VTEP interfaces with provided configuration (idempotent) + register: result + cisco.ios.ios_vxlan_vtep: *id001 + - name: Assert that task was idempotent + ansible.builtin.assert: + that: + - result['changed'] == false + + always: + - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/vars/main.yaml b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/vars/main.yaml new file mode 100644 index 000000000..9ee70d3f7 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/integration/targets/ios_vxlan_vtep/vars/main.yaml @@ -0,0 +1,274 @@ +--- +merged: + before: + - interface: nve1 + commands: + - interface nve1 + - source-interface Loopback1 + - host-reachability protocol bgp + - member vni 10101 ingress-replication + - member vni 10102 ingress-replication + - member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + - member vni 10202 mcast-group 225.0.0.102 FF0E:225::102 + - member vni 50901 vrf green + - member vni 50902 vrf blue + after: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue +replaced: + before: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + commands: + - interface nve1 + - no member vni 10101 ingress-replication + - member vni 10101 mcast-group FF0E:225::101 + - no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + - member vni 10201 mcast-group FF0E:225::102 + - no member vni 10102 ingress-replication + - no member vni 10202 mcast-group 225.0.0.102 FF0E:225::102 + - no member vni 50901 vrf green + - no member vni 50902 vrf blue + after: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: static + mcast_group: + ipv6: FF0E:225::101 + - vni: 10201 + replication: + type: static + mcast_group: + ipv6: FF0E:225::102 + +overridden: + before: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + commands: + - interface nve1 + - no member vni 10101 ingress-replication + - member vni 10101 mcast-group FF0E:225::101 + - no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + - member vni 10201 mcast-group FF0E:225::102 + - no member vni 10102 ingress-replication + - no member vni 10202 mcast-group 225.0.0.102 FF0E:225::102 + - no member vni 50901 vrf green + - no member vni 50902 vrf blue + - member vni 50901 vrf blue + after: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: static + mcast_group: + ipv6: FF0E:225::101 + - vni: 10201 + replication: + type: static + mcast_group: + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: blue + +deleted: + before: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + commands: + - interface nve1 + - no source-interface Loopback1 + - no host-reachability protocol bgp + - no member vni 10101 ingress-replication + - no member vni 10102 ingress-replication + - no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + - no member vni 10202 mcast-group 225.0.0.102 FF0E:225::102 + - no member vni 50901 vrf green + - no member vni 50902 vrf blue + + after: + - interface: nve1 + host_reachability_bgp: true + +gathered: + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10102 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + - vni: 10202 + replication: + type: static + mcast_group: + ipv4: 225.0.0.102 + ipv6: FF0E:225::102 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + +parsed: + config: + - interface: nve1 + source_interface: Loopback1 + host_reachability_bgp: true + member: + vni: + l2vni: + - vni: 10101 + replication: + type: ingress + - vni: 10201 + replication: + type: static + mcast_group: + ipv4: 225.0.0.101 + ipv6: FF0E:225::101 + l3vni: + - vni: 50901 + vrf: green + - vni: 50902 + vrf: blue + +rendered: + commands: + - interface nve1 + - source-interface Loopback1 + - member vni 10101 mcast-group FF0E:225::101 + - member vni 10201 mcast-group FF0E:225::102 + - member vni 50901 vrf blue diff --git a/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt b/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt index 64ccd8a88..9dadf1b54 100644 --- a/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt +++ b/ansible_collections/cisco/ios/tests/sanity/ignore-2.10.txt @@ -19,3 +19,6 @@ plugins/module_utils/network/ios/config/route_maps/route_maps.py import-2.6!skip plugins/module_utils/network/ios/config/logging_global/logging_global.py import-2.6!skip plugins/module_utils/network/ios/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/ios/config/ntp_global/ntp_global.py import-2.6!skip +plugins/module_utils/network/ios/config/vxlan_vtep/vxlan_vtep.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_global/evpn_global.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_evi/evpn_evi.py import-2.6!skip diff --git a/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt b/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt index ed36434e4..2847c9344 100644 --- a/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt +++ b/ansible_collections/cisco/ios/tests/sanity/ignore-2.11.txt @@ -19,3 +19,6 @@ plugins/module_utils/network/ios/config/route_maps/route_maps.py import-2.6!skip plugins/module_utils/network/ios/config/logging_global/logging_global.py import-2.6!skip plugins/module_utils/network/ios/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/ios/config/ntp_global/ntp_global.py import-2.6!skip +plugins/module_utils/network/ios/config/vxlan_vtep/vxlan_vtep.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_global/evpn_global.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_evi/evpn_evi.py import-2.6!skip diff --git a/ansible_collections/cisco/ios/tests/sanity/ignore-2.17.txt b/ansible_collections/cisco/ios/tests/sanity/ignore-2.17.txt new file mode 100644 index 000000000..d7ff17ca8 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/sanity/ignore-2.17.txt @@ -0,0 +1 @@ +plugins/action/ios.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` diff --git a/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt b/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt index df15af536..11aba94e9 100644 --- a/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt +++ b/ansible_collections/cisco/ios/tests/sanity/ignore-2.9.txt @@ -2,8 +2,6 @@ plugins/modules/ios_bgp.py validate-modules:deprecation-mismatch plugins/modules/ios_bgp.py validate-modules:invalid-documentation plugins/modules/ios_lldp.py validate-modules:deprecation-mismatch plugins/modules/ios_lldp.py validate-modules:invalid-documentation -plugins/modules/ios_logging.py validate-modules:deprecation-mismatch -plugins/modules/ios_logging.py validate-modules:invalid-documentation plugins/modules/ios_ntp.py validate-modules:deprecation-mismatch plugins/modules/ios_ntp.py validate-modules:invalid-documentation plugins/modules/ios_linkagg.py validate-modules:deprecation-mismatch @@ -29,3 +27,6 @@ plugins/module_utils/network/ios/config/route_maps/route_maps.py import-2.6!skip plugins/module_utils/network/ios/config/logging_global/logging_global.py import-2.6!skip plugins/module_utils/network/ios/config/prefix_lists/prefix_lists.py import-2.6!skip plugins/module_utils/network/ios/config/ntp_global/ntp_global.py import-2.6!skip +plugins/module_utils/network/ios/config/vxlan_vtep/vxlan_vtep.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_global/evpn_global.py import-2.6!skip +plugins/module_utils/network/ios/config/evpn_evi/evpn_evi.py import-2.6!skip diff --git a/ansible_collections/cisco/ios/tests/unit/mock/loader.py b/ansible_collections/cisco/ios/tests/unit/mock/loader.py index ebff16f63..0fc53edcd 100644 --- a/ansible_collections/cisco/ios/tests/unit/mock/loader.py +++ b/ansible_collections/cisco/ios/tests/unit/mock/loader.py @@ -31,7 +31,7 @@ from ansible.parsing.dataloader import DataLoader class DictDataLoader(DataLoader): def __init__(self, file_mapping=None): file_mapping = {} if file_mapping is None else file_mapping - assert type(file_mapping) == dict + assert isinstance(file_mapping, dict) super(DictDataLoader, self).__init__() diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir index 3adc44adb..b5b36f4f3 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_dir @@ -1,23 +1,29 @@ Directory of bootflash:/ - 11 drwx 16384 Jun 1 2017 13:03:27 +00:00 lost+found -325121 drwx 4096 Jun 1 2017 13:03:54 +00:00 .super.iso.dir - 12 -rw- 31 Jun 22 2018 15:17:06 +00:00 .CsrLxc_LastInstall - 13 -rw- 69 Jun 1 2017 13:05:53 +00:00 virtual-instance.conf -438913 drwx 4096 Jun 1 2017 13:04:57 +00:00 core - 15 -rw- 125736960 Jun 1 2017 13:03:54 +00:00 iosxe-remote-mgmt.16.03.04.ova -105667 -rw- 292164568 Jun 1 2017 13:04:04 +00:00 csr1000v-mono-universalk9.16.03.04.SPA.pkg -105668 -rw- 34370768 Jun 1 2017 13:04:10 +00:00 csr1000v-rpboot.16.03.04.SPA.pkg -105666 -rw- 5317 Jun 1 2017 13:04:10 +00:00 packages.conf -195073 drwx 4096 Jun 1 2017 13:04:51 +00:00 .prst_sync -414529 drwx 4096 Jun 1 2017 13:04:57 +00:00 .rollback_timer - 16 -rw- 0 Jun 1 2017 13:05:00 +00:00 tracelogs.kZn -16257 drwx 24576 Jun 22 2018 16:03:11 +00:00 tracelogs -349505 drwx 4096 Jun 1 2017 13:05:08 +00:00 .installer -292609 drwx 4096 Jun 1 2017 13:05:59 +00:00 virtual-instance - 17 -rw- 30 Jun 22 2018 15:17:59 +00:00 throughput_monitor_params -48769 drwx 4096 Jun 1 2017 13:06:04 +00:00 onep - 19 -rw- 376 Jun 22 2018 15:18:11 +00:00 csrlxc-cfg.log - 20 -rw- 0 Jun 22 2018 15:17:59 +00:00 cvac.log - -7897796608 bytes total (6608056320 bytes free) +131075 drwx 24576 Jun 25 2023 13:10:37 +00:00 tracelogs +131078 drwx 4096 Feb 21 2023 12:23:20 +00:00 .installer +17 -rw- 509 Feb 21 2023 12:20:00 +00:00 cvac.log +131124 drwx 4096 Feb 21 2023 12:19:59 +00:00 license_evlog + + +5183766528 bytes total (4009947136 bytes free) + +Directory of flash:/ + +131075 drwx 24576 Jun 25 2023 13:10:37 +00:00 tracelogs +131078 drwx 4096 Feb 21 2023 12:23:20 +00:00 .installer +17 -rw- 509 Feb 21 2023 12:20:00 +00:00 cvac.log +131124 drwx 4096 Feb 21 2023 12:19:59 +00:00 license_evlog + + +4183766528 bytes total (4009947136 bytes free) + +Directory of flash1:/ + +131075 drwx 24576 Jun 25 2023 13:10:37 +00:00 tracelogs +131078 drwx 4096 Feb 21 2023 12:23:20 +00:00 .installer +17 -rw- 509 Feb 21 2023 12:20:00 +00:00 cvac.log +131124 drwx 4096 Feb 21 2023 12:19:59 +00:00 license_evlog + + +6183766528 bytes total (4009921136 bytes free) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_processes_cpu b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_processes_cpu new file mode 100644 index 000000000..7aec22810 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/fixtures/ios_facts_show_processes_cpu @@ -0,0 +1,4 @@ +CPU utilization for five seconds: 3%/2%; one minute: 1%; five minutes: 5% + PID Runtime(ms) Invoked uSecs 5Sec 1Min 5Min TTY Process +Core 0: CPU utilization for five seconds: 4%; one minute: 0%; five minutes: 3% +Core 1: CPU utilization for five seconds: 5%; one minute: 5%; five minutes: 3% diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py index 5d97c5890..6bc99691c 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acl_interfaces.py @@ -23,33 +23,12 @@ class TestIosAclInterfacesModule(TestIosModule): def setUp(self): super(TestIosAclInterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acl_interfaces.acl_interfaces." "Acl_interfacesFacts.get_acl_interfaces_data", @@ -58,19 +37,9 @@ class TestIosAclInterfacesModule(TestIosModule): def tearDown(self): super(TestIosAclInterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() - # def load_fixtures(self, commands=None): - # def load_from_file(*args, **kwargs): - # return load_fixture("ios_acl_interfaces.cfg") - - # self.execute_show_command.side_effect = load_from_file - def test_ios_acl_interfaces_merged(self): self.execute_show_command.return_value = dedent( """\ diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py index e383080f6..33c4a1ddb 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_acls.py @@ -23,62 +23,48 @@ class TestIosAclsModule(TestIosModule): def setUp(self): super(TestIosAclsModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acls.acls." "AclsFacts.get_acl_data", ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_execute_show_command_name_specific = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.acls.acls." + "AclsFacts.get_acl_names", + ) + self.execute_show_command_name = self.mock_execute_show_command_name_specific.start() def tearDown(self): super(TestIosAclsModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() + self.mock_execute_show_command_name_specific.stop() def test_ios_acls_merged(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 - Extended IP access list test_pre + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 + ip access-list extended test_pre 10 permit ip any any precedence internet """, ) + self.execute_show_command_name.return_value = dedent( + """\ + Standard IP access list test_acl + """, + ) + set_module_args( dict( config=[ @@ -148,7 +134,7 @@ class TestIosAclsModule(TestIosModule): ), dict( grant="deny", - protocol_options=dict(tcp=dict(ack="true")), + protocol_options=dict(tcp=dict(ack="True")), sequence="200", source=dict(object_group="test_network_og"), destination=dict(object_group="test_network_og"), @@ -178,18 +164,339 @@ class TestIosAclsModule(TestIosModule): ] self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_ios_acls_merged_idempotent(self): + def test_ios_acls_merged_remarks_positional(self): self.execute_show_command.return_value = dedent( """\ + """, + ) + self.execute_show_command_name.return_value = dedent( + """\ Standard IP access list test_acl - Extended IP access list 110 + """, + ) + + set_module_args( + dict( + config=[ + { + "acls": [ + { + "aces": [ + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "sequence": 10, + "source": { + "address": "10.40.150.0", + "wildcard_bits": "0.0.0.255", + }, + }, + { + "destination": { + "address": "10.40.150.0", + "wildcard_bits": "0.0.0.255", + }, + "grant": "permit", + "protocol": "ip", + "sequence": 20, + "source": {"any": True}, + }, + ], + "acl_type": "extended", + "name": "199", + }, + { + "aces": [ + { + "grant": "permit", + "sequence": 10, + "source": { + "address": "10.182.250.0", + "wildcard_bits": "0.0.0.255", + }, + }, + ], + "acl_type": "standard", + "name": "42", + }, + { + "aces": [ + { + "destination": {"any": True, "port_protocol": {"eq": "22"}}, + "grant": "permit", + "protocol": "tcp", + "sequence": 10, + "source": { + "address": "10.57.66.243", + "wildcard_bits": "0.0.0.7", + }, + }, + { + "destination": {"any": True, "port_protocol": {"eq": "22"}}, + "grant": "permit", + "protocol": "tcp", + "sequence": 20, + "source": {"host": "10.160.114.111"}, + }, + { + "destination": {"any": True, "port_protocol": {"eq": "22"}}, + "grant": "permit", + "protocol": "tcp", + "sequence": 30, + "source": {"host": "10.160.115.22"}, + }, + { + "destination": {"any": True}, + "grant": "deny", + "log": {"set": True}, + "protocol": "ip", + "sequence": 40, + "source": {"any": True}, + }, + ], + "acl_type": "extended", + "name": "NET-MGMT-VTY", + }, + { + "aces": [ + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "remarks": [ + "FIRST REMARK BEFORE LINE 10", + "============", + "ALLOW HOST FROM BUILDING 10", + ], + "sequence": 10, + "source": {"host": "1.1.1.1"}, + }, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "remarks": [ + "FIRST REMARK BEFORE LINE 20", + "============", + "ALLOW HOST FROM BUILDING 20", + ], + "sequence": 20, + "source": {"host": "2.2.2.2"}, + }, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "remarks": [ + "FIRST REMARK BEFORE LINE 30", + "============", + "ALLOW NEW HOST FROM BUILDING 10", + ], + "sequence": 30, + "source": {"host": "3.3.3.3"}, + }, + { + "remarks": [ + "FIRST REMARK AT END OF ACL", + "SECOND REMARK AT END OF ACL", + ], + }, + ], + "acl_type": "extended", + "name": "TEST", + }, + { + "aces": [ + { + "remarks": [ + "empty remark 1", + "empty remark 2", + "empty remark never ends", + ], + }, + ], + "acl_type": "extended", + "name": "empty_ip_ex_acl", + }, + { + "aces": [ + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "remarks": [ + "I am a test ace", + "I am right after the test ace", + "I third the test ace", + ], + "sequence": 100, + "source": {"host": "100.100.100.100"}, + }, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ip", + "remarks": [ + "I am the next test ace", + "I am the next ace to the next ace", + ], + "sequence": 110, + "source": {"host": "10.40.150.0"}, + }, + {"remarks": ["I am the peace ace", "Peace out"]}, + ], + "acl_type": "extended", + "name": "mytest", + }, + ], + "afi": "ipv4", + }, + { + "acls": [ + { + "aces": [ + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "ipv6", + "sequence": 10, + "source": {"address": "2001:ABAD:BEEF:1221::/64"}, + }, + { + "destination": { + "host": "2001:ABAD:BEEF:1212::1", + "port_protocol": {"eq": "www"}, + }, + "grant": "deny", + "protocol": "tcp", + "sequence": 20, + "source": {"host": "2001:ABAD:BEEF:2345::1"}, + }, + ], + "name": "R1_TRAFFIC", + }, + { + "aces": [ + {"remarks": ["empty remark 1"], "sequence": 10}, + {"remarks": ["empty remark 2"], "sequence": 20}, + {"remarks": ["empty remark never ends"], "sequence": 30}, + ], + "name": "empty_ipv6_acl", + }, + { + "aces": [ + {"remarks": ["I am a ipv6 ace"], "sequence": 10}, + {"remarks": ["I am test"], "sequence": 20}, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "tcp", + "sequence": 30, + "source": {"any": True}, + }, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "udp", + "sequence": 40, + "source": {"any": True}, + }, + {"remarks": ["I am new set of ipv6 ace"], "sequence": 50}, + { + "destination": {"any": True}, + "grant": "permit", + "protocol": "icmp", + "sequence": 60, + "source": {"any": True}, + }, + ], + "name": "ipv6_acl", + }, + ], + "afi": "ipv6", + }, + ], + state="merged", + ), + ) + result = self.execute_module(changed=True) + commands = [ + "ip access-list extended mytest", + "remark I am a test ace", + "remark I am right after the test ace", + "remark I third the test ace", + "100 permit ip host 100.100.100.100 any", + "remark I am the next test ace", + "remark I am the next ace to the next ace", + "110 permit ip host 10.40.150.0 any", + "remark I am the peace ace", + "remark Peace out", + "ip access-list extended 199", + "10 permit ip 10.40.150.0 0.0.0.255 any", + "20 permit ip any 10.40.150.0 0.0.0.255", + "ip access-list extended NET-MGMT-VTY", + "10 permit tcp 10.57.66.243 0.0.0.7 any eq 22", + "20 permit tcp host 10.160.114.111 any eq 22", + "30 permit tcp host 10.160.115.22 any eq 22", + "40 deny ip any any log", + "ip access-list extended empty_ip_ex_acl", + "remark empty remark 1", + "remark empty remark 2", + "remark empty remark never ends", + "ip access-list extended TEST", + "remark FIRST REMARK BEFORE LINE 10", + "remark ============", + "remark ALLOW HOST FROM BUILDING 10", + "10 permit ip host 1.1.1.1 any", + "remark FIRST REMARK BEFORE LINE 20", + "remark ============", + "remark ALLOW HOST FROM BUILDING 20", + "20 permit ip host 2.2.2.2 any", + "remark FIRST REMARK BEFORE LINE 30", + "remark ============", + "remark ALLOW NEW HOST FROM BUILDING 10", + "30 permit ip host 3.3.3.3 any", + "remark FIRST REMARK AT END OF ACL", + "remark SECOND REMARK AT END OF ACL", + "ip access-list standard 42", + "10 permit 10.182.250.0 0.0.0.255", + "ipv6 access-list R1_TRAFFIC", + "permit ipv6 2001:ABAD:BEEF:1221::/64 any sequence 10", + "deny tcp host 2001:ABAD:BEEF:2345::1 host 2001:ABAD:BEEF:1212::1 eq www sequence 20", + "ipv6 access-list empty_ipv6_acl", + "remark empty remark 1", + " sequence 10", + "remark empty remark 2", + " sequence 20", + "remark empty remark never ends", + " sequence 30", + "ipv6 access-list ipv6_acl", + "remark I am a ipv6 ace", + " sequence 10", + "remark I am test", + " sequence 20", + "permit tcp any any sequence 30", + "permit udp any any sequence 40", + "remark I am new set of ipv6 ace", + " sequence 50", + "permit icmp any any sequence 60", + ] + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_acls_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( @@ -234,19 +541,22 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_replaced(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 ip access-list standard test_acl remark remark check 1 remark some random remark 2 """, ) - + self.execute_show_command_name.return_value = dedent( + """\ + Standard IP access list test_acl + """, + ) set_module_args( dict( config=[ @@ -259,7 +569,7 @@ class TestIosAclsModule(TestIosModule): aces=[ dict( grant="deny", - protocol_options=dict(tcp=dict(ack="true")), + protocol_options=dict(tcp=dict(ack="True")), source=dict( address="198.51.100.0", wildcard_bits="0.0.0.255", @@ -289,26 +599,30 @@ class TestIosAclsModule(TestIosModule): "ip access-list extended replace_acl", "deny tcp 198.51.100.0 0.0.0.255 198.51.101.0 0.0.0.255 eq telnet ack tos min-monetary-cost", "ip access-list standard test_acl", - "remark Another remark here", "no remark remark check 1", "no remark some random remark 2", + "remark Another remark here", ] self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_ios_acls_replaced_idempotent(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 - Extended IP access list test_pre + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 + ip access-list extended test_pre 10 permit ip any any precedence internet + ip access-list extended test-idem + 10 permit ip host 10.153.14.21 any + 20 permit ip host 10.153.14.22 any """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -328,7 +642,7 @@ class TestIosAclsModule(TestIosModule): "wildcard_bits": "0.0.0.255", }, "destination": {"any": True, "port_protocol": {"eq": "22"}}, - "log": {"user_cookie": "testLog"}, + "log": {"set": True, "user_cookie": "testLog"}, }, { "sequence": 20, @@ -359,6 +673,26 @@ class TestIosAclsModule(TestIosModule): }, {"name": "test_acl", "acl_type": "standard"}, { + "aces": [ + { + "destination": {"any": True}, + "grant": "permit", + "protocol_options": {"ip": True}, + "sequence": 10, + "source": {"host": "10.153.14.21"}, + }, + { + "destination": {"any": True}, + "grant": "permit", + "protocol_options": {"ip": True}, + "sequence": 20, + "source": {"host": "10.153.14.22"}, + }, + ], + "acl_type": "extended", + "name": "test-idem", + }, + { "name": "test_pre", "acl_type": "extended", "aces": [ @@ -406,15 +740,16 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_overridden(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -426,7 +761,7 @@ class TestIosAclsModule(TestIosModule): aces=[ dict( grant="deny", - protocol_options=dict(tcp=dict(syn="true")), + protocol_options=dict(tcp=dict(syn="True")), source=dict( address="198.51.100.0", wildcard_bits="0.0.0.255", @@ -461,17 +796,21 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_overridden_idempotent(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - Reflexive IP access list MIRROR + ip access-list reflexive MIRROR permit tcp host 0.0.0.0 eq 22 host 192.168.0.1 eq 50200 (2 matches) (time left 123) permit tcp host 0.0.0.0 eq 22 host 192.168.0.1 eq 50201 (2 matches) (time left 345) permit tcp host 0.0.0.0 eq 22 host 192.168.0.1 eq 50202 (2 matches) (time left 678) - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 + """, + ) + self.execute_show_command_name.return_value = dedent( + """\ + Standard IP access list test_acl """, ) set_module_args( @@ -493,7 +832,7 @@ class TestIosAclsModule(TestIosModule): "wildcard_bits": "0.0.0.255", }, "destination": {"any": True, "port_protocol": {"eq": "22"}}, - "log": {"user_cookie": "testLog"}, + "log": {"set": True, "user_cookie": "testLog"}, }, { "sequence": 20, @@ -558,15 +897,16 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_deleted_afi_based(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args(dict(config=[dict(afi="ipv4")], state="deleted")) result = self.execute_module(changed=True) commands = ["no ip access-list extended 110", "no ip access-list standard test_acl"] @@ -575,15 +915,16 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_deleted_acl_based(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - IPv6 access list R1_TRAFFIC - deny tcp any eq www any eq telnet ack dscp af11 sequence 10 + ipv6 access-list R1_TRAFFIC + sequence 10 deny tcp any eq www any eq telnet ack dscp af11 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -595,7 +936,7 @@ class TestIosAclsModule(TestIosModule): aces=[ dict( grant="deny", - protocol_options=dict(icmp=dict(echo="true")), + protocol_options=dict(icmp=dict(echo="True")), sequence="10", source=dict(address="192.0.2.0", wildcard_bits="0.0.0.255"), destination=dict( @@ -617,11 +958,11 @@ class TestIosAclsModule(TestIosModule): aces=[ dict( grant="deny", - protocol_options=dict(tcp=dict(ack="true")), + protocol_options=dict(tcp=dict(ack="True")), sequence="10", - source=dict(any="true", port_protocol=dict(eq="www")), + source=dict(any="True", port_protocol=dict(eq="www")), destination=dict( - any="true", + any="True", port_protocol=dict(eq="telnet"), ), dscp="af11", @@ -639,6 +980,7 @@ class TestIosAclsModule(TestIosModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_ios_acls_rendered(self): + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -653,7 +995,7 @@ class TestIosAclsModule(TestIosModule): grant="deny", sequence="10", remarks=["check for remark", "remark for acl 110"], - protocol_options=dict(tcp=dict(syn="true")), + protocol_options=dict(tcp=dict(syn="True")), source=dict(address="192.0.2.0", wildcard_bits="0.0.0.255"), destination=dict( address="192.0.3.0", @@ -681,9 +1023,10 @@ class TestIosAclsModule(TestIosModule): self.assertEqual(sorted(result["rendered"]), sorted(commands)) def test_ios_acls_parsed(self): + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( - running_config="""IPv6 access list R1_TRAFFIC\n deny tcp any eq www any range 10 20 ack dscp af11 sequence 10 + running_config="""ipv6 access-list R1_TRAFFIC\n sequence 10 deny tcp any eq www any range 10 20 ack dscp af11 20 permit icmp host 192.0.2.1 host 192.0.2.2 echo\n 30 permit icmp host 192.0.2.3 host 192.0.2.4 echo-reply""", state="parsed", ), @@ -732,9 +1075,10 @@ class TestIosAclsModule(TestIosModule): self.assertEqual(parsed_list, result["parsed"]) def test_ios_acls_parsed_matches(self): + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( - running_config="""Standard IP access list R1_TRAFFIC\n10 permit 10.11.12.13 (2 matches)\n + running_config="""ip access-list standard R1_TRAFFIC\n10 permit 10.11.12.13 (2 matches)\n 40 permit 128.0.0.0, wildcard bits 63.255.255.255 (2 matches)\n60 permit 134.107.136.0, wildcard bits 0.0.0.255 (1 match)""", state="parsed", ), @@ -752,18 +1096,12 @@ class TestIosAclsModule(TestIosModule): { "sequence": 40, "grant": "permit", - "source": { - "address": "128.0.0.0", - "wildcard_bits": "63.255.255.255", - }, + "protocol_options": {"protocol_number": 128}, }, { - "grant": "permit", "sequence": 60, - "source": { - "address": "134.107.136.0", - "wildcard_bits": "0.0.0.255", - }, + "grant": "permit", + "protocol_options": {"protocol_number": 134}, }, ], }, @@ -775,15 +1113,16 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_overridden_remark(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl - Extended IP access list 110 + ip access-list standard test_acl + ip access-list extended 110 10 permit tcp 198.51.100.0 0.0.0.255 any eq 22 log (tag = testLog) 20 deny icmp 192.0.2.0 0.0.0.255 192.0.3.0 0.0.0.255 echo dscp ef ttl eq 10 30 deny icmp object-group test_network_og any dscp ef ttl eq 10 - access-list 110 remark test ab. - access-list 110 remark test again ab. + remark test ab. + remark test again ab. """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -814,12 +1153,12 @@ class TestIosAclsModule(TestIosModule): def test_ios_acls_overridden_option(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl ip access-list standard test_acl remark remark check 1 remark some random remark 2 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( @@ -833,7 +1172,7 @@ class TestIosAclsModule(TestIosModule): aces=[ dict( grant="deny", - protocol_options=dict(tcp=dict(ack="true")), + protocol_options=dict(tcp=dict(ack="True")), source=dict( address="198.51.100.0", wildcard_bits="0.0.0.255", @@ -918,6 +1257,7 @@ class TestIosAclsModule(TestIosModule): """\ """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( @@ -983,12 +1323,13 @@ class TestIosAclsModule(TestIosModule): def test_ios_delete_acl(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list 2 + ip access-list standard 2 30 permit 172.16.1.11 20 permit 172.16.1.10 log 10 permit 172.16.1.2 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -1019,12 +1360,13 @@ class TestIosAclsModule(TestIosModule): def test_ios_failed_extra_param_standard_acl(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl + ip access-list standard test_acl ip access-list standard test_acl remark remark check 1 remark some random remark 2 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( @@ -1059,12 +1401,13 @@ class TestIosAclsModule(TestIosModule): def test_ios_failed_update_with_merged(self): self.execute_show_command.return_value = dedent( """\ - Standard IP access list test_acl + ip access-list standard test_acl 30 permit 172.16.1.11 20 permit 172.16.1.10 log 10 permit 172.16.1.2 """, ) + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ @@ -1098,15 +1441,16 @@ class TestIosAclsModule(TestIosModule): ) def test_ios_acls_parsed_multioption(self): + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( running_config=dedent( """\ - Standard IP access list 2 + ip access-list standard 2 30 permit 172.16.1.11 20 permit 172.16.1.10 10 permit 172.16.1.2 - Extended IP access list 101 + ip access-list extended 101 15 permit tcp any host 172.16.2.9 18 permit tcp any host 172.16.2.11 20 permit udp host 172.16.1.21 any @@ -1115,17 +1459,13 @@ class TestIosAclsModule(TestIosModule): 50 permit ip any 10.1.1.0 0.0.0.255 60 permit tcp any host 10.1.1.1 eq telnet 70 permit tcp 10.1.1.0 0.0.0.255 172.16.1.0 0.0.0.255 eq telnet time-range EVERYOTHERDAY (active) - Extended IP access list outboundfilters + ip access-list extended outboundfilters 10 permit icmp 10.1.1.0 0.0.0.255 172.16.1.0 0.0.0.255 - Extended IP access list test + ip access-list extended test 10 permit ip host 10.2.2.2 host 10.3.3.3 20 permit tcp host 10.1.1.1 host 10.5.5.5 eq www 30 permit icmp any any 40 permit udp host 10.6.6.6 10.10.10.0 0.0.0.255 eq domain - Extended MAC access list system-cpp-bpdu-range - permit any 0180.c200.0000 0000.0000.0003 - Extended MAC access list system-cpp-cdp - permit any host 0100.0ccc.cccc """, ), state="parsed", @@ -1282,6 +1622,7 @@ class TestIosAclsModule(TestIosModule): self.assertEqual(parsed_list, result["parsed"]) def test_ios_acls_rendered_muiltioption(self): + self.execute_show_command_name.return_value = dedent("") set_module_args( dict( config=[ diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py index 3bd293925..259da5ece 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_address_family.py @@ -23,33 +23,12 @@ class TestIosBgpAddressFamilyModule(TestIosModule): def setUp(self): super(TestIosBgpAddressFamilyModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.bgp_address_family.bgp_address_family." "Bgp_address_familyFacts.get_bgp_address_family_data", @@ -58,11 +37,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): def tearDown(self): super(TestIosBgpAddressFamilyModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_bgp_address_family_merged(self): @@ -143,7 +118,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): neighbors=[ dict( neighbor_address="198.51.100.1", - remote_as=65100, + remote_as="65.11", route_maps=[dict(name="test-route-out", out="true")], prefix_lists=[dict(name="AS65100-PREFIX-OUT", out="true")], ), @@ -169,7 +144,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): "bgp aggregate-timer 20", "bgp dmzlink-bw", "bgp scan-time 10", - "neighbor 198.51.100.1 remote-as 65100", + "neighbor 198.51.100.1 remote-as 65.11", "neighbor 198.51.100.1 route-map test-route-out out", "network 192.0.1.1 route-map test_route", "default-metric 10", @@ -253,7 +228,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): network 198.51.110.10 mask 255.255.255.255 backdoor aggregate-address 192.0.2.1 255.255.255.255 as-confed-set neighbor 198.51.100.1 remote-as 10 - neighbor 198.51.100.1 local-as 20 + neighbor 198.51.100.1 local-as 10.64760 neighbor 198.51.100.1 activate neighbor 198.51.100.1 next-hop-self all neighbor 198.51.100.1 aigp send cost-community 100 poi igp-cost transitive @@ -346,7 +321,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): }, }, }, - "local_as": {"number": 20, "set": True}, + "local_as": {"number": "10.64760", "set": True}, "neighbor_address": "198.51.100.1", "nexthop_self": {"all": True}, "prefix_lists": [{"name": "AS65100-PREFIX-OUT", "out": True}], @@ -796,7 +771,7 @@ class TestIosBgpAddressFamilyModule(TestIosModule): ), ) - result = self.execute_module(changed=False, commands=[]) + self.execute_module(changed=False, commands=[]) def test_ios_bgp_address_family_deleted(self): self.execute_show_command.return_value = dedent( @@ -1188,8 +1163,8 @@ class TestIosBgpAddressFamilyModule(TestIosModule): ], "neighbors": [ { - "remote_as": 10, - "local_as": {"set": True, "number": 20}, + "remote_as": "10", + "local_as": {"set": True, "number": "20"}, "activate": True, "neighbor_address": "198.51.100.1", "nexthop_self": {"all": True}, diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py index 35fe1dd2d..95aa8d8e9 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_bgp_global.py @@ -23,33 +23,12 @@ class TestIosBgpGlobalModule(TestIosModule): def setUp(self): super(TestIosBgpGlobalModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.bgp_global.bgp_global." "Bgp_globalFacts.get_bgp_global_data", @@ -58,11 +37,7 @@ class TestIosBgpGlobalModule(TestIosModule): def tearDown(self): super(TestIosBgpGlobalModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_bgp_global_merged(self): @@ -343,7 +318,6 @@ class TestIosBgpGlobalModule(TestIosModule): state="merged", ), ) - # self.assertEqual(sorted(result["commands"]), sorted(commands)) with self.assertRaises(AnsibleFailJson) as error: self.execute_module(changed=False, commands=[]) self.assertIn( @@ -351,6 +325,62 @@ class TestIosBgpGlobalModule(TestIosModule): str(error.exception), ) + def test_ios_bgp_global_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + router bgp 65000 + bgp nopeerup-delay post-boot 10 + bgp bestpath compare-routerid + bgp advertise-best-external + aggregate-address 192.168.0.11 255.255.0.0 attribute-map map1 + timers bgp 100 200 150 + redistribute connected metric 10 + neighbor 192.0.2.2 remote-as 100 + neighbor 192.0.2.2 route-map test-route out + address-family ipv4 + neighbor 192.0.2.28 activate + neighbor 172.31.35.140 activate + """, + ) + set_module_args( + dict( + config=dict( + as_number="65000", + aggregate_address=dict( + dict(address="192.168.0.11", attribute_map="map1", netmask="255.255.0.0"), + ), + aggregate_addresses=[ + dict(address="192.168.0.1", attribute_map="map", netmask="255.255.0.0"), + dict(address="192.168.0.2", attribute_map="map2", netmask="255.255.0.0"), + ], + bgp=dict( + advertise_best_external=True, + bestpath_options=dict(compare_routerid=True), + log_neighbor_changes=True, + nopeerup_delay_options=dict(cold_boot=20, post_boot=10), + ), + redistribute=[dict(connected=dict(set=True, metric=10))], + neighbors=[ + dict(address="192.0.2.1", remote_as=200, description="replace neighbor"), + ], + ), + state="overridden", + ), + ) + commands = [ + "router bgp 65000", + "no timers bgp 100 200 150", + "bgp log-neighbor-changes", + "bgp nopeerup-delay cold-boot 20", + "aggregate-address 192.168.0.1 255.255.0.0 attribute-map map", + "aggregate-address 192.168.0.2 255.255.0.0 attribute-map map2", + "neighbor 192.0.2.1 remote-as 200", + "neighbor 192.0.2.1 description replace neighbor", + "no neighbor 192.0.2.2", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + def test_ios_bgp_global_replaced(self): self.execute_show_command.return_value = dedent( """\ diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py index fb8188b41..778bb1ccb 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_config.py @@ -200,6 +200,15 @@ class TestIosConfigModule(TestIosModule): commands = parents + lines self.execute_module(changed=True, commands=commands) + def test_ios_config_replace_block_src(self): + src = load_fixture("ios_config_src.cfg") + set_module_args(dict(src=src, replace="block")) + self.conn.get_diff = MagicMock( + return_value=self.cliconf_obj.get_diff(src, self.running_config), + ) + commands = ["hostname foo", "interface GigabitEthernet0/0", "no ip address"] + self.execute_module(changed=True, commands=commands) + def test_ios_config_match_none(self): lines = ["hostname router"] set_module_args(dict(lines=lines, match="none")) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py new file mode 100644 index 000000000..94008b0aa --- /dev/null +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_evi.py @@ -0,0 +1,418 @@ +# +# (c) 2021, Ansible by Red Hat, inc +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.ios.plugins.modules import ios_evpn_evi +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args + +from .ios_module import TestIosModule + + +class TestIosEvpnEviModule(TestIosModule): + module = ios_evpn_evi + + def setUp(self): + super(TestIosEvpnEviModule, self).setUp() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.evpn_evi.evpn_evi." + "Evpn_eviFacts.get_evpn_evi_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosEvpnEviModule, self).tearDown() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_ios_evpn_evi_merged(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + ! + l2vpn evpn instance 201 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type ingress + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "route_distinguisher": "1:1", + "default_gateway": { + "advertise": {"enable": False}, + }, + "ip": { + "local_learning": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "static", + "default_gateway": { + "advertise": {"enable": True}, + }, + "ip": { + "local_learning": {"disable": True}, + }, + }, + ], + state="merged", + ), + ) + commands = [ + "l2vpn evpn instance 101 vlan-based", + "ip local-learning enable", + "replication-type ingress", + "rd 1:1", + "l2vpn evpn instance 202 vlan-based", + "default-gateway advertise enable", + "ip local-learning disable", + "replication-type static", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + rd 1:1 + replication-type ingress + ip local-learning enable + ! + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + ! + l2vpn evpn instance 201 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type static + ip local-learning disable + default-gateway advertise enable + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "route_distinguisher": "1:1", + "default_gateway": { + "advertise": {"enable": False}, + }, + "ip": { + "local_learning": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "static", + "default_gateway": { + "advertise": {"enable": True}, + }, + "ip": { + "local_learning": {"disable": True}, + }, + }, + ], + state="merged", + ), + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_deleted_evi(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type static + default-gateway advertise enable + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + }, + ], + state="deleted", + ), + ) + commands = [ + "no l2vpn evpn instance 101 vlan-based", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_ospf_interfaces_deleted_all(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type static + default-gateway advertise enable + """, + ) + set_module_args(dict(config=[], state="deleted")) + commands = [ + "no l2vpn evpn instance 101 vlan-based", + "no l2vpn evpn instance 102 vlan-based", + "no l2vpn evpn instance 202 vlan-based", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_deleted_blank(self): + self.execute_show_command.return_value = dedent( + """\ + """, + ) + set_module_args(dict(config=list(), state="deleted")) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_replaced(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + rd 1:1 + replication-type ingress + ip local-learning enable + ! + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + ! + l2vpn evpn instance 201 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type static + ip local-learning disable + default-gateway advertise enable + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "ingress", + }, + ], + state="replaced", + ), + ) + commands = [ + "l2vpn evpn instance 101 vlan-based", + "default-gateway advertise enable", + "no ip local-learning enable", + "no rd 1:1", + "l2vpn evpn instance 202 vlan-based", + "no default-gateway advertise enable", + "no ip local-learning disable", + "replication-type ingress", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_replaced_idempotent(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable + ! + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + ! + l2vpn evpn instance 201 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type ingress + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "ingress", + }, + ], + state="replaced", + ), + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_overridden(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable + ! + l2vpn evpn instance 102 vlan-based + encapsulation vxlan + replication-type ingress + ! + l2vpn evpn instance 201 vlan-based + encapsulation vxlan + replication-type static + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type ingress + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "static", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + ], + state="overridden", + ), + ) + commands = [ + "no l2vpn evpn instance 102 vlan-based", + "no l2vpn evpn instance 201 vlan-based", + "l2vpn evpn instance 202 vlan-based", + "default-gateway advertise enable", + "replication-type static", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_evi_overridden_idempotent(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn instance 101 vlan-based + encapsulation vxlan + replication-type ingress + default-gateway advertise enable + ! + l2vpn evpn instance 202 vlan-based + encapsulation vxlan + replication-type static + default-gateway advertise enable + """, + ) + set_module_args( + dict( + config=[ + { + "evi": "101", + "replication_type": "ingress", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + { + "evi": "202", + "replication_type": "static", + "default_gateway": { + "advertise": {"enable": True}, + }, + }, + ], + state="overridden", + ), + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py new file mode 100644 index 000000000..d3bfa1585 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_evpn_global.py @@ -0,0 +1,185 @@ +# +# (c) 2023 Red Hat +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.ios.plugins.modules import ios_evpn_global +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args + +from .ios_module import TestIosModule + + +class TestIosEvpnGlobalModule(TestIosModule): + module = ios_evpn_global + + def setUp(self): + super(TestIosEvpnGlobalModule, self).setUp() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.evpn_global.evpn_global." + "Evpn_globalFacts.get_evpn_global_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosEvpnGlobalModule, self).tearDown() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_ios_evpn_global_merged(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn + replication-type static + router-id Loopback1 + default-gateway advertise + """, + ) + set_module_args( + dict( + config=dict( + replication_type="ingress", + route_target=dict(auto=dict(vni=True)), + default_gateway=dict(advertise=False), + ip=dict(local_learning=dict(disable=True)), + flooding_suppression=dict(address_resolution=dict(disable=False)), + ), + state="merged", + ), + ) + commands = [ + "l2vpn evpn", + "no default-gateway advertise", + "replication-type ingress", + "route-target auto vni", + "ip local-learning disable", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_global_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn + replication-type ingress + router-id Loopback1 + ip local-learning disable + route-target auto vni + """, + ) + set_module_args( + dict( + config=dict( + replication_type="ingress", + route_target=dict(auto=dict(vni=True)), + default_gateway=dict(advertise=False), + ip=dict(local_learning=dict(disable=True)), + flooding_suppression=dict(address_resolution=dict(disable=False)), + ), + state="merged", + ), + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_global_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn + replication-type static + flooding-suppression address-resolution disable + router-id Loopback2 + default-gateway advertise + """, + ) + set_module_args(dict(config=dict(), state="deleted")) + commands = [ + "no l2vpn evpn", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_global_deleted_blank(self): + self.execute_show_command.return_value = dedent( + """\ + """, + ) + set_module_args(dict(config=dict(), state="deleted")) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_global_replaced_overridden(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn + replication-type ingress + router-id Loopback1 + ip local-learning disable + route-target auto vni + """, + ) + set_module_args( + dict( + config=dict( + replication_type="static", + router_id="Loopback2", + default_gateway=dict(advertise=True), + flooding_suppression=dict(address_resolution=dict(disable=True)), + ), + state="replaced", + ), + ) + commands = [ + "l2vpn evpn", + "default-gateway advertise", + "flooding-suppression address-resolution disable", + "no ip local-learning disable", + "replication-type static", + "no route-target auto vni", + "router-id Loopback2", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) + + def test_ios_evpn_global_replaced_overridden_idempotent(self): + """both the replaced and overridden states are supported to have same behaviour""" + self.execute_show_command.return_value = dedent( + """\ + l2vpn evpn + replication-type static + flooding-suppression address-resolution disable + router-id Loopback2 + default-gateway advertise + """, + ) + set_module_args( + dict( + config=dict( + replication_type="static", + router_id="Loopback2", + default_gateway=dict(advertise=True), + flooding_suppression=dict(address_resolution=dict(disable=True)), + ), + state="overridden", + ), + ) + commands = [] + result = self.execute_module(changed=False) + self.assertEqual(sorted(result["commands"]), sorted(commands)) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py index 09dd1a899..a99d7f011 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_facts.py @@ -119,13 +119,29 @@ class TestIosFactsModule(TestIosModule): def test_ios_facts_filesystems_info(self): set_module_args(dict(gather_subset="hardware")) result = self.execute_module() + cpu_utilization_data = { + "core": { + "five_seconds": 3, + "one_minute": 1, + "five_minutes": 5, + "five_seconds_interrupt": 2, + }, + "core_0": {"five_seconds": 4, "one_minute": 0, "five_minutes": 3}, + "core_1": {"five_seconds": 5, "one_minute": 5, "five_minutes": 3}, + } + net_filesystem_data = { + "bootflash:": {"spacetotal_kb": 5062272.0, "spacefree_kb": 3915964.0}, + "flash:": {"spacetotal_kb": 4085709.5, "spacefree_kb": 3915964.0}, + "flash1:": {"spacetotal_kb": 6038834.5, "spacefree_kb": 3915938.609375}, + } + self.assertEqual( - result["ansible_facts"]["ansible_net_filesystems_info"]["bootflash:"]["spacetotal_kb"], - 7712692.0, + result["ansible_facts"]["ansible_net_filesystems_info"], + net_filesystem_data, ) self.assertEqual( - result["ansible_facts"]["ansible_net_filesystems_info"]["bootflash:"]["spacefree_kb"], - 6453180.0, + result["ansible_facts"]["ansible_net_cpu_utilization"], + cpu_utilization_data, ) def test_ios_facts_memory_info(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py index 858ad343d..6b16bddf0 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_hostname.py @@ -23,33 +23,12 @@ class TestIosHostnameModule(TestIosModule): def setUp(self): super(TestIosHostnameModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.hostname.hostname." "HostnameFacts.get_hostname_data", @@ -58,11 +37,7 @@ class TestIosHostnameModule(TestIosModule): def tearDown(self): super(TestIosHostnameModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_hostname_merged_idempotent(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py index 368067b4b..caac40ccb 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_interfaces.py @@ -23,33 +23,12 @@ class TestIosInterfacesModule(TestIosModule): def setUp(self): super(TestIosInterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.interfaces.interfaces." "InterfacesFacts.get_interfaces_data", @@ -58,11 +37,7 @@ class TestIosInterfacesModule(TestIosModule): def tearDown(self): super(TestIosInterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_interfaces_merged(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py index 47bcced6e..d9ec2b189 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l2_interfaces.py @@ -23,33 +23,12 @@ class TestIosL2InterfacesModule(TestIosModule): def setUp(self): super(TestIosL2InterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.l2_interfaces.l2_interfaces." "L2_interfacesFacts.get_l2_interfaces_data", @@ -58,11 +37,7 @@ class TestIosL2InterfacesModule(TestIosModule): def tearDown(self): super(TestIosL2InterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_l2_interfaces_merged(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py index e020f4fdd..de9442b59 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_l3_interfaces.py @@ -23,33 +23,12 @@ class TestIosL3InterfacesModule(TestIosModule): def setUp(self): super(TestIosL3InterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.l3_interfaces.l3_interfaces." "L3_InterfacesFacts.get_l3_interfaces_data", @@ -58,11 +37,7 @@ class TestIosL3InterfacesModule(TestIosModule): def tearDown(self): super(TestIosL3InterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_l3_interfaces_merged_common_ip(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py index a5b46c916..6c56406e6 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp.py @@ -111,6 +111,22 @@ class TestIosLacpModule(TestIosModule): result = self.execute_module(changed=True) self.assertEqual(result["commands"], commands) + def test_ios_lacp_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + 123, 5e00.0000.8000 + """, + ) + set_module_args( + dict( + config={"system": {"priority": 12300}}, + state="overridden", + ), + ) + commands = ["lacp system-priority 12300"] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + def test_ios_lacp_deleted(self): self.execute_show_command.return_value = dedent( """\ diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py index 2be548564..f58aa9d65 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lacp_interfaces.py @@ -49,7 +49,6 @@ class TestIosLacpInterfaceModule(TestIosModule): "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", ) self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.lacp_interfaces.lacp_interfaces." "Lacp_InterfacesFacts.get_lacp_interface_data", diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py index 74301348d..1f97bef24 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lag_interfaces.py @@ -23,33 +23,12 @@ class TestIosLagInterfacesModule(TestIosModule): def setUp(self): super(TestIosLagInterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.lag_interfaces.lag_interfaces." "Lag_interfacesFacts.get_lag_interfaces_data", @@ -58,11 +37,7 @@ class TestIosLagInterfacesModule(TestIosModule): def tearDown(self): super(TestIosLagInterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_lag_interfaces_merged(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py index dd67f0608..4c54ef5c9 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_lldp_global.py @@ -120,6 +120,25 @@ class TestIosLldpGlobalModule(TestIosModule): result = self.execute_module(changed=True) self.assertEqual(result["commands"], commands) + def test_ios_lldp_global_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + lldp timer 10 + lldp holdtime 10 + lldp reinit 3 + lldp run + """, + ) + set_module_args( + dict( + config={"timer": 15, "reinit": 9}, + state="overridden", + ), + ) + commands = ["no lldp holdtime", "no lldp run", "lldp timer 15", "lldp reinit 9"] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + def test_ios_lldp_global_deleted(self): self.execute_show_command.return_value = dedent( """\ diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py deleted file mode 100644 index 26278952a..000000000 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging.py +++ /dev/null @@ -1,153 +0,0 @@ -# -# (c) 2016 Red Hat Inc. -# (c) 2017 Paul Neumann -# -# 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.cisco.ios.plugins.modules import ios_logging -from ansible_collections.cisco.ios.tests.unit.compat.mock import patch -from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args - -from .ios_module import TestIosModule, load_fixture - - -class TestIosLoggingModule(TestIosModule): - module = ios_logging - - def setUp(self): - super(TestIosLoggingModule, self).setUp() - - self.mock_get_config = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_capabilities = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_capabilities", - ) - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = {"device_info": {"network_os_version": "15.6(2)T"}} - - def tearDown(self): - super(TestIosLoggingModule, self).tearDown() - - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_get_capabilities.stop() - - def load_fixtures(self, commands=None): - self.get_config.return_value = load_fixture("ios_logging_config.cfg") - self.load_config.return_value = None - - def test_ios_logging_buffer_size_changed_implicit(self): - set_module_args(dict(dest="buffered")) - commands = ["logging buffered 4096"] - self.execute_module(changed=True, commands=commands) - - def test_ios_logging_buffer_size_changed_explicit(self): - set_module_args(dict(dest="buffered", size=6000)) - commands = ["logging buffered 6000"] - self.execute_module(changed=True, commands=commands) - - def test_ios_logging_add_host(self): - set_module_args(dict(dest="host", name="192.168.1.1")) - commands = ["logging host 192.168.1.1"] - self.execute_module(changed=True, commands=commands) - - def test_ios_logging_host_idempotent(self): - set_module_args(dict(dest="host", name="2.3.4.5")) - commands = [] - self.execute_module(changed=False, commands=commands) - - def test_ios_logging_delete_non_exist_host(self): - set_module_args(dict(dest="host", name="192.168.1.1", state="absent")) - commands = [] - self.execute_module(changed=False, commands=commands) - - def test_ios_logging_delete_host(self): - set_module_args(dict(dest="host", name="2.3.4.5", state="absent")) - commands = ["no logging host 2.3.4.5"] - self.execute_module(changed=True, commands=commands) - - def test_ios_logging_configure_disabled_monitor_destination(self): - set_module_args(dict(dest="monitor", level="debugging")) - commands = ["logging monitor debugging"] - self.execute_module(changed=True, commands=commands) - - -class TestIosLoggingModuleIOS12(TestIosModule): - module = ios_logging - - def setUp(self): - super(TestIosLoggingModuleIOS12, self).setUp() - - self.mock_get_config = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_capabilities = patch( - "ansible_collections.cisco.ios.plugins.modules.ios_logging.get_capabilities", - ) - self.get_capabilities = self.mock_get_capabilities.start() - self.get_capabilities.return_value = {"device_info": {"network_os_version": "12.1(2)T"}} - - def tearDown(self): - super(TestIosLoggingModuleIOS12, self).tearDown() - - self.mock_get_config.stop() - self.mock_load_config.stop() - self.mock_get_capabilities.stop() - - def load_fixtures(self, commands=None): - self.get_config.return_value = load_fixture("ios_logging_config_ios12.cfg") - self.load_config.return_value = None - - def test_ios_logging_add_host(self): - set_module_args(dict(dest="host", name="192.168.1.1")) - commands = ["logging 192.168.1.1"] - self.execute_module(changed=True, commands=commands) - - def test_ios_logging_host_idempotent(self): - set_module_args(dict(dest="host", name="2.3.4.5")) - commands = [] - self.execute_module(changed=False, commands=commands) - - def test_ios_logging_delete_non_exist_host(self): - set_module_args(dict(dest="host", name="192.168.1.1", state="absent")) - commands = [] - self.execute_module(changed=False, commands=commands) - - def test_ios_logging_delete_host(self): - set_module_args(dict(dest="host", name="2.3.4.5", state="absent")) - commands = ["no logging 2.3.4.5"] - self.execute_module(changed=True, commands=commands) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py index 6520ebc7a..c3024636a 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_logging_global.py @@ -23,33 +23,12 @@ class TestIosLoggingGlobalModule(TestIosModule): def setUp(self): super(TestIosLoggingGlobalModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.logging_global.logging_global." "Logging_globalFacts.get_logging_data", @@ -58,11 +37,7 @@ class TestIosLoggingGlobalModule(TestIosModule): def tearDown(self): super(TestIosLoggingGlobalModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_logging_global_merged_idempotent(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py index d80b568f4..a9d0392c1 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ntp_global.py @@ -23,33 +23,12 @@ class TestIosNtpGlobalModule(TestIosModule): def setUp(self): super(TestIosNtpGlobalModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ntp_global.ntp_global." "Ntp_globalFacts.get_ntp_data", @@ -58,11 +37,7 @@ class TestIosNtpGlobalModule(TestIosModule): def tearDown(self): super(TestIosNtpGlobalModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_ntp_global_merged_idempotent(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py index fe16e7a18..3721ba3ba 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospf_interfaces.py @@ -23,33 +23,12 @@ class TestIosOspfInterfacesModule(TestIosModule): def setUp(self): super(TestIosOspfInterfacesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospf_interfaces.ospf_interfaces." "Ospf_interfacesFacts.get_ospf_interfaces_data", @@ -58,11 +37,7 @@ class TestIosOspfInterfacesModule(TestIosModule): def tearDown(self): super(TestIosOspfInterfacesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_ospf_interfaces_merged(self): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py index ba6283f4c..b73e34395 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv2.py @@ -8,11 +8,13 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type +from textwrap import dedent + from ansible_collections.cisco.ios.plugins.modules import ios_ospfv2 from ansible_collections.cisco.ios.tests.unit.compat.mock import patch from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args -from .ios_module import TestIosModule, load_fixture +from .ios_module import TestIosModule class TestIosOspfV2Module(TestIosModule): @@ -21,33 +23,12 @@ class TestIosOspfV2Module(TestIosModule): def setUp(self): super(TestIosOspfV2Module, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv2.ospfv2." "Ospfv2Facts.get_ospfv2_data", @@ -56,20 +37,24 @@ class TestIosOspfV2Module(TestIosModule): def tearDown(self): super(TestIosOspfV2Module, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() - def load_fixtures(self, commands=None): - def load_from_file(*args, **kwargs): - return load_fixture("ios_ospfv2.cfg") - - self.execute_show_command.side_effect = load_from_file - def test_ios_ospfv2_merged(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( config=dict( @@ -122,6 +107,20 @@ class TestIosOspfV2Module(TestIosModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_ios_ospfv2_merged_specific_param(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( config={ @@ -143,6 +142,20 @@ class TestIosOspfV2Module(TestIosModule): self.assertEqual(sorted(result["commands"]), sorted(commands)) def test_ios_ospfv2_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( config=dict( @@ -176,25 +189,56 @@ class TestIosOspfV2Module(TestIosModule): self.execute_module(changed=False, commands=[]) def test_ios_ospfv2_replaced(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( - config=dict( - processes=[ - dict( - process_id="200", - auto_cost=dict(reference_bandwidth="4"), - domain_id=dict(ip_address=dict(address="192.0.1.1")), - max_metric=dict(on_startup=dict(time=200), router_lsa=True), - areas=[dict(area_id="10", capability=True)], - vrf="blue", - ), + config={ + "processes": [ + { + "process_id": "200", + "auto_cost": { + "reference_bandwidth": "4", + }, + "domain_id": { + "ip_address": { + "address": "192.0.1.1", + }, + }, + "max_metric": { + "on_startup": { + "time": 200, + }, + "router_lsa": True, + }, + "areas": [ + { + "area_id": "10", + "capability": True, + }, + ], + "vrf": "blue", + }, ], - ), + }, state="replaced", ), ) commands = [ "router ospf 200 vrf blue", + "auto-cost reference-bandwidth 4", "no distribute-list 123 in", "no distribute-list 10 out", "domain-id 192.0.1.1", @@ -203,73 +247,21 @@ class TestIosOspfV2Module(TestIosModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result["commands"]), sorted(commands)) - def test_ios_ospfv2_replaced_idempotent(self): - set_module_args( - dict( - config=dict( - processes=[ - dict( - process_id="200", - auto_cost=dict(reference_bandwidth="4"), - distribute_list=dict( - acls=[ - dict(direction="out", name="10"), - dict(direction="in", name="123"), - ], - ), - domain_id=dict(ip_address=dict(address="192.0.3.1")), - max_metric=dict(on_startup=dict(time=100), router_lsa=True), - areas=[dict(area_id="10", capability=True)], - passive_interfaces=dict( - default=True, - interface=dict( - set_interface=False, - name=["GigabitEthernet0/1", "GigabitEthernet0/2"], - ), - ), - vrf="blue", - ), - ], - ), - state="replaced", - ), - ) - self.execute_module(changed=False, commands=[]) - - def test_ios_ospfv2_overridden_idempotent(self): - set_module_args( - dict( - config=dict( - processes=[ - dict( - process_id="200", - auto_cost=dict(reference_bandwidth="4"), - distribute_list=dict( - acls=[ - dict(direction="out", name="10"), - dict(direction="in", name="123"), - ], - ), - domain_id=dict(ip_address=dict(address="192.0.3.1")), - max_metric=dict(on_startup=dict(time=100), router_lsa=True), - areas=[dict(area_id="10", capability=True)], - passive_interfaces=dict( - default=True, - interface=dict( - set_interface=False, - name=["GigabitEthernet0/1", "GigabitEthernet0/2"], - ), - ), - vrf="blue", - ), - ], - ), - state="overridden", - ), - ) - self.execute_module(changed=False, commands=[]) - def test_ios_ospfv2_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( config={ @@ -318,7 +310,6 @@ class TestIosOspfV2Module(TestIosModule): "ranges": [ { "address": "172.16.1.0", - "advertise": True, "cost": 20, "netmask": "0.0.0.255", "not_advertise": True, @@ -344,14 +335,14 @@ class TestIosOspfV2Module(TestIosModule): "bfd": True, "capability": { "lls": True, - "opaque": True, - "transit": True, - "vrf_lite": True, + "opaque": False, + "transit": False, + "vrf_lite": False, }, "compatible": { "rfc1583": True, - "rfc1587": True, - "rfc5243": True, + "rfc1587": False, + "rfc5243": False, }, "default_information": { "always": True, @@ -400,11 +391,9 @@ class TestIosOspfV2Module(TestIosModule): "limit": { "dc": { "disable": True, - "number": 20, }, "non_dc": { "disable": True, - "number": 10, }, }, "local_rib_criteria": { @@ -436,7 +425,6 @@ class TestIosOspfV2Module(TestIosModule): "area": "area1", "set": True, }, - "sync": True, }, "traffic_eng": { "area": "area12", @@ -479,7 +467,6 @@ class TestIosOspfV2Module(TestIosModule): "strict_lsa_checking": True, }, }, - # "passive_interface": "GigabitEthernet0/1", "passive_interfaces": { "default": True, "interface": { @@ -493,11 +480,9 @@ class TestIosOspfV2Module(TestIosModule): "queue_depth": { "hello": { "max_packets": 10, - "unlimited": True, }, "update": { "max_packets": 30, - "unlimited": True, }, }, "router_id": "router1", @@ -505,7 +490,6 @@ class TestIosOspfV2Module(TestIosModule): "summary_address": { "address": "172.16.1.0", "mask": "0.0.0.255", - "not_advertise": True, "nssa_only": True, "tag": 12, }, @@ -513,8 +497,6 @@ class TestIosOspfV2Module(TestIosModule): "lsa": 12, "pacing": { "flood": 25, - "lsa_group": 15, - "retransmission": 30, }, "throttle": { "lsa": { @@ -542,7 +524,7 @@ class TestIosOspfV2Module(TestIosModule): commands = [ "no router ospf 200 vrf blue", "router ospf 1 vrf vrf1", - "adjacency stagger none 2", + "adjacency stagger none 10", "address-family ipv4 multicast", "topology base", "exit-address-family", @@ -553,47 +535,71 @@ class TestIosOspfV2Module(TestIosModule): "default-information originate always metric 25 metric-type 26 route-map rmap1", "default-metric 50", "discard-route external 5 internal 2", - "domain-id 192.168.1.0 True", + "distance ospf inter-area 2 intra-area 3 external 1", + "domain-id 192.168.1.0 secondary", "domain-tag 54", "event-log one-shot pause size 10", "help", "ignore lsa mospf", "interface-id snmp-if-index", "ispf", - "limit retransmissions dc 20 dc disable non-dc 10 non-dc disable", + "limit retransmissions dc disable non-dc disable", "local-rib-criteria forwarding-address inter-area-summary nssa-translation", "log-adjacency-changes detail", - "max-lsa 10 10 ignore-count 10 ignore-time 10 reset-time 10 warning-only", + "max-lsa 10 10 warning-only", "max-metric router-lsa external-lsa 10 include-stub on-startup 110 summary-lsa 20", "maximum-paths 15", + "mpls ldp autoconfig area area1", + "mpls traffic-eng area area12", "neighbor 172.16.1.0 cost 2 database-filter all out poll-interval 20 priority 10", - "network 198.51.100.0 0.0.0.255 area 5", + "nsf cisco helper disable", + "nsf ietf helper disable", + "nsf ietf helper strict-lsa-checking", "prefix-suppression", "priority 10", + "queue-depth hello 10", + "queue-depth update 30", "router-id router1", "shutdown", - "summary-address 172.16.1.0 0.0.0.255 not-advertise", + "summary-address 172.16.1.0 0.0.0.255 nssa-only tag 12", + "timers pacing flood 25", "traffic-share min across-interfaces", "ttl-security all-interfaces hops 12", "area 5 authentication message-digest", "area 10 authentication message-digest", "area 10 capability default-exclusion", "area 10 default-cost 10", - "area 10 nssa translate type7 suppress-fa", "area 10 nssa default-information-originate metric 10 metric-type 1 nssa-only no-ext-capability no-redistribution no-summary", - "area 10 range 172.16.1.0 0.0.0.255 advertise cost 20", + "area 10 nssa translate type7 suppress-fa", "area 10 sham-link checkSource checkDestination cost 10 ttl-security hops 20", "area 10 stub no-ext-capability no-summary", "area 10 filter-list prefix test_prefix_in in", "area 10 filter-list prefix test_prefix_out out", + "area 10 range 172.16.1.0 0.0.0.255 not-advertise cost 20", + "network 198.51.100.0 0.0.0.255 area 5", "passive-interface default", "no passive-interface GigabitEthernet0/1", "no passive-interface GigabitEthernet0/2", ] result = self.execute_module(changed=True) + self.maxDiff = None self.assertEqual(commands, result["commands"]) def test_ios_ospfv2_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict(config=dict(processes=[dict(process_id="200", vrf="blue")]), state="deleted"), ) @@ -601,6 +607,20 @@ class TestIosOspfV2Module(TestIosModule): self.execute_module(changed=True, commands=commands) def test_ios_ospfv2_parsed(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( running_config="router ospf 1\n area 5 authentication\n area 5 capability default-exclusion", @@ -621,6 +641,20 @@ class TestIosOspfV2Module(TestIosModule): self.assertEqual(parsed_list, result["parsed"]) def test_ios_ospfv2_rendered(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) set_module_args( dict( config={ @@ -672,7 +706,6 @@ class TestIosOspfV2Module(TestIosModule): "advertise": True, "cost": 20, "netmask": "0.0.0.255", - "not_advertise": True, }, ], "sham_link": { @@ -695,14 +728,14 @@ class TestIosOspfV2Module(TestIosModule): "bfd": True, "capability": { "lls": True, - "opaque": True, - "transit": True, - "vrf_lite": True, + "opaque": False, + "transit": False, + "vrf_lite": False, }, "compatible": { "rfc1583": True, - "rfc1587": True, - "rfc5243": True, + "rfc1587": False, + "rfc5243": False, }, "default_information": { "always": True, @@ -771,7 +804,7 @@ class TestIosOspfV2Module(TestIosModule): "number": 10, "reset_time": 10, "threshold_value": 10, - "warning_only": True, + "warning_only": False, }, "max_metric": { "external_lsa": 10, @@ -783,10 +816,6 @@ class TestIosOspfV2Module(TestIosModule): "maximum_paths": 15, "mpls": { "ldp": { - "autoconfig": { - "area": "area1", - "set": True, - }, "sync": True, }, "traffic_eng": { @@ -830,7 +859,6 @@ class TestIosOspfV2Module(TestIosModule): "strict_lsa_checking": True, }, }, - # "passive_interface": "GigabitEthernet0/1", "passive_interfaces": { "default": True, "interface": { @@ -843,11 +871,9 @@ class TestIosOspfV2Module(TestIosModule): "process_id": 1, "queue_depth": { "hello": { - "max_packets": 10, "unlimited": True, }, "update": { - "max_packets": 30, "unlimited": True, }, }, @@ -856,15 +882,12 @@ class TestIosOspfV2Module(TestIosModule): "summary_address": { "address": "172.16.1.0", "mask": "0.0.0.255", - "not_advertise": True, "nssa_only": True, "tag": 12, }, "timers": { "lsa": 12, "pacing": { - "flood": 25, - "lsa_group": 15, "retransmission": 30, }, "throttle": { @@ -891,7 +914,7 @@ class TestIosOspfV2Module(TestIosModule): ) commands = [ "address-family ipv4 multicast", - "adjacency stagger none 2", + "adjacency stagger none 10", "area 10 authentication message-digest", "area 10 capability default-exclusion", "area 10 default-cost 10", @@ -910,7 +933,8 @@ class TestIosOspfV2Module(TestIosModule): "default-information originate always metric 25 metric-type 26 route-map rmap1", "default-metric 50", "discard-route external 5 internal 2", - "domain-id 192.168.1.0 True", + "distance ospf inter-area 2 intra-area 3 external 1", + "domain-id 192.168.1.0 secondary", "domain-tag 54", "event-log one-shot pause size 10", "exit-address-family", @@ -918,26 +942,218 @@ class TestIosOspfV2Module(TestIosModule): "ignore lsa mospf", "interface-id snmp-if-index", "ispf", - "limit retransmissions dc 20 dc disable non-dc 10 non-dc disable", + "limit retransmissions dc 20 non-dc 10", "local-rib-criteria forwarding-address inter-area-summary nssa-translation", "log-adjacency-changes detail", - "max-lsa 10 10 ignore-count 10 ignore-time 10 reset-time 10 warning-only", + "max-lsa 10 10 ignore-count 10 ignore-time 10 reset-time 10", "max-metric router-lsa external-lsa 10 include-stub on-startup 110 summary-lsa 20", "maximum-paths 15", + "mpls ldp sync", + "mpls traffic-eng area area12", "neighbor 172.16.1.0 cost 2 database-filter all out poll-interval 20 priority 10", "network 198.51.100.0 0.0.0.255 area 5", "no passive-interface GigabitEthernet0/1", "no passive-interface GigabitEthernet0/2", + "nsf cisco helper disable", + "nsf ietf helper disable", + "nsf ietf helper strict-lsa-checking", "passive-interface default", "prefix-suppression", "priority 10", + "queue-depth hello unlimited", + "queue-depth update unlimited", "router ospf 1 vrf vrf1", "router-id router1", "shutdown", - "summary-address 172.16.1.0 0.0.0.255 not-advertise", + "summary-address 172.16.1.0 0.0.0.255 nssa-only tag 12", + "timers pacing retransmission 30", "topology base", "traffic-share min across-interfaces", "ttl-security all-interfaces hops 12", ] result = self.execute_module(changed=False) + self.maxDiff = None self.assertEqual(sorted(result["rendered"]), commands) + + def test_ios_ospfv2_overridden_2(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + area 10 filter-list prefix test_prefix_in in + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + router ospf 210 vrf green + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) + + set_module_args( + dict( + config={ + "processes": [ + { + "process_id": 200, + "vrf": "blue", + "auto_cost": {"set": True, "reference_bandwidth": 4}, + "distribute_list": { + "acls": [ + {"name": "110", "direction": "out"}, + {"name": "123", "direction": "in"}, + ], + }, + "queue_depth": { + "hello": { + "unlimited": True, + }, + "update": { + "unlimited": True, + }, + }, + "domain_id": {"null": True}, + "timers": { + "pacing": { + "lsa_group": 25, + }, + }, + "max_metric": {"router_lsa": True, "on_startup": {"time": 100}}, + "areas": [{"area_id": "10", "capability": True}], + "passive_interfaces": { + "default": True, + "interface": { + "set_interface": False, + "name": ["GigabitEthernet0/2", "GigabitEthernet0/1"], + }, + }, + }, + { + "process_id": 210, + "vrf": "green", + "auto_cost": {"set": True, "reference_bandwidth": 5}, + "distribute_list": { + "acls": [ + {"name": "5120", "direction": "out"}, + {"name": "123", "direction": "out"}, + ], + }, + "domain_id": {"ip_address": {"address": "192.0.3.1"}}, + "nsf": { + "ietf": { + "strict_lsa_checking": True, + }, + }, + "mpls": { + "ldp": { + "sync": True, + }, + }, + "timers": { + "pacing": { + "flood": 25, + }, + }, + "max_metric": { + "router_lsa": True, + "on_startup": {"wait_for_bgp": True}, + }, + "areas": [{"area_id": "11", "capability": True}], + "passive_interfaces": { + "default": True, + "interface": { + "set_interface": False, + "name": ["GigabitEthernet0/2"], + }, + }, + }, + ], + }, + state="overridden", + ), + ) + + result = self.execute_module(changed=True) + print(result["commands"]) + commands = [ + "router ospf 200 vrf blue", + "domain-id null", + "queue-depth hello unlimited", + "queue-depth update unlimited", + "timers pacing lsa-group 25", + "no area 10 filter-list prefix test_prefix_in in", + "distribute-list 110 out", + "no distribute-list 10 out", + "router ospf 210 vrf green", + "auto-cost reference-bandwidth 5", + "max-metric router-lsa on-startup wait-for-bgp", + "mpls ldp sync", + "nsf ietf helper strict-lsa-checking", + "timers pacing flood 25", + "area 11 capability default-exclusion", + "no area 10 capability default-exclusion", + "distribute-list 5120 out", + "no distribute-list 123 in", + "distribute-list 123 out", + "no distribute-list 10 out", + "passive-interface GigabitEthernet0/1", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_ospfv2_overridden_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + router ospf 200 vrf blue + auto-cost reference-bandwidth 4 + distribute-list 10 out + distribute-list 123 in + domain-id 192.0.3.1 + max-metric router-lsa on-startup 100 + area 10 capability default-exclusion + passive-interface default + no passive-interface GigabitEthernet0/1 + no passive-interface GigabitEthernet0/2 + """, + ) + set_module_args( + dict( + config=dict( + processes=[ + { + "process_id": 200, + "vrf": "blue", + "auto_cost": {"set": True, "reference_bandwidth": 4}, + "distribute_list": { + "acls": [ + {"name": "10", "direction": "out"}, + {"name": "123", "direction": "in"}, + ], + }, + "domain_id": {"ip_address": {"address": "192.0.3.1"}}, + "max_metric": {"router_lsa": True, "on_startup": {"time": 100}}, + "areas": [{"area_id": "10", "capability": True}], + "passive_interfaces": { + "default": True, + "interface": { + "set_interface": False, + "name": ["GigabitEthernet0/2", "GigabitEthernet0/1"], + }, + }, + }, + ], + ), + state="overridden", + ), + ) + self.execute_module(changed=False, commands=[]) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py index 5403ef25d..30c646123 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ospfv3.py @@ -21,33 +21,12 @@ class TestIosOspfV3Module(TestIosModule): def setUp(self): super(TestIosOspfV3Module, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.ospfv3.ospfv3." "Ospfv3Facts.get_ospfv3_data", @@ -56,11 +35,7 @@ class TestIosOspfV3Module(TestIosModule): def tearDown(self): super(TestIosOspfV3Module, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def load_fixtures(self, commands=None): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py index 7e7035eae..bdb822e62 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_ping.py @@ -87,6 +87,7 @@ class TestIosPingModule(TestIosModule): "afi": "ip", "count": 4, "dest": "8.8.8.8", + "size": 800, "df_bit": True, "source": "Loopback88", "state": "present", @@ -95,7 +96,7 @@ class TestIosPingModule(TestIosModule): ) result = self.execute_module() mock_res = { - "commands": "ping vrf DummyVrf ip 8.8.8.8 repeat 4 df-bit source Loopback88", + "commands": "ping vrf DummyVrf ip 8.8.8.8 repeat 4 df-bit size 800 source Loopback88", "packet_loss": "0%", "packets_rx": 2, "packets_tx": 2, diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py index 29a4f4c24..2aac373dd 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_prefix_lists.py @@ -21,33 +21,12 @@ class TestIosPrefixListsModule(TestIosModule): def setUp(self): super(TestIosPrefixListsModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.prefix_lists.prefix_lists." "Prefix_listsFacts.get_prefix_list_data", @@ -56,11 +35,7 @@ class TestIosPrefixListsModule(TestIosModule): def tearDown(self): super(TestIosPrefixListsModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def load_fixtures(self, commands=None): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py index c0600290c..0e450f908 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_route_maps.py @@ -21,33 +21,12 @@ class TestIosRouteMapsModule(TestIosModule): def setUp(self): super(TestIosRouteMapsModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.route_maps.route_maps." "Route_mapsFacts.get_route_maps_data", @@ -56,11 +35,7 @@ class TestIosRouteMapsModule(TestIosModule): def tearDown(self): super(TestIosRouteMapsModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def load_fixtures(self, commands=None): diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py index b77be44f2..cbf9a9fd7 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_service.py @@ -23,33 +23,12 @@ class TestIosServiceModule(TestIosModule): def setUp(self): super(TestIosServiceModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.service.service." "ServiceFacts.get_service_data", @@ -58,11 +37,7 @@ class TestIosServiceModule(TestIosModule): def tearDown(self): super(TestIosServiceModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_service_merged_idempotent(self): @@ -197,6 +172,62 @@ class TestIosServiceModule(TestIosModule): self.assertEqual(sorted(result["commands"]), sorted(deleted)) + def test_ios_service_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + service call-home + service config + service counters max age 0 + service dhcp + service pad + service password-recovery + service private-config-encryption + service prompt config + service slave-log + service timestamps log datetime msec + """, + ) + playbook = { + "config": { + "timestamps": [ + { + "msg": "log", + "timestamp": "datetime", + "datetime_options": { + "localtime": True, + "msec": True, + "show_timezone": True, + "year": True, + }, + }, + { + "msg": "debug", + "timestamp": "datetime", + }, + ], + "tcp_keepalives_in": True, + "tcp_keepalives_out": True, + "password_encryption": True, + "counters": 5, + }, + } + overridden = [ + "no service call-home", + "no service config", + "no service pad", + "service counters max age 5", + "service password-encryption", + "service tcp-keepalives-in", + "service tcp-keepalives-out", + "service timestamps debug datetime", + "service timestamps log datetime msec localtime show-timezone year", + ] + playbook["state"] = "overridden" + set_module_args(playbook) + result = self.execute_module(changed=True) + + self.assertEqual(sorted(result["commands"]), sorted(overridden)) + def test_ios_service_replaced(self): self.execute_show_command.return_value = dedent( """\ @@ -270,7 +301,48 @@ class TestIosServiceModule(TestIosModule): playbook = { "config": { "call_home": True, - "private_config_encryption": True, + "timestamps": [ + { + "msg": "debug", + "timestamp": "datetime", + "datetime_options": { + "msec": True, + }, + }, + { + "msg": "log", + "timestamp": "datetime", + "datetime_options": { + "msec": True, + }, + }, + ], + }, + } + replaced = [] + playbook["state"] = "replaced" + set_module_args(playbook) + result = self.execute_module(changed=False) + self.maxDiff = None + + self.assertEqual(sorted(result["commands"]), sorted(replaced)) + + def test_ios_service_replaced_idempotent_old(self): + self.execute_show_command.return_value = dedent( + """\ + service slave-log + service timestamps debug datetime msec + service timestamps log datetime msec + service prompt config + service counters max age 0 + service dhcp + service call-home + service password-recovery + """, + ) + playbook = { + "config": { + "call_home": True, "timestamps": [ { "msg": "debug", diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py index e0319bd7b..c45f3548a 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_snmp_server.py @@ -22,34 +22,12 @@ class TestIosSnmpServerModule(TestIosModule): def setUp(self): super(TestIosSnmpServerModule, self).setUp() - - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.snmp_server.snmp_server." "Snmp_serverFacts.get_snmp_data", @@ -65,11 +43,7 @@ class TestIosSnmpServerModule(TestIosModule): def tearDown(self): super(TestIosSnmpServerModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() self.mock_execute_show_command_user.stop() @@ -327,7 +301,9 @@ class TestIosSnmpServerModule(TestIosModule): "ipsla": True, "isis": True, "l2tun": {"pseudowire_status": True, "session": True}, - "mpls_vpn": True, + "mpls": { + "vpn": {"enable": True}, + }, "msdp": True, "mvpn": True, "ospf": { @@ -422,7 +398,7 @@ class TestIosSnmpServerModule(TestIosModule): """\ User name: paul Engine ID: 000000090200000000000A0B - storage-type: nonvolatile active access-list: ipv6 + storage-type: nonvolatile active access-list ipv6: ipv6only Authentication Protocol: MD5 Privacy Protocol: AES128 Group-name: familypaul @@ -598,7 +574,9 @@ class TestIosSnmpServerModule(TestIosModule): "ipsla": True, "isis": True, "l2tun": {"pseudowire_status": True, "session": True}, - "mpls_vpn": True, + "mpls": { + "vpn": {"enable": True}, + }, "msdp": True, "mvpn": True, "ospf": { @@ -643,7 +621,12 @@ class TestIosSnmpServerModule(TestIosModule): }, "users": [ {"acl_v4": "24", "group": "newfamily", "username": "newuser", "version": "v1"}, - {"acl_v4": "ipv6", "group": "familypaul", "username": "paul", "version": "v3"}, + { + "acl_v6": "ipv6only", + "group": "familypaul", + "username": "paul", + "version": "v3", + }, {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, {"acl_v4": "27", "group": "mfamily", "username": "flow", "version": "v3"}, ], @@ -663,7 +646,8 @@ class TestIosSnmpServerModule(TestIosModule): "snmp-server trap-source GigabitEthernet0/0", "snmp-server system-shutdown", "snmp-server enable traps bfd", - "snmp-server enable traps bgp cbgp2 state-changes all backward-trans limited threshold prefix", + "snmp-server enable traps bgp cbgp2", + "snmp-server enable traps bgp state-changes all backward-trans limited threshold prefix", "snmp-server enable traps bridge newroot topologychange", "snmp-server enable traps eigrp", "snmp-server enable traps energywise", @@ -698,11 +682,11 @@ class TestIosSnmpServerModule(TestIosModule): "snmp-server enable traps l2tun pseudowire status", "snmp-server enable traps l2tun session", "snmp-server enable traps pim neighbor-change rp-mapping-change invalid-pim-message", - "snmp-server enable traps snmp authentication linkdown linkup warmstart coldstart", + "snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart", "snmp-server enable traps frame-relay", "snmp-server enable traps cef resource-failure peer-state-change peer-fib-state-change inconsistency", "snmp-server enable traps dlsw", - "snmp-server enable traps ethernet evc create delete status", + "snmp-server enable traps ethernet evc status create delete", "snmp-server host 172.16.2.1 version 2c trapsac tty", "snmp-server host 172.16.1.1 version 3 auth group0 tty", "snmp-server host 172.16.2.99 check slb", @@ -718,8 +702,8 @@ class TestIosSnmpServerModule(TestIosModule): "snmp-server context contextWord2", "snmp-server password-policy policy3 define min-len 12 max-len 12 upper-case 12 special-char 22 digits 23 change 11", "snmp-server user newuser newfamily v1 access 24", - "snmp-server user paul familypaul v3 access ipv6", - "snmp-server user replaceUser replaceUser v3", + "snmp-server user paul familypaul v3 access ipv6 ipv6only", + "snmp-server user replaceUser replaceUser v3 access 22", "snmp-server user flow mfamily v3 access 27", ] playbook["state"] = "merged" @@ -755,65 +739,109 @@ class TestIosSnmpServerModule(TestIosModule): snmp-server contact this is contact string snmp-server chassis-id this is a chassis id string snmp-server system-shutdown - snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart - snmp-server enable traps flowmon - snmp-server enable traps tty - snmp-server enable traps eigrp - snmp-server enable traps casa - snmp-server enable traps ospf state-change - snmp-server enable traps ospf errors - snmp-server enable traps ospf retransmit - snmp-server enable traps ospf lsa - snmp-server enable traps ospf cisco-specific state-change nssa-trans-change - snmp-server enable traps ospf cisco-specific state-change shamlink interface - snmp-server enable traps ospf cisco-specific state-change shamlink neighbor - snmp-server enable traps ospf cisco-specific errors - snmp-server enable traps ospf cisco-specific retransmit - snmp-server enable traps ospf cisco-specific lsa - snmp-server enable traps ethernet cfm cc mep-up mep-down cross-connect loop config - snmp-server enable traps ethernet cfm crosscheck mep-missing mep-unknown service-up + snmp-server enable traps aaa_server snmp-server enable traps auth-framework sec-violation + snmp-server enable traps bfd + snmp-server enable traps bgp + snmp-server enable traps bgp cbgp2 + snmp-server enable traps bridge newroot topologychange + snmp-server enable traps bulkstat collection transfer + snmp-server enable traps call-home message-send-fail server-fail + snmp-server enable traps cef resource-failure peer-state-change peer-fib-state-change inconsistency + snmp-server enable traps config + snmp-server enable traps config-copy + snmp-server enable traps config-ctid + snmp-server enable traps cpu threshold + snmp-server enable traps dhcp + snmp-server enable traps eigrp snmp-server enable traps energywise - snmp-server enable traps pw vc - snmp-server enable traps l2tun session - snmp-server enable traps l2tun pseudowire status + snmp-server enable traps entity + snmp-server enable traps entity-diag boot-up-fail hm-test-recover hm-thresh-reached scheduled-test-fail + snmp-server enable traps entity-perf throughput-notif + snmp-server enable traps entity-state + snmp-server enable traps envmon fan shutdown supply temperature status + snmp-server enable traps errdisable snmp-server enable traps ether-oam + snmp-server enable traps ethernet cfm alarm + snmp-server enable traps ethernet cfm cc mep-up mep-down cross-connect loop config + snmp-server enable traps ethernet cfm crosscheck mep-missing mep-unknown service-up snmp-server enable traps ethernet evc status create delete - snmp-server enable traps bridge newroot topologychange - snmp-server enable traps vtp + snmp-server enable traps event-manager + snmp-server enable traps flash insertion removal lowspace + snmp-server enable traps flex-links status + snmp-server enable traps flowmon + snmp-server enable traps fru-ctrl + snmp-server enable traps hsrp snmp-server enable traps ike policy add snmp-server enable traps ike policy delete snmp-server enable traps ike tunnel start snmp-server enable traps ike tunnel stop + snmp-server enable traps ipmulticast snmp-server enable traps ipsec cryptomap add - snmp-server enable traps ipsec cryptomap delete snmp-server enable traps ipsec cryptomap attach + snmp-server enable traps ipsec cryptomap delete snmp-server enable traps ipsec cryptomap detach + snmp-server enable traps ipsec too-many-sas snmp-server enable traps ipsec tunnel start snmp-server enable traps ipsec tunnel stop - snmp-server enable traps ipsec too-many-sas - snmp-server enable traps bfd - snmp-server enable traps bgp - snmp-server enable traps bgp cbgp2 - snmp-server enable traps cef resource-failure peer-state-change peer-fib-state-change inconsistency - snmp-server enable traps dlsw - snmp-server enable traps frame-relay - snmp-server enable traps frame-relay subif - snmp-server enable traps hsrp - snmp-server enable traps ipmulticast + snmp-server enable traps ipsla snmp-server enable traps isis + snmp-server enable traps license + snmp-server enable traps l2tc threshold sys-threshold + snmp-server enable traps lisp + snmp-server enable traps local-auth + snmp-server enable traps mac-notification change move threshold + snmp-server enable traps memory bufferpeak + snmp-server enable traps mpls fast-reroute protected + snmp-server enable traps mpls rfc ldp + snmp-server enable traps mpls rfc traffic-eng + snmp-server enable traps mpls rfc vpn + snmp-server enable traps mpls traffic-eng + snmp-server enable traps mpls vpn snmp-server enable traps msdp snmp-server enable traps mvpn + snmp-server enable traps nhrp nhc + snmp-server enable traps nhrp nhp + snmp-server enable traps nhrp nhs + snmp-server enable traps nhrp quota-exceeded + snmp-server enable traps ospf cisco-specific errors + snmp-server enable traps ospf cisco-specific lsa + snmp-server enable traps ospf cisco-specific retransmit + snmp-server enable traps ospf cisco-specific state-change nssa-trans-change + snmp-server enable traps ospf cisco-specific state-change shamlink interface + snmp-server enable traps ospf cisco-specific state-change shamlink neighbor + snmp-server enable traps ospf errors + snmp-server enable traps ospf lsa + snmp-server enable traps ospf retransmit + snmp-server enable traps ospf state-change + snmp-server enable traps ospfv3 errors + snmp-server enable traps ospfv3 state-change snmp-server enable traps pim neighbor-change rp-mapping-change invalid-pim-message - snmp-server enable traps rsvp - snmp-server enable traps ipsla - snmp-server enable traps slb real virtual csrp - snmp-server enable traps syslog - snmp-server enable traps event-manager snmp-server enable traps pki - snmp-server enable traps ethernet cfm alarm - snmp-server enable traps mpls vpn + snmp-server enable traps port-security + snmp-server enable traps power-ethernet police + snmp-server enable traps pw vc + snmp-server enable traps rep + snmp-server enable traps rf + snmp-server enable traps smart-license + snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart + snmp-server enable traps stackwise + snmp-server enable traps stpx inconsistency root-inconsistency loop-inconsistency + snmp-server enable traps syslog + snmp-server enable traps transceiver all + snmp-server enable traps trustsec authz-file-error cache-file-error keystore-file-error keystore-sync-fail random-number-fail src-entropy-fail + snmp-server enable traps trustsec-interface unauthorized sap-fail authc-fail supplicant-fail authz-fail + snmp-server enable traps trustsec-policy peer-policy-updated authz-sgacl-fail + snmp-server enable traps trustsec-server radius-server provision-secret + snmp-server enable traps trustsec-sxp conn-srcaddr-err msg-parse-err conn-config-err binding-err conn-up conn-down binding-expn-fail + snmp-server enable traps tty + snmp-server enable traps udld link-fail-rpt status-change + snmp-server enable traps vlan-membership + snmp-server enable traps vlancreate + snmp-server enable traps vlandelete snmp-server enable traps vrfmib vrf-up vrf-down vnet-trunk-up vnet-trunk-down + snmp-server enable traps vswitch dual-active vsl + snmp-server enable traps vtp snmp-server host 172.16.2.99 informs version 2c check msdp snmp-server host 172.16.2.99 check slb snmp-server host 172.16.2.99 checktrap isis @@ -846,60 +874,109 @@ class TestIosSnmpServerModule(TestIosModule): "no snmp-server source-interface informs Loopback999", "no snmp-server trap-source GigabitEthernet0/0", "no snmp-server system-shutdown", - "no snmp-server enable traps auth-framework", + "no snmp-server enable traps aaa_server", + "no snmp-server enable traps auth-framework sec-violation", "no snmp-server enable traps bfd", "no snmp-server enable traps bgp", + "no snmp-server enable traps bgp cbgp2", "no snmp-server enable traps bridge newroot topologychange", - "no snmp-server enable traps casa", + "no snmp-server enable traps bulkstat collection transfer", + "no snmp-server enable traps call-home message-send-fail server-fail", + "no snmp-server enable traps cef resource-failure peer-state-change peer-fib-state-change inconsistency", + "no snmp-server enable traps config", + "no snmp-server enable traps config-copy", + "no snmp-server enable traps config-ctid", + "no snmp-server enable traps cpu threshold", + "no snmp-server enable traps dhcp", "no snmp-server enable traps eigrp", "no snmp-server enable traps energywise", + "no snmp-server enable traps entity", + "no snmp-server enable traps entity-diag boot-up-fail hm-test-recover hm-thresh-reached scheduled-test-fail", + "no snmp-server enable traps entity-perf throughput-notif", + "no snmp-server enable traps entity-state", + "no snmp-server enable traps envmon fan shutdown supply temperature status", + "no snmp-server enable traps errdisable", + "no snmp-server enable traps ether-oam", + "no snmp-server enable traps ethernet cfm alarm", + "no snmp-server enable traps ethernet cfm cc mep-up mep-down cross-connect loop config", + "no snmp-server enable traps ethernet cfm crosscheck mep-missing mep-unknown service-up", + "no snmp-server enable traps ethernet evc status create delete", "no snmp-server enable traps event-manager", + "no snmp-server enable traps flash insertion removal lowspace", + "no snmp-server enable traps flex-links status", "no snmp-server enable traps flowmon", + "no snmp-server enable traps fru-ctrl", "no snmp-server enable traps hsrp", - "no snmp-server enable traps ipsla", - "no snmp-server enable traps isis", - "no snmp-server enable traps msdp", - "no snmp-server enable traps mvpn", - "no snmp-server enable traps mpls vpn", - "no snmp-server enable traps pki", - "no snmp-server enable traps pw vc", - "no snmp-server enable traps rsvp", - "no snmp-server enable traps syslog", - "no snmp-server enable traps tty", - "no snmp-server enable traps vrfmib vrf-up vrf-down vnet-trunk-up vnet-trunk-down", - "no snmp-server enable traps ipmulticast", "no snmp-server enable traps ike policy add", "no snmp-server enable traps ike policy delete", "no snmp-server enable traps ike tunnel start", "no snmp-server enable traps ike tunnel stop", + "no snmp-server enable traps ipmulticast", "no snmp-server enable traps ipsec cryptomap add", - "no snmp-server enable traps ipsec cryptomap delete", "no snmp-server enable traps ipsec cryptomap attach", + "no snmp-server enable traps ipsec cryptomap delete", "no snmp-server enable traps ipsec cryptomap detach", + "no snmp-server enable traps ipsec too-many-sas", "no snmp-server enable traps ipsec tunnel start", "no snmp-server enable traps ipsec tunnel stop", - "no snmp-server enable traps ipsec too-many-sas", + "no snmp-server enable traps ipsla", + "no snmp-server enable traps isis", + "no snmp-server enable traps license", + "no snmp-server enable traps l2tc threshold sys-threshold", + "no snmp-server enable traps lisp", + "no snmp-server enable traps local-auth", + "no snmp-server enable traps mac-notification change move threshold", + "no snmp-server enable traps memory bufferpeak", + "no snmp-server enable traps mpls fast-reroute protected", + "no snmp-server enable traps mpls rfc ldp", + "no snmp-server enable traps mpls rfc traffic-eng", + "no snmp-server enable traps mpls rfc vpn", + "no snmp-server enable traps mpls traffic-eng", + "no snmp-server enable traps mpls vpn", + "no snmp-server enable traps msdp", + "no snmp-server enable traps mvpn", + "no snmp-server enable traps nhrp nhc", + "no snmp-server enable traps nhrp nhp", + "no snmp-server enable traps nhrp nhs", + "no snmp-server enable traps nhrp quota-exceeded", "no snmp-server enable traps ospf cisco-specific errors", - "no snmp-server enable traps ospf cisco-specific retransmit", "no snmp-server enable traps ospf cisco-specific lsa", + "no snmp-server enable traps ospf cisco-specific retransmit", "no snmp-server enable traps ospf cisco-specific state-change nssa-trans-change", "no snmp-server enable traps ospf cisco-specific state-change shamlink interface", "no snmp-server enable traps ospf cisco-specific state-change shamlink neighbor", "no snmp-server enable traps ospf errors", - "no snmp-server enable traps ospf retransmit", "no snmp-server enable traps ospf lsa", + "no snmp-server enable traps ospf retransmit", "no snmp-server enable traps ospf state-change", - "no snmp-server enable traps l2tun pseudowire status", - "no snmp-server enable traps l2tun session", + "no snmp-server enable traps ospfv3 errors", + "no snmp-server enable traps ospfv3 state-change", "no snmp-server enable traps pim neighbor-change rp-mapping-change invalid-pim-message", - "no snmp-server enable traps snmp authentication linkdown linkup warmstart coldstart", - "no snmp-server enable traps frame-relay", - "no snmp-server enable traps cef resource-failure peer-state-change peer-fib-state-change inconsistency", - "no snmp-server enable traps dlsw", - "no snmp-server enable traps ethernet evc create delete status", - "no snmp-server enable traps ethernet cfm alarm", - "no snmp-server enable traps ethernet cfm cc mep-up mep-down cross-connect loop config", - "no snmp-server enable traps ethernet cfm crosscheck mep-missing mep-unknown service-up", + "no snmp-server enable traps pki", + "no snmp-server enable traps port-security", + "no snmp-server enable traps power-ethernet police", + "no snmp-server enable traps pw vc", + "no snmp-server enable traps rep", + "no snmp-server enable traps rf", + "no snmp-server enable traps smart-license", + "no snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart", + "no snmp-server enable traps stackwise", + "no snmp-server enable traps stpx inconsistency root-inconsistency loop-inconsistency", + "no snmp-server enable traps syslog", + "no snmp-server enable traps transceiver all", + "no snmp-server enable traps trustsec authz-file-error cache-file-error keystore-file-error keystore-sync-fail random-number-fail src-entropy-fail", + "no snmp-server enable traps trustsec-interface unauthorized sap-fail authc-fail supplicant-fail authz-fail", + "no snmp-server enable traps trustsec-policy peer-policy-updated authz-sgacl-fail", + "no snmp-server enable traps trustsec-server radius-server provision-secret", + "no snmp-server enable traps trustsec-sxp conn-srcaddr-err msg-parse-err conn-config-err binding-err conn-up conn-down binding-expn-fail", + "no snmp-server enable traps tty", + "no snmp-server enable traps udld link-fail-rpt status-change", + "no snmp-server enable traps vlan-membership", + "no snmp-server enable traps vlancreate", + "no snmp-server enable traps vlandelete", + "no snmp-server enable traps vrfmib vrf-up vrf-down vnet-trunk-up vnet-trunk-down", + "no snmp-server enable traps vswitch dual-active vsl", + "no snmp-server enable traps vtp", "no snmp-server host 172.16.1.1 version 3 auth group0 tty", "no snmp-server host 172.16.2.1 version 3 priv newtera rsrb", "no snmp-server host 172.16.2.1 version 3 noauth replaceUser slb", @@ -1105,7 +1182,7 @@ class TestIosSnmpServerModule(TestIosModule): "trap_source": "GigabitEthernet0/0", "trap_timeout": 2, "traps": { - "auth_framework": {"enable": True}, + "auth_framework": {"enable": True, "sec_violation": True}, "bfd": {"enable": True}, "bgp": {"cbgp2": True, "enable": True}, "bridge": {"enable": True, "newroot": True, "topologychange": True}, @@ -1155,7 +1232,9 @@ class TestIosSnmpServerModule(TestIosModule): "ipsla": True, "isis": True, "l2tun": {"pseudowire_status": True, "session": True}, - "mpls_vpn": True, + "mpls": { + "vpn": {"enable": True}, + }, "msdp": True, "mvpn": True, "ospf": { @@ -1200,7 +1279,12 @@ class TestIosSnmpServerModule(TestIosModule): }, "users": [ {"acl_v4": "24", "group": "newfamily", "username": "newuser", "version": "v1"}, - {"acl_v4": "ipv6", "group": "familypaul", "username": "paul", "version": "v3"}, + { + "acl_v6": "ipv6acl", + "group": "familypaul", + "username": "paul", + "version": "v3", + }, {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, ], "views": [ @@ -1243,8 +1327,9 @@ class TestIosSnmpServerModule(TestIosModule): "no snmp-server context contextBAD", "snmp-server password-policy policy1 define max-len 24 upper-case 12 lower-case 12 special-char 32 digits 23 change 3", "snmp-server password-policy policy2 define min-len 12 upper-case 12 special-char 22 change 9", - "snmp-server user paul familypaul v3 access ipv6", + "snmp-server user paul familypaul v3 access ipv6 ipv6acl", "snmp-server view newView TestFamilyName included", + "no snmp-server enable traps vtp", "no snmp-server view test-view! test-test included", ] playbook["state"] = "overridden" @@ -1351,10 +1436,11 @@ class TestIosSnmpServerModule(TestIosModule): }, }, "envmon": { + "enable": True, "status": True, "supply": True, "temperature": True, - "fan": {"supply": True, "temperature": True}, + "fan_enable": True, }, "ethernet": { "cfm": { @@ -1711,7 +1797,7 @@ class TestIosSnmpServerModule(TestIosModule): def test_ios_snmpv3_user_server_merged(self): self.execute_show_command.return_value = dedent( """\ - snmp-server user rhcisco testfamily v3 access ipv6 + snmp-server user rhcisco testfamily v3 access ipv4 """, ) @@ -1726,14 +1812,14 @@ class TestIosSnmpServerModule(TestIosModule): User name: paul Engine ID: 000000090200000000000A0B - storage-type: nonvolatile active access-list: ipv6 + storage-type: nonvolatile active access-list: 22 Authentication Protocol: MD5 Privacy Protocol: None Group-name: familypaul User name: flow Engine ID: 000000090200000000000A0B - storage-type: nonvolatile active access-list: 27 + storage-type: nonvolatile active access-list: 22 Authentication Protocol: MD5 Privacy Protocol: None Group-name: mfamily @@ -1743,13 +1829,23 @@ class TestIosSnmpServerModule(TestIosModule): playbook = { "config": { "users": [ - {"acl_v4": "ipv6", "group": "familypaul", "username": "paul", "version": "v3"}, - {"acl_v4": "27", "group": "mfamily", "username": "flow", "version": "v3"}, + { + "acl_v6": "ipv6acl", + "group": "familypaul", + "username": "paul", + "version": "v3", + }, + { + "acl_v4": "27", + "group": "mfamily", + "username": "flow", + "version": "v3", + }, ], }, } merged = [ - "snmp-server user paul familypaul v3 access ipv6", + "snmp-server user paul familypaul v3 access ipv6 ipv6acl 22", "snmp-server user flow mfamily v3 access 27", ] @@ -1786,13 +1882,27 @@ class TestIosSnmpServerModule(TestIosModule): playbook = { "config": { "users": [ - {"group": "replaceUser", "username": "replaceUser", "version": "v3"}, - {"acl_v4": "27", "group": "mfamily", "username": "flow", "version": "v3"}, + { + "acl_v4": "22", + "authentication": { + "algorithm": "md5", + "password": "replaceUser", + }, + "group": "replaceUser", + "username": "replaceUser", + "version": "v3", + }, + { + "acl_v4": "27", + "group": "mfamily", + "username": "flow", + "version": "v3", + }, ], }, } overridden = [ - "no snmp-server user flow mfamily v3", + "no snmp-server user flow mfamily v3 access 27", "snmp-server user flow mfamily v3 access 27", "no snmp-server user newuser newfamily v1 access 24", ] diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py index bbc2b2e0f..d1046cc72 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_static_routes.py @@ -23,33 +23,12 @@ class TestIosStaticRoutesModule(TestIosModule): def setUp(self): super(TestIosStaticRoutesModule, self).setUp() - self.mock_get_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.get_config", - ) - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.network.Config.load_config", - ) - self.load_config = self.mock_load_config.start() - - self.mock_get_resource_connection_config = patch( - "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.cfg.base." - "get_resource_connection", - ) - self.get_resource_connection_config = self.mock_get_resource_connection_config.start() - self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." "get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() - self.mock_edit_config = patch( - "ansible_collections.cisco.ios.plugins.module_utils.network.ios.providers.providers.CliProvider.edit_config", - ) - self.edit_config = self.mock_edit_config.start() - self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.static_routes.static_routes." "Static_routesFacts.get_static_routes_data", @@ -58,11 +37,7 @@ class TestIosStaticRoutesModule(TestIosModule): def tearDown(self): super(TestIosStaticRoutesModule, self).tearDown() - self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() - self.mock_edit_config.stop() - self.mock_get_config.stop() - self.mock_load_config.stop() self.mock_execute_show_command.stop() def test_ios_static_routes_merged(self): @@ -127,8 +102,8 @@ class TestIosStaticRoutesModule(TestIosModule): ) result = self.execute_module(changed=True) commands = [ - "ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150", "ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast", + "ip route vrf ansible_vrf 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150", ] self.assertEqual(result["commands"], commands) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py index 28d5126c2..8cd3c07c3 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_user.py @@ -49,7 +49,7 @@ class TestIosUserModule(TestIosModule): self.mock_get_config.stop() self.mock_load_config.stop() - def load_fixtures(self, commands=None, transport="cli"): + def load_fixtures(self, commands=None): self.get_config.return_value = load_fixture("ios_user_config.cfg") self.load_config.return_value = dict(diff=None, session="session") diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py index 201e814c5..c19d58ffd 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vlans.py @@ -50,6 +50,18 @@ class TestIosVlansModule(TestIosModule): ) self.edit_config = self.mock_edit_config.start() + self.mock_get_resource_connection_facts_2 = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts_2 = self.mock_get_resource_connection_facts_2.start() + + self.mock_execute_show_command_2 = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." + "VlansFacts.get_vlans_data", + ) + self.execute_show_command_2 = self.mock_execute_show_command_2.start() + self.mock_execute_show_command = patch( "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans." "VlansFacts.get_vlans_data", @@ -69,8 +81,10 @@ class TestIosVlansModule(TestIosModule): self.mock_load_config.stop() self.mock_execute_show_command.stop() self.mock_l2_device_command.stop() + self.mock_get_resource_connection_facts_2.stop() + self.mock_execute_show_command_2.stop() - def load_fixtures(self, commands=None, transport="cli"): + def load_fixtures(self, commands=None): def load_from_file(*args, **kwargs): return load_fixture("ios_vlans_config.cfg") @@ -372,7 +386,7 @@ class TestIosVlansModule(TestIosModule): ) self.execute_module(changed=False, commands=[], sort=True) - def test_ios_delete_vlans_config(self): + def test_ios_delete_vlans(self): set_module_args(dict(config=[dict(vlan_id=150)], state="deleted")) result = self.execute_module(changed=True) commands = ["no vlan 150"] @@ -648,3 +662,220 @@ class TestIosVlansModule(TestIosModule): self.maxDiff = None self.assertEqual(result["gathered"], gathered) + + def test_ios_vlans_config_merged(self): + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="merged", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = [ + "vlan configuration 101", + "member evpn-instance 101 vni 10101", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_vlans_config_merged_idempotent(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="merged", + configuration=True, + ), + ) + self.execute_module(changed=False, commands=[], sort=True) + + def test_ios_vlans_config_overridden(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=102, + vni=10102, + ), + ), + dict( + vlan_id=102, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + state="overridden", + configuration=True, + ), + ) + result = self.execute_module(changed=True) + commands = [ + "vlan configuration 101", + "no member evpn-instance 101 vni 10101", + "vlan configuration 102", + "no member evpn-instance 102 vni 10102", + "vlan configuration 101", + "member evpn-instance 102 vni 10102", + "vlan configuration 102", + "member evpn-instance 101 vni 10101", + "no vlan configuration 201", + "no vlan configuration 202", + "no vlan configuration 901", + "no vlan configuration 902", + ] + self.assertEqual(result["commands"], commands) + + def test_ios_delete_vlans_config(self): + self.execute_show_command_2 = self.mock_execute_show_command_2.start() + self.execute_show_command_2.return_value = dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 201 + member evpn-instance 201 vni 10201 + vlan configuration 202 + member evpn-instance 202 vni 10202 + vlan configuration 901 + member vni 50901 + vlan configuration 902 + member vni 50902 + """, + ) + set_module_args( + dict( + config=[ + {"vlan_id": 101}, + ], + configuration=True, + state="deleted", + ), + ) + result = self.execute_module(changed=True) + commands = ["no vlan configuration 101"] + self.assertEqual(result["commands"], commands) + + def test_vlans_config_rendered(self): + self.execute_show_command_2.return_value = dedent( + """\ + """, + ) + set_module_args( + dict( + config=[ + dict( + vlan_id=101, + member=dict( + evi=101, + vni=10101, + ), + ), + ], + configuration=True, + state="rendered", + ), + ) + commands = [ + "vlan configuration 101", + "member evpn-instance 101 vni 10101", + ] + result = self.execute_module(changed=False) + self.assertEqual(result["rendered"], commands) + + def test_vlans_config_parsed(self): + set_module_args( + dict( + running_config=dedent( + """\ + vlan configuration 101 + member evpn-instance 101 vni 10101 + vlan configuration 102 + member evpn-instance 102 vni 10102 + vlan configuration 901 + member vni 50901 + """, + ), + state="parsed", + configuration=True, + ), + ) + parsed = [ + { + "member": { + "evi": 101, + "vni": 10101, + }, + "vlan_id": 101, + }, + { + "member": { + "evi": 102, + "vni": 10102, + }, + "vlan_id": 102, + }, + { + "member": { + "vni": 50901, + }, + "vlan_id": 901, + }, + ] + + result = self.execute_module(changed=False) + self.maxDiff = None + self.assertEqual(result["parsed"], parsed) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py index d4043689e..d36ea41e1 100644 --- a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vrf.py @@ -388,3 +388,72 @@ class TestIosVrfModule(TestIosModule): set_module_args(dict(name="test_19", interfaces=["Ethernet1"])) commands = ["interface Ethernet1", "vrf forwarding test_19", "ip address 1.2.3.4/5"] self.execute_module(changed=True, commands=commands, sort=False) + + def test_ios_mdt(self): + set_module_args( + { + "name": "blue", + "address_family": [ + { + "afi": "ipv4", + "mdt": { + "overlay": { + "use_bgp": { + "enable": True, + "spt_only": True, + }, + }, + "auto_discovery": { + "vxlan": { + "enable": True, + "inter_as": True, + }, + }, + "default": { + "vxlan_mcast_group": "239.1.1.1", + }, + "data": { + "vxlan_mcast_group": "225.2.2.0 0.0.0.255", + "threshold": "112", + }, + }, + }, + { + "afi": "ipv6", + "mdt": { + "overlay": { + "use_bgp": { + "enable": True, + "spt_only": True, + }, + }, + "auto_discovery": { + "vxlan": { + "enable": True, + "inter_as": True, + }, + }, + "default": { + "vxlan_mcast_group": "239.1.1.2", + }, + }, + }, + ], + }, + ) + commands = [ + "vrf definition blue", + "address-family ipv4", + "mdt overlay use-bgp spt-only", + "mdt auto-discovery vxlan inter-as", + "mdt default vxlan 239.1.1.1", + "mdt data vxlan 225.2.2.0 0.0.0.255", + "mdt data threshold 112", + "exit-address-family", + "address-family ipv6", + "mdt overlay use-bgp spt-only", + "mdt auto-discovery vxlan inter-as", + "mdt default vxlan 239.1.1.2", + "exit-address-family", + ] + self.execute_module(changed=True, commands=commands, sort=False) diff --git a/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py new file mode 100644 index 000000000..25b0bc8a6 --- /dev/null +++ b/ansible_collections/cisco/ios/tests/unit/modules/network/ios/test_ios_vxlan_vtep.py @@ -0,0 +1,443 @@ +# +# (c) 2023, Red Hat +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +# + +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from textwrap import dedent + +from ansible_collections.cisco.ios.plugins.modules import ios_vxlan_vtep +from ansible_collections.cisco.ios.tests.unit.compat.mock import patch +from ansible_collections.cisco.ios.tests.unit.modules.utils import set_module_args + +from .ios_module import TestIosModule + + +class TestIosVxlanVtepModule(TestIosModule): + module = ios_vxlan_vtep + + def setUp(self): + super(TestIosVxlanVtepModule, self).setUp() + + self.mock_get_resource_connection_facts = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base." + "get_resource_connection", + ) + self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() + + self.mock_execute_show_command = patch( + "ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vxlan_vtep.vxlan_vtep." + "Vxlan_vtepFacts.get_vxlan_vtep_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + + def tearDown(self): + super(TestIosVxlanVtepModule, self).tearDown() + self.mock_get_resource_connection_facts.stop() + self.mock_execute_show_command.stop() + + def test_ios_vxlan_vtep_merged(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback1 + host-reachability protocol bgp + member vni 10101 mcast-group 225.0.0.101 + member vni 10102 ingress-replication + member vni 50901 vrf green + member vni 10201 mcast-group 225.0.0.101 + member vni 10202 ingress-replication + member vni 50902 vrf blue + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": {"type": "ingress"}, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv4": "225.0.0.101", + "ipv6": "FF0E:225::101", + }, + }, + }, + ], + "l3vni": [ + { + "vni": "50901", + "vrf": "blue", + }, + ], + }, + }, + }, + ], + state="merged", + ), + ) + commands = [ + "interface nve1", + "source-interface Loopback2", + "no member vni 10101 mcast-group 225.0.0.101", + "member vni 10101 ingress-replication", + "no member vni 10201 mcast-group 225.0.0.101", + "member vni 10201 mcast-group 225.0.0.101 FF0E:225::101", + "no member vni 50901 vrf green", + "no member vni 50902 vrf blue", + "member vni 50901 vrf blue", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_vxlan_vtep_merged_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 ingress-replication + member vni 10102 ingress-replication + member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + member vni 10202 ingress-replication + member vni 50901 vrf blue + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": {"type": "ingress"}, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv4": "225.0.0.101", + "ipv6": "FF0E:225::101", + }, + }, + }, + ], + "l3vni": [ + { + "vni": "50901", + "vrf": "blue", + }, + ], + }, + }, + }, + ], + state="merged", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_vxlan_vtep_replaced(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 ingress-replication + member vni 10102 ingress-replication + member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + member vni 10202 ingress-replication + member vni 50901 vrf blue + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "host_reachability_bgp": True, + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::101", + }, + }, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::102", + }, + }, + }, + ], + }, + }, + }, + ], + state="replaced", + ), + ) + commands = [ + "interface nve1", + "no member vni 10101 ingress-replication", + "member vni 10101 mcast-group FF0E:225::101", + "no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101", + "member vni 10201 mcast-group FF0E:225::102", + "no member vni 10102 ingress-replication", + "no member vni 10202 ingress-replication", + "no member vni 50901 vrf blue", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_vxlan_vtep_replaced_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 mcast-group FF0E:225::101 + member vni 10201 mcast-group FF0E:225::102 + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "host_reachability_bgp": True, + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::101", + }, + }, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::102", + }, + }, + }, + ], + }, + }, + }, + ], + state="replaced", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_vxlan_vtep_overridden(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10102 ingress-replication + member vni 10202 ingress-replication + member vni 10101 ingress-replication + member vni 10201 mcast-group 225.0.0.101 FF0E:225::101 + member vni 50901 vrf blue + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "host_reachability_bgp": True, + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::101", + }, + }, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::102", + }, + }, + }, + ], + }, + }, + }, + ], + state="overridden", + ), + ) + commands = [ + "interface nve1", + "no member vni 10101 ingress-replication", + "member vni 10101 mcast-group FF0E:225::101", + "no member vni 10201 mcast-group 225.0.0.101 FF0E:225::101", + "member vni 10201 mcast-group FF0E:225::102", + "no member vni 10102 ingress-replication", + "no member vni 10202 ingress-replication", + "no member vni 50901 vrf blue", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_vxlan_vtep_overridden_idempotent(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 mcast-group FF0E:225::101 + member vni 10201 mcast-group FF0E:225::102 + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "source_interface": "Loopback2", + "host_reachability_bgp": True, + "member": { + "vni": { + "l2vni": [ + { + "vni": "10101", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::101", + }, + }, + }, + { + "vni": "10201", + "replication": { + "type": "static", + "mcast_group": { + "ipv6": "FF0E:225::102", + }, + }, + }, + ], + }, + }, + }, + ], + state="overridden", + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_ios_vxlan_vtep_deleted(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 mcast-group FF0E:225::101 + member vni 10201 mcast-group FF0E:225::102 + """, + ) + set_module_args(dict(config=[dict(interface="nve1")], state="deleted")) + commands = [ + "interface nve1", + "no source-interface Loopback2", + "no host-reachability protocol bgp", + "no member vni 10101 mcast-group FF0E:225::101", + "no member vni 10201 mcast-group FF0E:225::102", + ] + result = self.execute_module(changed=True) + self.assertEqual(result["commands"], commands) + + def test_ios_vxlan_vtep_deleted_member_vni(self): + self.execute_show_command.return_value = dedent( + """\ + interface nve1 + no ip address + source-interface Loopback2 + host-reachability protocol bgp + member vni 10101 mcast-group FF0E:225::101 + member vni 10201 mcast-group FF0E:225::102 + """, + ) + set_module_args( + dict( + config=[ + { + "interface": "nve1", + "member": { + "vni": { + "l2vni": [ + {"vni": "10101"}, + {"vni": "10201"}, + ], + }, + }, + }, + ], + state="deleted", + ), + ) + commands = [ + "interface nve1", + "no member vni 10101 mcast-group FF0E:225::101", + "no member vni 10201 mcast-group FF0E:225::102", + ] + result = self.execute_module(changed=True) + self.assertEqual(sorted(result["commands"]), sorted(commands)) diff --git a/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py b/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py index 8d86ada75..0b7cf8704 100644 --- a/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py +++ b/ansible_collections/cisco/ios/tests/unit/plugins/cliconf/test_ios.py @@ -94,44 +94,44 @@ class TestPluginCLIConfIOS(unittest.TestCase): """Test get_capabilities""" capabilities = json.loads(self._cliconf.get_capabilities()) mock_capabilities = { - "network_api": "cliconf", - "rpc": [ - "get_config", - "edit_config", - "get_capabilities", - "get", - "enable_response_logging", - "disable_response_logging", - "edit_banner", - "get_diff", - "run_commands", - "get_defaults_flag", - ], + "device_info": { + "network_os": "ios", + "network_os_hostname": "an-csr-01", + "network_os_image": "bootflash:packages.conf", + "network_os_model": "CSR1000V", + "network_os_type": "L2", + "network_os_version": "16.06.01", + }, "device_operations": { - "supports_diff_replace": True, "supports_commit": False, - "supports_rollback": False, - "supports_defaults": True, - "supports_onbox_diff": False, "supports_commit_comment": False, - "supports_multiline_delimiter": True, - "supports_diff_match": True, + "supports_defaults": True, "supports_diff_ignore_lines": True, + "supports_diff_match": True, + "supports_diff_replace": True, "supports_generate_diff": True, + "supports_multiline_delimiter": True, + "supports_onbox_diff": False, "supports_replace": False, + "supports_rollback": False, }, - "device_info": { - "network_os_hostname": "an-csr-01", - "network_os_image": "bootflash:packages.conf", - "network_os_model": "CSR1000V", - "network_os_version": "16.06.01", - "network_os": "ios", - "network_os_type": "L2", - }, - "format": ["text"], "diff_match": ["line", "strict", "exact", "none"], "diff_replace": ["line", "block"], + "format": ["text"], + "network_api": "cliconf", "output": [], + "rpc": [ + "edit_config", + "enable_response_logging", + "get", + "get_capabilities", + "get_config", + "disable_response_logging", + "run_commands", + "edit_banner", + "get_diff", + "run_commands", + "get_defaults_flag", + ], } - - self.assertEqual(mock_capabilities, capabilities) + self.assertEqual(sorted(mock_capabilities), sorted(capabilities)) |