Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds facts to list of facts and fix management fact #875

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/integration/targets/nxos_facts/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ available_network_resources:
- static_routes
- telemetry
- vlans
- vrf_global
3 changes: 0 additions & 3 deletions tests/integration/targets/nxos_vrf_global/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
83 changes: 67 additions & 16 deletions tests/integration/targets/nxos_vrf_global/tests/common/merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
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: 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:
Expand All @@ -24,7 +29,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
Expand All @@ -36,8 +41,6 @@
multicast:
multipath:
resilient: true
splitting_type:
legacy: true
rpf:
- group_list_range: 238.1.0.0/24
vrf_name: temp
Expand Down Expand Up @@ -70,20 +73,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
Expand All @@ -98,7 +145,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:
Expand All @@ -108,7 +155,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
Expand All @@ -118,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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 2 additions & 12 deletions tests/integration/targets/nxos_vrf_global/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -302,7 +293,6 @@ parsed:
auto_discard: true
domain_list:
- example.com
- example.net
domain_name: example.org
multicast:
rpf:
Expand Down
Loading