diff options
10 files changed, 127 insertions, 1 deletions
diff --git a/lib/ansible/modules/network/nxos/nxos_ospf.py b/lib/ansible/modules/network/nxos/nxos_ospf.py index 6fb4f7091a..47a71c36bd 100644 --- a/lib/ansible/modules/network/nxos/nxos_ospf.py +++ b/lib/ansible/modules/network/nxos/nxos_ospf.py @@ -139,7 +139,7 @@ def main(): existing_list = existing['ospf'] candidate = CustomNetworkConfig(indent=3) - if state == 'present': + if state == 'present' and ospf not in existing_list: state_present(module, proposed, candidate) if state == 'absent' and ospf in existing_list: state_absent(module, proposed, candidate) diff --git a/test/integration/nxos.yaml b/test/integration/nxos.yaml index 64d0631b3b..00358b57e9 100644 --- a/test/integration/nxos.yaml +++ b/test/integration/nxos.yaml @@ -242,6 +242,15 @@ - block: - include_role: + name: nxos_ospf + when: "limit_to in ['*', 'nxos_ospf']" + rescue: + - set_fact: + failed_modules: "{{ failed_modules }} + [ 'nxos_ospf' ]" + test_failed: true + + - block: + - include_role: name: nxos_interface_ospf when: "limit_to in ['*', 'nxos_interface_ospf']" rescue: diff --git a/test/integration/targets/nxos_ospf/defaults/main.yaml b/test/integration/targets/nxos_ospf/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/nxos_ospf/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_ospf/meta/main.yml b/test/integration/targets/nxos_ospf/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_ospf/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_ospf/tasks/cli.yaml b/test/integration/targets/nxos_ospf/tasks/cli.yaml new file mode 100644 index 0000000000..d675462dd0 --- /dev/null +++ b/test/integration/targets/nxos_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_ospf/tasks/main.yaml b/test/integration/targets/nxos_ospf/tasks/main.yaml new file mode 100644 index 0000000000..fea9337c14 --- /dev/null +++ b/test/integration/targets/nxos_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_ospf/tasks/nxapi.yaml b/test/integration/targets/nxos_ospf/tasks/nxapi.yaml new file mode 100644 index 0000000000..ea525379f7 --- /dev/null +++ b/test/integration/targets/nxos_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_ospf/tests/cli/sanity.yaml b/test/integration/targets/nxos_ospf/tests/cli/sanity.yaml new file mode 100644 index 0000000000..f207b01258 --- /dev/null +++ b/test/integration/targets/nxos_ospf/tests/cli/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ cli }}" + +- import_tasks: targets/nxos_ospf/tests/common/sanity.yaml diff --git a/test/integration/targets/nxos_ospf/tests/common/sanity.yaml b/test/integration/targets/nxos_ospf/tests/common/sanity.yaml new file mode 100644 index 0000000000..a07cf1abe1 --- /dev/null +++ b/test/integration/targets/nxos_ospf/tests/common/sanity.yaml @@ -0,0 +1,55 @@ +--- +- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_ospf sanity test" + +- name: "Enable feature OSPF" + nxos_feature: + feature: ospf + state: enabled + provider: "{{ connection }}" + ignore_errors: yes + +- block: + - name: Configure ospf + nxos_ospf: &config + ospf: 1 + state: present + provider: "{{ connection }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Check Idempotence" + nxos_ospf: *config + register: result + + - assert: &false + that: + - "result.changed == false" + + rescue: + - name: "Disable feature OSPF" + nxos_feature: + feature: ospf + state: disabled + provider: "{{ connection }}" + ignore_errors: yes + + always: + - name: Unconfigure ospf + nxos_ospf: &unconfig + ospf: 1 + state: absent + provider: "{{ connection }}" + register: result + + - assert: *true + + - name: "Check Idempotence" + nxos_ospf: *unconfig + register: result + + - assert: *false + + - debug: msg="END TRANSPORT:{{ connection.transport }} nxos_ospf sanity test" diff --git a/test/integration/targets/nxos_ospf/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_ospf/tests/nxapi/sanity.yaml new file mode 100644 index 0000000000..15af0691a9 --- /dev/null +++ b/test/integration/targets/nxos_ospf/tests/nxapi/sanity.yaml @@ -0,0 +1,4 @@ +--- +- set_fact: connection="{{ nxapi }}" + +- import_tasks: targets/nxos_ospf/tests/common/sanity.yaml |