From d69440c4efb73fd0dbcd3f788e22f98bf0e5b70f Mon Sep 17 00:00:00 2001 From: saichint Date: Tue, 15 Aug 2017 09:08:55 -0700 Subject: [PATCH] Fix nxos_vpc issues (#28188) * fix for nxos_vpc issues * fix unit tests * clean documentation --- lib/ansible/modules/network/nxos/nxos_vpc.py | 13 +-- test/integration/nxos.yaml | 9 +++ .../targets/nxos_vpc/defaults/main.yaml | 2 + .../targets/nxos_vpc/meta/main.yml | 2 + .../targets/nxos_vpc/tasks/cli.yaml | 15 ++++ .../targets/nxos_vpc/tasks/main.yaml | 7 ++ .../targets/nxos_vpc/tasks/nxapi.yaml | 28 +++++++ .../targets/nxos_vpc/tests/cli/sanity.yaml | 4 + .../targets/nxos_vpc/tests/common/sanity.yaml | 81 +++++++++++++++++++ .../targets/nxos_vpc/tests/nxapi/sanity.yaml | 4 + .../modules/network/nxos/test_nxos_vpc.py | 2 +- 11 files changed, 157 insertions(+), 10 deletions(-) create mode 100644 test/integration/targets/nxos_vpc/defaults/main.yaml create mode 100644 test/integration/targets/nxos_vpc/meta/main.yml create mode 100644 test/integration/targets/nxos_vpc/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_vpc/tasks/main.yaml create mode 100644 test/integration/targets/nxos_vpc/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_vpc/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_vpc/tests/common/sanity.yaml create mode 100644 test/integration/targets/nxos_vpc/tests/nxapi/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_vpc.py b/lib/ansible/modules/network/nxos/nxos_vpc.py index 4a77a409b1..fbe7ba71e9 100644 --- a/lib/ansible/modules/network/nxos/nxos_vpc.py +++ b/lib/ansible/modules/network/nxos/nxos_vpc.py @@ -105,14 +105,6 @@ EXAMPLES = ''' peer_gw: true auto_recovery: true -# peer-gateway might ask for confirmation to apply changes -# Device should be configured with terminal dont-ask that makes -# the device take default answer on confirmation prompt - -- name: Make device take default answer - nxos_command: - commands: terminal dont-ask - - name: configure nxos_vpc: domain: 100 @@ -196,7 +188,7 @@ def get_vpc(module): for each in vpc_list: if 'delay restore' in each: line = each.split() - if len(line) == 5: + if len(line) == 3: delay_restore = line[-1] if 'peer-keepalive destination' in each: line = each.split() @@ -283,6 +275,8 @@ def get_commands_to_config_vpc(module, vpc, domain, existing): command = CONFIG_ARGS.get(param) if command is not None: command = command.format(**vpc).strip() + if 'peer-gateway' in command: + commands.append('terminal dont-ask') commands.append(command) if commands or domain_only: @@ -370,6 +364,7 @@ def main(): module.fail_json(msg="You are trying to remove a domain that " "does not exist on the device") else: + commands.append('terminal dont-ask') commands.append('no vpc domain {0}'.format(domain)) cmds = flatten_list(commands) diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index e76ae25755..f9b804ab6e 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -168,6 +168,15 @@ failed_modules: "{{ failed_modules }} + [ 'nxos_vrrp' ]" test_failed: true + - block: + - include_role: + name: nxos_vpc + when: "limit_to in ['*', 'nxos_vpc']" + rescue: + - set_fact: + failed_modules: "{{ failed_modules }} + [ 'nxos_vpc' ]" + test_failed: true + - block: - include_role: name: nxos_vtp_domain diff --git a/test/integration/targets/nxos_vpc/defaults/main.yaml b/test/integration/targets/nxos_vpc/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/nxos_vpc/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_vpc/meta/main.yml b/test/integration/targets/nxos_vpc/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_vpc/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_vpc/tasks/cli.yaml b/test/integration/targets/nxos_vpc/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/nxos_vpc/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_vpc/tasks/main.yaml b/test/integration/targets/nxos_vpc/tasks/main.yaml new file mode 100644 index 0000000000..fea9337c14 --- /dev/null +++ b/test/integration/targets/nxos_vpc/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_vpc/tasks/nxapi.yaml b/test/integration/targets/nxos_vpc/tasks/nxapi.yaml new file mode 100644 index 0000000000..ea525379f7 --- /dev/null +++ b/test/integration/targets/nxos_vpc/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_vpc/tests/cli/sanity.yaml b/test/integration/targets/nxos_vpc/tests/cli/sanity.yaml new file mode 100644 index 0000000000..c1cb1acb1a --- /dev/null +++ b/test/integration/targets/nxos_vpc/tests/cli/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ cli }}" + +- import_tasks: targets/nxos_vpc/tests/common/sanity.yaml diff --git a/test/integration/targets/nxos_vpc/tests/common/sanity.yaml b/test/integration/targets/nxos_vpc/tests/common/sanity.yaml new file mode 100644 index 0000000000..f67b659874 --- /dev/null +++ b/test/integration/targets/nxos_vpc/tests/common/sanity.yaml @@ -0,0 +1,81 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_vpc sanity test" + +- block: + - name: enable feature vpc + nxos_feature: + feature: vpc + state: enabled + provider: "{{ connection }}" + + - name: Ensure ntc VRF exists on switch + nxos_vrf: + vrf: ntc + provider: "{{ connection }}" + + - name: Configure vpc + nxos_vpc: &conf_vpc + state: present + domain: 100 + role_priority: 500 + system_priority: 2000 + pkl_dest: 192.168.100.4 + pkl_src: 10.1.100.20 + pkl_vrf: ntc + peer_gw: true + delay_restore: 5 + auto_recovery: true + provider: "{{ connection }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Conf Idempotence" + nxos_vpc: *conf_vpc + register: result + + - assert: &false + that: + - "result.changed == false" + + - name: remove vpc + nxos_vpc: &rem_vpc + state: absent + domain: 100 + role_priority: 32667 + system_priority: 2000 + pkl_dest: 192.168.100.4 + pkl_src: 10.1.100.20 + pkl_vrf: ntc + peer_gw: true + delay_restore: 5 + auto_recovery: false + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Remove Idempotence" + nxos_vpc: *rem_vpc + register: result + + - assert: *false + + always: + - name: remove vrf + nxos_vrf: + vrf: ntc + state: absent + provider: "{{ connection }}" + ignore_errors: yes + + - name: disable feature vpc + nxos_feature: + feature: vpc + state: disabled + provider: "{{ connection }}" + ignore_errors: yes + +- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_vpc sanity test" diff --git a/test/integration/targets/nxos_vpc/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_vpc/tests/nxapi/sanity.yaml new file mode 100644 index 0000000000..d04b6a422b --- /dev/null +++ b/test/integration/targets/nxos_vpc/tests/nxapi/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ nxapi }}" + +- import_tasks: targets/nxos_vpc/tests/common/sanity.yaml diff --git a/test/units/modules/network/nxos/test_nxos_vpc.py b/test/units/modules/network/nxos/test_nxos_vpc.py index 9944788c1b..4e658a22a9 100644 --- a/test/units/modules/network/nxos/test_nxos_vpc.py +++ b/test/units/modules/network/nxos/test_nxos_vpc.py @@ -59,7 +59,7 @@ class TestNxosVpcModule(TestNxosModule): pkl_dest='192.168.100.4', pkl_src='10.1.100.20', peer_gw=True, auto_recovery=True)) self.execute_module(changed=True, commands=[ - 'vpc domain 100', 'role priority 32667', 'system-priority 2000', + 'vpc domain 100', 'terminal dont-ask', 'role priority 32667', 'system-priority 2000', 'peer-keepalive destination 192.168.100.4 source 10.1.100.20 vrf management', 'peer-gateway', 'auto-recovery', ])