From 65cf31e1cea08f5d6e4bba0609f564e65d5ae79c Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Mon, 7 Aug 2017 13:54:31 -0400 Subject: [PATCH] Fix nxos_interface_ospf idempotence issue (#27783) * Add tests and fix 27167 * Add modify test --- .../network/nxos/nxos_interface_ospf.py | 7 ++ test/integration/nxos.yaml | 9 ++ .../nxos_interface_ospf/defaults/main.yaml | 2 + .../targets/nxos_interface_ospf/meta/main.yml | 2 + .../nxos_interface_ospf/tasks/cli.yaml | 15 +++ .../nxos_interface_ospf/tasks/main.yaml | 7 ++ .../nxos_interface_ospf/tasks/nxapi.yaml | 28 +++++ .../nxos_interface_ospf/tests/cli/sanity.yaml | 4 + .../tests/common/sanity.yaml | 119 ++++++++++++++++++ .../tests/nxapi/sanity.yaml | 4 + 10 files changed, 197 insertions(+) create mode 100644 test/integration/targets/nxos_interface_ospf/defaults/main.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/meta/main.yml create mode 100644 test/integration/targets/nxos_interface_ospf/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/tasks/main.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml create mode 100644 test/integration/targets/nxos_interface_ospf/tests/nxapi/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_interface_ospf.py b/lib/ansible/modules/network/nxos/nxos_interface_ospf.py index b0ef81299fb..c1ccda9a20f 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface_ospf.py +++ b/lib/ansible/modules/network/nxos/nxos_interface_ospf.py @@ -285,6 +285,13 @@ def state_present(module, existing, proposed, candidate): existing_commands = apply_key_map(PARAM_TO_COMMAND_KEYMAP, existing) for key, value in proposed_commands.items(): + if existing_commands.get(key): + if key == 'ip router ospf': + if proposed['area'] == existing['area']: + continue + if existing_commands[key] == proposed_commands[key]: + continue + if value is True: commands.append(key) elif value is False: diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index ef0b0aa4b7e..64d0631b3b1 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -240,6 +240,15 @@ failed_modules: "{{ failed_modules }} + [ 'nxos_vxlan_vtep' ]" test_failed: true + - block: + - include_role: + name: nxos_interface_ospf + when: "limit_to in ['*', 'nxos_interface_ospf']" + rescue: + - set_fact: + failed_modules: "{{ failed_modules }} + [ 'nxos_interface_ospf' ]" + test_failed: true + - block: - include_role: name: nxos_logging diff --git a/test/integration/targets/nxos_interface_ospf/defaults/main.yaml b/test/integration/targets/nxos_interface_ospf/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_interface_ospf/meta/main.yml b/test/integration/targets/nxos_interface_ospf/meta/main.yml new file mode 100644 index 00000000000..ae741cbdc71 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_interface_ospf/tasks/cli.yaml b/test/integration/targets/nxos_interface_ospf/tasks/cli.yaml new file mode 100644 index 00000000000..d675462dd02 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/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_interface_ospf/tasks/main.yaml b/test/integration/targets/nxos_interface_ospf/tasks/main.yaml new file mode 100644 index 00000000000..fea9337c14c --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/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_interface_ospf/tasks/nxapi.yaml b/test/integration/targets/nxos_interface_ospf/tasks/nxapi.yaml new file mode 100644 index 00000000000..ea525379f7f --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/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_interface_ospf/tests/cli/sanity.yaml b/test/integration/targets/nxos_interface_ospf/tests/cli/sanity.yaml new file mode 100644 index 00000000000..420af7420e9 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/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_interface_ospf/tests/common/sanity.yaml b/test/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml new file mode 100644 index 00000000000..9315fc102a8 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/tests/common/sanity.yaml @@ -0,0 +1,119 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_interface_ospf sanity test" + +- set_fact: testint="{{ nxos_int1 }}" + +- name: "Setup - Disable feature OSPF" + nxos_feature: &disable + feature: ospf + state: disabled + provider: "{{ connection }}" + ignore_errors: yes + +- name: "Setup - Enable feature OSPF" + nxos_feature: &enable + feature: ospf + state: enabled + provider: "{{ connection }}" + ignore_errors: yes + +- name: "Put interface into default state" + nxos_config: &intdefault + lines: + - "default interface {{ testint }}" + provider: "{{ connection }}" + ignore_errors: yes + +- name: "Remove switchport config" + nxos_config: &removeswitchport + commands: + - no switchport + parents: + - "interface {{ testint }}" + provider: "{{ connection }}" + ignore_errors: yes + +- block: + - name: configure ospf interface + nxos_interface_ospf: &configure + interface: "{{ testint }}" + ospf: 1 + area: 1 + cost: 55 + passive_interface: true + hello_interval: 15 + dead_interval: 75 + state: present + provider: "{{ connection }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Check Idempotence" + nxos_interface_ospf: *configure + register: result + + - assert: &false + that: + - "result.changed == false" + + - name: Modify properties + nxos_interface_ospf: &modify + interface: "{{ testint }}" + ospf: 1 + area: 1 + cost: 66 + passive_interface: false + hello_interval: 17 + dead_interval: 70 + state: present + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence" + nxos_interface_ospf: *modify + register: result + + - assert: *false + + - name: remove ospf interface config + nxos_interface_ospf: &removeconfig + interface: "{{ testint }}" + ospf: 1 + area: 1 + cost: 55 + passive_interface: true + hello_interval: 15 + dead_interval: 75 + state: absent + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence" + nxos_interface_ospf: *removeconfig + register: result + + - assert: *false + + - name: "Disable feature OSPF" + nxos_feature: *disable + ignore_errors: yes + + - name: "Interface cleanup" + nxos_config: *intdefault + + rescue: + - name: "Disable feature OSPF" + nxos_feature: *disable + + - name: "Interface cleanup" + nxos_config: *intdefault + + always: + - debug: msg="END TRANSPORT:{{ connection.transport }} nxos_interface_ospf sanity test" diff --git a/test/integration/targets/nxos_interface_ospf/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_interface_ospf/tests/nxapi/sanity.yaml new file mode 100644 index 00000000000..e30ea6eaf70 --- /dev/null +++ b/test/integration/targets/nxos_interface_ospf/tests/nxapi/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ nxapi }}" + +- import_tasks: "{{ role_path }}/tests/common/sanity.yaml"