From 7292dd20ed1cd88ff0d94357dcfc3405b4a3e193 Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Wed, 13 Sep 2017 08:03:06 -0400 Subject: [PATCH] Fix nxos_overlay_global networking modules (#28943) --- .../network/nxos/nxos_overlay_global.py | 25 ++--- test/integration/nxos.yaml | 8 ++ .../tests/common/set_state_present.yaml | 2 + .../nxos_overlay_global/defaults/main.yaml | 2 + .../targets/nxos_overlay_global/meta/main.yml | 2 + .../nxos_overlay_global/tasks/cli.yaml | 15 +++ .../nxos_overlay_global/tasks/main.yaml | 7 ++ .../nxos_overlay_global/tasks/nxapi.yaml | 28 +++++ .../tasks/platform/n7k/cleanup.yaml | 24 ++++ .../tasks/platform/n7k/setup.yaml | 40 +++++++ .../nxos_overlay_global/tests/cli/sanity.yaml | 4 + .../tests/common/sanity.yaml | 104 ++++++++++++++++++ .../tests/nxapi/sanity.yaml | 4 + .../targets/prepare_nxos_tests/tasks/main.yml | 41 +++++++ 14 files changed, 293 insertions(+), 13 deletions(-) create mode 100644 test/integration/targets/nxos_overlay_global/defaults/main.yaml create mode 100644 test/integration/targets/nxos_overlay_global/meta/main.yml create mode 100644 test/integration/targets/nxos_overlay_global/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tasks/main.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tests/common/sanity.yaml create mode 100644 test/integration/targets/nxos_overlay_global/tests/nxapi/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_overlay_global.py b/lib/ansible/modules/network/nxos/nxos_overlay_global.py index 84ded5fbef..2fa3b4b9ed 100644 --- a/lib/ansible/modules/network/nxos/nxos_overlay_global.py +++ b/lib/ansible/modules/network/nxos/nxos_overlay_global.py @@ -95,24 +95,23 @@ def get_commands(module, existing, proposed, candidate): proposed_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, proposed) existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) - for key, value in proposed_commands.items(): - if value == 'default': - existing_value = existing_commands.get(key) - if existing_value: - commands.append('no {0} {1}'.format(key, existing_value)) - else: - if 'anycast-gateway-mac' in key: - value = normalize_mac(value, module) - existing_value = existing_commands.get(key) - if existing_value and value != existing_value: - command = '{0} {1}'.format(key, value) - commands.append(command) - + for key, proposed in proposed_commands.items(): + existing_value = existing_commands.get(key) + if proposed == 'default' and existing_value: + commands.append('no {0} {1}'.format(key, existing_value)) + elif 'anycast-gateway-mac' in key and proposed != 'default': + proposed = normalize_mac(proposed, module) + existing_value = normalize_mac(existing_value, module) + if proposed != existing_value: + command = '{0} {1}'.format(key, proposed) + commands.append(command) if commands: candidate.add(commands, parents=[]) def normalize_mac(proposed_mac, module): + if proposed_mac is None: + return '' try: if '-' in proposed_mac: splitted_mac = proposed_mac.split('-') diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index 1085cc73a2..4b2fbc313c 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -345,6 +345,14 @@ when: "limit_to in ['*', 'nxos_bgp_neighbor_af']" rescue: - set_fact: test_failed=true + + - block: + - include_role: + name: nxos_overlay_global + when: "limit_to in ['*', 'nxos_overlay_global']" + rescue: + - set_fact: test_failed=true + ########### - debug: var=failed_modules when: test_failed diff --git a/test/integration/targets/nxos_interface/tests/common/set_state_present.yaml b/test/integration/targets/nxos_interface/tests/common/set_state_present.yaml index d7a7f71477..017518d562 100644 --- a/test/integration/targets/nxos_interface/tests/common/set_state_present.yaml +++ b/test/integration/targets/nxos_interface/tests/common/set_state_present.yaml @@ -12,6 +12,7 @@ nxos_interface: interface: Loopback1 state: present + description: 'Configured by Ansible - Layer3' provider: "{{ connection }}" register: result @@ -23,6 +24,7 @@ nxos_interface: interface: Loopback1 state: present + description: 'Configured by Ansible - Layer3' provider: "{{ connection }}" register: result diff --git a/test/integration/targets/nxos_overlay_global/defaults/main.yaml b/test/integration/targets/nxos_overlay_global/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_overlay_global/meta/main.yml b/test/integration/targets/nxos_overlay_global/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_overlay_global/tasks/cli.yaml b/test/integration/targets/nxos_overlay_global/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tasks/cli.yaml @@ -0,0 +1,15 @@ +--- +- name: collect all cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_overlay_global/tasks/main.yaml b/test/integration/targets/nxos_overlay_global/tasks/main.yaml new file mode 100644 index 0000000000..fea9337c14 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tasks/main.yaml @@ -0,0 +1,7 @@ +--- +# Use block to ensure that both cli and nxapi tests +# will run even if there are failures or errors. +- block: + - { include: cli.yaml, tags: ['cli'] } + always: + - { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_overlay_global/tasks/nxapi.yaml b/test/integration/targets/nxos_overlay_global/tasks/nxapi.yaml new file mode 100644 index 0000000000..ea525379f7 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tasks/nxapi.yaml @@ -0,0 +1,28 @@ +--- +- name: collect all nxapi test cases + find: + paths: "{{ role_path }}/tests/nxapi" + patterns: "{{ testcase }}.yaml" + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: enable nxapi + nxos_config: + lines: + - feature nxapi + - nxapi http port 80 + provider: "{{ cli }}" + +- name: run test case + include: "{{ test_case_to_run }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + +- name: disable nxapi + nxos_config: + lines: + - no feature nxapi + provider: "{{ cli }}" diff --git a/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml b/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml new file mode 100644 index 0000000000..d5baa44d6b --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml @@ -0,0 +1,24 @@ +--- +- name: "Unconfigure VDC setting limit-resource module-type f3" + nxos_config: + commands: + - 'terminal dont-ask ; vdc {{ vdcid }} ; no limit-resource module-type f3' + match: none + provider: "{{ connection }}" + ignore_errors: yes + +- name: Previous command is asynchronous and can take a while. Allow time for it to complete + pause: + seconds: 45 + +- name: "Configure VDC setting allocate interface unallocated-interfaces" + nxos_config: &allocate + commands: + - 'terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces' + match: none + provider: "{{ connection }}" + ignore_errors: yes + +- name: Previous command is asynchronous can take a while. Allow time for it to complete + pause: + seconds: 45 diff --git a/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml b/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml new file mode 100644 index 0000000000..b6d3f51cae --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml @@ -0,0 +1,40 @@ +--- +- name: "Get default vdc id" + nxos_command: + commands: ['show vdc current-vdc | json'] + provider: "{{ connection }}" + register: vdcout + +- set_fact: vdcid="{{ vdcout.stdout_lines[0].name }}" + +- name: "Configure VDC setting limit-resource module-type f3" + nxos_config: + commands: + - "terminal dont-ask ; vdc {{ vdcid }} ; limit-resource module-type f3" + match: none + provider: "{{ connection }}" + ignore_errors: yes + +- name: Previous command is asynchronous and can take a while. Allow time for it to complete + pause: + seconds: 45 + +- name: "Configure VDC setting allocate interface unallocated-interfaces" + nxos_config: &allocate + commands: + - "terminal dont-ask ; vdc {{ vdcid }} ; allocate interface unallocated-interfaces" + match: none + provider: "{{ connection }}" + ignore_errors: yes + +- name: Previous command is asynchronous and can take a while. Allow time for it to complete + pause: + seconds: 45 + +- name: "Configure Additional N7K requiste features" + nxos_config: + commands: + - feature-set fabric + - feature fabric forwarding + match: none + provider: "{{ connection }}" diff --git a/test/integration/targets/nxos_overlay_global/tests/cli/sanity.yaml b/test/integration/targets/nxos_overlay_global/tests/cli/sanity.yaml new file mode 100644 index 0000000000..420af7420e --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tests/cli/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ cli }}" + +- import_tasks: "{{ role_path }}/tests/common/sanity.yaml" diff --git a/test/integration/targets/nxos_overlay_global/tests/common/sanity.yaml b/test/integration/targets/nxos_overlay_global/tests/common/sanity.yaml new file mode 100644 index 0000000000..a24fe8c163 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tests/common/sanity.yaml @@ -0,0 +1,104 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_overlay_global sanity test" + +- set_fact: overlay_global_supported="false" +- set_fact: overlay_global_supported="true" + when: platform | search("N35NG|N7K|^N9K$") or + (platform | match("N9k-F") and imagetag | version_compare('F3', 'ne')) + +- debug: msg="Platform {{ platform }} running Image version {{ image_version }} supports nxos_overlay_global" + when: overlay_global_supported + +# Setup Block +- block: + - name: "Enable nv overlay evpn" + nxos_evpn_global: &enable_evpn + nv_overlay_evpn: true + provider: "{{ connection }}" + + - name: "Apply N7K specific setup config" + include: targets/nxos_overlay_global/tasks/platform/n7k/setup.yaml + when: platform | match('N7K') + + - name: "Configure Additional N7K requiste features" + nxos_config: + commands: + - feature-set fabric + - feature fabric forwarding + match: none + provider: "{{ connection }}" + when: platform | match('N7K') + + - name: "Remove possibly existing mac" + nxos_overlay_global: + anycast_gateway_mac: "default" + provider: "{{ connection }}" + ignore_errors: yes + + when: overlay_global_supported + +# Test execution block +- block: + + - name: Configure overlay global + nxos_overlay_global: &configure + anycast_gateway_mac: "b.b.b" + provider: "{{ connection }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Check Idempotence" + nxos_overlay_global: *configure + register: result + + - assert: &false + that: + - "result.changed == false" + + - name: Update anycast gateway mac + nxos_overlay_global: &update + anycast_gateway_mac: "a.a.a" + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence" + nxos_overlay_global: *update + register: result + + - assert: *false + + + - name: Remove anycast gateway mac + nxos_overlay_global: &remove + anycast_gateway_mac: "default" + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence" + nxos_overlay_global: *remove + register: result + + - assert: *false + + when: overlay_global_supported + + always: + - name: "Apply N7K specific cleanup config" + include: targets/nxos_overlay_global/tasks/platform/n7k/cleanup.yaml + when: platform | match('N7K') + + - name: "Disable nv overlay evpn" + nxos_evpn_global: &disable_evpn + nv_overlay_evpn: false + provider: "{{ connection }}" + ignore_errors: yes + when: overlay_global_supported + + - debug: msg="END TRANSPORT:{{ connection.transport }} nxos_overlay_global sanity test" diff --git a/test/integration/targets/nxos_overlay_global/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_overlay_global/tests/nxapi/sanity.yaml new file mode 100644 index 0000000000..e30ea6eaf7 --- /dev/null +++ b/test/integration/targets/nxos_overlay_global/tests/nxapi/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ nxapi }}" + +- import_tasks: "{{ role_path }}/tests/common/sanity.yaml" diff --git a/test/integration/targets/prepare_nxos_tests/tasks/main.yml b/test/integration/targets/prepare_nxos_tests/tasks/main.yml index bd9abf9e8f..78e65cb55d 100644 --- a/test/integration/targets/prepare_nxos_tests/tasks/main.yml +++ b/test/integration/targets/prepare_nxos_tests/tasks/main.yml @@ -48,6 +48,15 @@ - set_fact: nxos_int2="{{ intdataraw[2].interface }}" - set_fact: nxos_int3="{{ intdataraw[3].interface }}" +# Get image version information for this device +- name: "Gather image version info" + nxos_command: + commands: ['sh version | json'] + provider: "{{ cli }}" + register: nxos_version_output + +- set_fact: image_version="{{ nxos_version_output.stdout[0]['kickstart_ver_str'] }}" + # Get platform information for this device # # Usage in integration test playbook: @@ -62,6 +71,7 @@ register: nxos_inventory_output - set_fact: platform="{{ nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'][0]['productid'].split('-')[0] }}" +- set_fact: chassis_type="{{ nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'][0]['productid'].split('-')[1] }}" # Check if platform is fretta - set_fact: fretta={% for row in nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'] if 'FM-R' in row['productid'] %}"true"{% endfor %} @@ -74,3 +84,34 @@ # Check if platform is titanium - set_fact: titanium={% for row in nxos_inventory_output.stdout_lines[0]['TABLE_inv']['ROW_inv'] if 'NX-OSv' in row['desc']%}"true"{% endfor %} when: platform | match("N7K") + +# Set platform to N35 for N3k-35xx +- set_fact: platform="N35" + when: (chassis_type | search("C35")) + +# Set platform to N35NG for N3k-35xx running image version +# 7.0(3)I7 or later. NG(Next Gen) +- set_fact: platform="N35NG" + when: (chassis_type | search("C35")) and image_version | search("7.0\(3\)I7") + +# Create matrix of simple keys based on platform +# and image version for use within test playbooks. +- set_fact: imagetag="" +- set_fact: imagetag="I2" + when: image_version | search("7.0\(3\)I2") +- set_fact: imagetag="I3" + when: image_version | search("7.0\(3\)I3") +- set_fact: imagetag="I4" + when: image_version | search("7.0\(3\)I4") +- set_fact: imagetag="I5" + when: image_version | search("7.0\(3\)I5") +- set_fact: imagetag="I6" + when: image_version | search("7.0\(3\)I6") +- set_fact: imagetag="I7" + when: image_version | search("7.0\(3\)I7") +- set_fact: imagetag="F1" + when: image_version | search("7.0\(3\)F1") +- set_fact: imagetag="F2" + when: image_version | search("7.0\(3\)F2") +- set_fact: imagetag="F3" + when: image_version | search("7.0\(3\)F3")