From fe65e1a4e84422ca8a501b8c88c7606e8f2503af Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 29 Jul 2024 12:24:35 +0530 Subject: [PATCH 1/3] Adds facts to list of facts and fix management fact --- tests/integration/targets/nxos_facts/vars/main.yml | 1 + tests/integration/targets/nxos_vrf_global/tasks/main.yml | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/targets/nxos_facts/vars/main.yml b/tests/integration/targets/nxos_facts/vars/main.yml index 5965c4191..f010eb0ac 100644 --- a/tests/integration/targets/nxos_facts/vars/main.yml +++ b/tests/integration/targets/nxos_facts/vars/main.yml @@ -28,3 +28,4 @@ available_network_resources: - static_routes - telemetry - vlans + - vrf_global diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml index 53a64850f..51edbb4da 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/main.yml +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -8,9 +8,6 @@ ansible.builtin.set_fact: management: - ip: - name_server: - address_list: - - "{{ result.stdout[0] | regex_search('ip name-server ([0-9.]+)', '\\1') | first }}" route: - destination: "{{ result.stdout[0] | regex_search('ip route [0-9.]+/[0-9]+ ([0-9.]+)', '\\1') | first }}" source: "{{ result.stdout[0] | regex_search('ip route ([0-9.]+/[0-9]+)', '\\1') | first }}" From 837c1dd7f74db83dd3ab4dd442817a7e47893ae2 Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 29 Jul 2024 19:57:36 +0530 Subject: [PATCH 2/3] updated test to make sure it works with CI device --- .../targets/nxos_vrf_global/tasks/main.yml | 18 +++++ .../nxos_vrf_global/tests/common/merged.yaml | 78 +++++++++++++++---- .../targets/nxos_vrf_global/vars/main.yaml | 13 +--- 3 files changed, 82 insertions(+), 27 deletions(-) diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml index 51edbb4da..95a0dd8a8 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/main.yml +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -4,6 +4,24 @@ commands: show running | section '^vrf' register: result +- name: Check CI machine # Check if CI machine is being used as CI machine does not support some attributes + cisco.nxos.nxos_config: + lines: + - ip multicast multipath legacy + parents: "vrf context check" + register: result_check + ignore_errors: true + +- name: Set check fact + ansible.builtin.set_fact: + isci: result_check.failed + +- name: Remove CI check config + cisco.nxos.nxos_config: + lines: + - no vrf context check + ignore_errors: true + - name: Set management fact ansible.builtin.set_fact: management: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml index 62706f137..11206cdff 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml @@ -5,10 +5,14 @@ - ansible.builtin.include_tasks: _remove_config.yaml - block: - - name: Merge provided configuration with device configuration - register: result - cisco.nxos.nxos_vrf_global: &id001 - config: + - name: Set config to test based on device # As some devices do not support some of the attributes + ansible.builtin.set_fact: + symmetric_diff: + - ip multicast multipath legacy + - ipv6 multicast group-range prefix-list temp + - multicast service-reflect interface Ethernet1/1 map interface Ethernet2/2 + - multicast service-reflect interface Ethernet2/1 map interface Ethernet4/2 + vrfConfig: vrfs: - description: this-is-test ip: @@ -24,7 +28,7 @@ ssm_translate: - group: 232.0.0.0/8 source: 10.1.1.1 - - group: 239.1.2.3/24 + - group: 239.1.2.0/24 source: 192.168.1.1 mroutes: - group: 192.168.1.0/24 @@ -36,8 +40,6 @@ multicast: multipath: resilient: true - splitting_type: - legacy: true rpf: - group_list_range: 238.1.0.0/24 vrf_name: temp @@ -70,20 +72,64 @@ - group: ff30::/16 source: 2001:db8:0:abcd::5 multicast: - group_range_prefix_list: temp multipath: resilient: true splitting_type: none: true - multicast: - service_reflect: - - map_to: Ethernet2/2 - service_interface: Ethernet1/1 - - map_to: Ethernet4/2 - service_interface: Ethernet2/1 name: VRF7 vni: vni_number: 5 + + - name: Update Fact based on device + ansible.utils.update_fact: + updates: + - path: vrfConfig.vrfs.0.ip.multicast.multipath.splitting_type + value: true + - path: vrfConfig.vrfs.0.ipv6.multicast.group_range_prefix_list + value: temp + - path: vrfConfig.vrfs.0.multicast + value: + service_reflect: + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 + when: not isci + register: updated_fact + + - name: Set final test config + ansible.builtin.set_fact: + vrfConfig: "{{ updated_fact.vrfConfig }}" + when: not isci + + - name: Set final commands to test against + ansible.builtin.set_fact: + final_commands: "{{ merged['commands'] | difference(symmetric_diff) if isci else merged['commands'] }}" + + - name: Update after dict to test against + ansible.utils.update_fact: + updates: + - path: merged.after.vrfs.0.ip.multicast.multipath.splitting_type + value: true + - path: merged.after.vrfs.0.ipv6.multicast.group_range_prefix_list + value: temp + - path: merged.after.vrfs.0.multicast + value: + service_reflect: + - map_to: Ethernet2/2 + service_interface: Ethernet1/1 + - map_to: Ethernet4/2 + service_interface: Ethernet2/1 + register: updated_after + + - name: Set final dict to test against + ansible.builtin.set_fact: + updated_after: "{{ updated_after.merged.after.vrfs if not isci else merged['after']['vrfs'] }}" + + - name: Merge provided configuration with device configuration + register: result + cisco.nxos.nxos_vrf_global: &id001 + config: "{{ vrfConfig }}" state: merged - name: Remove management from list of result @@ -98,7 +144,7 @@ - name: Assert that correct set of commands were generated ansible.builtin.assert: that: - - "{{ merged['commands'] | symmetric_difference(result['commands']) | length == 0 }}" + - "{{ final_commands | symmetric_difference(result['commands']) | length == 0 }}" - name: Assert that before dicts are correctly generated ansible.builtin.assert: @@ -108,7 +154,7 @@ - name: Assert that after dict is correctly generated ansible.builtin.assert: that: - - res_after['after']['vrfs'] == merged['after']['vrfs'] + - res_after['after']['vrfs'] == updated_after - name: Merge provided configuration with device configuration (idempotent) register: result diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index 54705f0a4..66664b920 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -35,7 +35,7 @@ merged: - ipv6 multicast multipath none - ip domain-list example.net - ip igmp ssm-translate 232.0.0.0/8 10.1.1.1 - - ip igmp ssm-translate 239.1.2.3/24 192.168.1.1 + - ip igmp ssm-translate 239.1.2.0/24 192.168.1.1 - ip mroute 192.168.1.0/24 192.168.1.1 - ip mroute 192.168.1.0/24 192.168.1.2 2 vrf temp - ip multicast rpf select vrf temp group-list 238.1.0.0/24 @@ -63,7 +63,7 @@ merged: ssm_translate: - group: 232.0.0.0/8 source: 10.1.1.1 - - group: 239.1.2.3/24 + - group: 239.1.2.0/24 source: 192.168.1.1 mroutes: - group: 192.168.1.0/24 @@ -75,8 +75,6 @@ merged: multicast: multipath: resilient: true - splitting_type: - legacy: true rpf: - group_list_range: 238.1.0.0/24 vrf_name: temp @@ -109,17 +107,10 @@ merged: - group: "ff30::/16" source: "2001:db8:0:abcd::5" multicast: - group_range_prefix_list: temp multipath: resilient: true splitting_type: none: true - multicast: - service_reflect: - - map_to: Ethernet2/2 - service_interface: Ethernet1/1 - - map_to: Ethernet4/2 - service_interface: Ethernet2/1 name: VRF7 vni: vni_number: 5 From 4f2c63764e6401403d7ff179b8058902a9b7e72b Mon Sep 17 00:00:00 2001 From: roverflow Date: Mon, 29 Jul 2024 21:21:21 +0530 Subject: [PATCH 3/3] fixes running the tests by adding pauses --- .../targets/nxos_vrf_global/tasks/main.yml | 18 ------------------ .../tests/common/_check_device.yaml | 18 ++++++++++++++++++ .../nxos_vrf_global/tests/common/_parsed.cfg | 1 - .../tests/common/_populate_config.yaml | 2 ++ .../nxos_vrf_global/tests/common/merged.yaml | 5 +++++ .../nxos_vrf_global/tests/common/replaced.yaml | 1 - .../nxos_vrf_global/tests/common/rtt.yaml | 4 ++++ .../targets/nxos_vrf_global/vars/main.yaml | 1 - 8 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 tests/integration/targets/nxos_vrf_global/tests/common/_check_device.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tasks/main.yml b/tests/integration/targets/nxos_vrf_global/tasks/main.yml index 95a0dd8a8..51edbb4da 100644 --- a/tests/integration/targets/nxos_vrf_global/tasks/main.yml +++ b/tests/integration/targets/nxos_vrf_global/tasks/main.yml @@ -4,24 +4,6 @@ commands: show running | section '^vrf' register: result -- name: Check CI machine # Check if CI machine is being used as CI machine does not support some attributes - cisco.nxos.nxos_config: - lines: - - ip multicast multipath legacy - parents: "vrf context check" - register: result_check - ignore_errors: true - -- name: Set check fact - ansible.builtin.set_fact: - isci: result_check.failed - -- name: Remove CI check config - cisco.nxos.nxos_config: - lines: - - no vrf context check - ignore_errors: true - - name: Set management fact ansible.builtin.set_fact: management: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_check_device.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_check_device.yaml new file mode 100644 index 000000000..6ec0ca9c6 --- /dev/null +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_check_device.yaml @@ -0,0 +1,18 @@ +--- +- name: Check machine + cisco.nxos.nxos_config: + lines: + - ip multicast multipath legacy + parents: vrf context check + register: result_check + ignore_errors: true + +- name: Set check fact + ansible.builtin.set_fact: + isci: result_check.failed + +- name: Remove CI check config + cisco.nxos.nxos_config: + lines: + - no vrf context check + ignore_errors: true diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg index 60a0a2fdf..c188eea23 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_parsed.cfg @@ -4,7 +4,6 @@ vrf context management vrf context temp ip domain-name example.org ip domain-list example.com - ip domain-list example.net description Test ip auto-discard ip multicast rpf select vrf temp1 group-list 238.1.0.0/24 diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml index a8b8ae4cd..2adf74794 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/_populate_config.yaml @@ -11,6 +11,8 @@ - ipv6 mld ssm-translate ff28::/16 2001:db8:0:abcd::2 - ipv6 mld ssm-translate ff30::/16 2001:db8:0:abcd::5 match: none + retries: 3 + delay: 20 - name: Merge another vrf cisco.nxos.nxos_config: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml index 11206cdff..c9fb4c341 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml @@ -3,6 +3,7 @@ msg: START Merged nxos_vrf_global state for integration tests on connection={{ ansible_connection }} - ansible.builtin.include_tasks: _remove_config.yaml +- ansible.builtin.include_tasks: _check_device.yaml - block: - name: Set config to test based on device # As some devices do not support some of the attributes @@ -164,5 +165,9 @@ ansible.builtin.assert: that: - result['changed'] == false + + - name: Wait for 20 seconds after merging + ansible.builtin.wait_for: + timeout: 20 always: - ansible.builtin.include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml index c57a6f446..0a4503b24 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/replaced.yaml @@ -2,7 +2,6 @@ - ansible.builtin.debug: msg: START replaced nxos_vrf_global state for integration tests on connection={{ ansible_connection }} -- ansible.builtin.include_tasks: _remove_config.yaml - ansible.builtin.include_tasks: _populate_config.yaml - block: diff --git a/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml b/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml index cff796bdc..2de6c6f4c 100644 --- a/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml +++ b/tests/integration/targets/nxos_vrf_global/tests/common/rtt.yaml @@ -32,6 +32,10 @@ gather_network_resources: - vrf_global + - name: Wait for 20 seconds after merging + ansible.builtin.wait_for: + timeout: 20 + - name: Overridden the provided configuration with the existing running configuration cisco.nxos.nxos_vrf_global: config: diff --git a/tests/integration/targets/nxos_vrf_global/vars/main.yaml b/tests/integration/targets/nxos_vrf_global/vars/main.yaml index 66664b920..e3fd5df5e 100644 --- a/tests/integration/targets/nxos_vrf_global/vars/main.yaml +++ b/tests/integration/targets/nxos_vrf_global/vars/main.yaml @@ -293,7 +293,6 @@ parsed: auto_discard: true domain_list: - example.com - - example.net domain_name: example.org multicast: rpf: