From 8a6d69919863c2b1583da03e91e1c2108cde892c Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Thu, 18 Jan 2018 11:50:15 +0530 Subject: [PATCH] Enable nxapi nxos_banner test (#35033) Signed-off-by: Trishna Guha --- .../modules/network/nxos/nxos_banner.py | 12 +++++-- .../targets/nxos_banner/tasks/main.yaml | 2 +- .../tests/{common => cli}/basic-exec.yaml | 17 +++++----- .../tests/{common => cli}/basic-motd.yaml | 16 ++++++---- .../tests/{common => cli}/basic-no-motd.yaml | 10 +++--- .../nxos_banner/tests/nxapi/basic-exec.yaml | 32 +++++++++++++++++++ .../nxos_banner/tests/nxapi/basic-motd.yaml | 29 +++++++++++++++++ .../tests/nxapi/basic-no-motd.yaml | 25 +++++++++++++++ 8 files changed, 119 insertions(+), 24 deletions(-) rename test/integration/targets/nxos_banner/tests/{common => cli}/basic-exec.yaml (68%) rename test/integration/targets/nxos_banner/tests/{common => cli}/basic-motd.yaml (66%) rename test/integration/targets/nxos_banner/tests/{common => cli}/basic-no-motd.yaml (70%) create mode 100644 test/integration/targets/nxos_banner/tests/nxapi/basic-exec.yaml create mode 100644 test/integration/targets/nxos_banner/tests/nxapi/basic-motd.yaml create mode 100644 test/integration/targets/nxos_banner/tests/nxapi/basic-no-motd.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_banner.py b/lib/ansible/modules/network/nxos/nxos_banner.py index b17ebf3dda..cbf61122d9 100644 --- a/lib/ansible/modules/network/nxos/nxos_banner.py +++ b/lib/ansible/modules/network/nxos/nxos_banner.py @@ -117,9 +117,17 @@ def map_config_to_obj(module): module.fail_json(msg="banner: exec may not be supported on this platform. Possible values are : exec | motd") if isinstance(output, dict): - output = list(output.values())[0] + output = list(output.values()) + if output != []: + output = output[0] + else: + output = '' if isinstance(output, dict): - output = list(output.values())[0] + output = list(output.values()) + if output != []: + output = output[0] + else: + output = '' obj = {'banner': module.params['banner'], 'state': 'absent'} if output: diff --git a/test/integration/targets/nxos_banner/tasks/main.yaml b/test/integration/targets/nxos_banner/tasks/main.yaml index f9482f77cf..4b0f8c64d9 100644 --- a/test/integration/targets/nxos_banner/tasks/main.yaml +++ b/test/integration/targets/nxos_banner/tasks/main.yaml @@ -1,3 +1,3 @@ --- - { include: cli.yaml, tags: ['cli'] } -#- { include: nxapi.yaml, tags: ['nxapi'] } +- { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_banner/tests/common/basic-exec.yaml b/test/integration/targets/nxos_banner/tests/cli/basic-exec.yaml similarity index 68% rename from test/integration/targets/nxos_banner/tests/common/basic-exec.yaml rename to test/integration/targets/nxos_banner/tests/cli/basic-exec.yaml index 978f3892a9..f795df3f58 100644 --- a/test/integration/targets/nxos_banner/tests/common/basic-exec.yaml +++ b/test/integration/targets/nxos_banner/tests/cli/basic-exec.yaml @@ -1,12 +1,12 @@ --- -- debug: msg="START nxos_banner exec test" +- debug: msg="START cli/nxos_banner exec test" - block: - name: setup - remove exec - nxos_banner: + nxos_banner: &remove banner: exec state: absent - provider: "{{ connection }}" + provider: "{{ cli }}" - name: Set exec nxos_banner: &exec @@ -16,7 +16,7 @@ that has a multiline string state: present - provider: "{{ connection }}" + provider: "{{ cli }}" register: result - assert: @@ -33,10 +33,9 @@ - "result.changed == false" - "result.commands | length == 0" + - name: teardown - remove exec + nxos_banner: *remove + when: platform is match("N7K") -- debug: msg="END nxos_banner exec test" - -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" +- debug: msg="END cli/nxos_banner exec test" diff --git a/test/integration/targets/nxos_banner/tests/common/basic-motd.yaml b/test/integration/targets/nxos_banner/tests/cli/basic-motd.yaml similarity index 66% rename from test/integration/targets/nxos_banner/tests/common/basic-motd.yaml rename to test/integration/targets/nxos_banner/tests/cli/basic-motd.yaml index 9a207f8b4b..18121ba3a6 100644 --- a/test/integration/targets/nxos_banner/tests/common/basic-motd.yaml +++ b/test/integration/targets/nxos_banner/tests/cli/basic-motd.yaml @@ -1,9 +1,11 @@ --- +- debug: msg="START cli/nxos_banner motd test" + - name: setup - remove motd - nxos_banner: + nxos_banner: &remove banner: motd state: absent - provider: "{{ connection }}" + provider: "{{ cli }}" - name: Set motd nxos_banner: &motd @@ -13,7 +15,7 @@ that has a multiline string state: present - provider: "{{ connection }}" + provider: "{{ cli }}" register: result - assert: @@ -28,8 +30,8 @@ - assert: that: - "result.changed == false" - - "result.commands | length == 0" -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" +- name: teardown - remove motd + nxos_banner: *remove + +- debug: msg="END cli/nxos_banner motd test" diff --git a/test/integration/targets/nxos_banner/tests/common/basic-no-motd.yaml b/test/integration/targets/nxos_banner/tests/cli/basic-no-motd.yaml similarity index 70% rename from test/integration/targets/nxos_banner/tests/common/basic-no-motd.yaml rename to test/integration/targets/nxos_banner/tests/cli/basic-no-motd.yaml index b7c9fbfc99..8f4368c229 100644 --- a/test/integration/targets/nxos_banner/tests/common/basic-no-motd.yaml +++ b/test/integration/targets/nxos_banner/tests/cli/basic-no-motd.yaml @@ -1,4 +1,6 @@ --- +- debug: msg="START cli/nxos_banner no-motd test" + - name: Setup nxos_banner: banner: motd @@ -6,13 +8,13 @@ Junk motd banner over multiple lines state: present - provider: "{{ connection }}" + provider: "{{ cli }}" - name: remove motd nxos_banner: &rm-motd banner: motd state: absent - provider: "{{ connection }}" + provider: "{{ cli }}" register: result - assert: @@ -29,6 +31,4 @@ - "result.changed == false" - "result.commands | length == 0" -# FIXME add in tests for everything defined in docs -# FIXME Test state:absent + test: -# FIXME Without powers ensure "privileged mode required" +- debug: msg="END cli/nxos_banner no-motd test" diff --git a/test/integration/targets/nxos_banner/tests/nxapi/basic-exec.yaml b/test/integration/targets/nxos_banner/tests/nxapi/basic-exec.yaml new file mode 100644 index 0000000000..8ecc7f06a9 --- /dev/null +++ b/test/integration/targets/nxos_banner/tests/nxapi/basic-exec.yaml @@ -0,0 +1,32 @@ +--- +- debug: msg="START nxapi/nxos_banner exec test" + +- block: + - name: setup - remove exec + nxos_banner: &remove + banner: exec + state: absent + provider: "{{ nxapi }}" + + - name: Set exec + nxos_banner: &exec + banner: exec + text: | + this is my exec banner + that has a multiline + string + state: present + provider: "{{ nxapi }}" + register: result + + - assert: + that: + - "result.changed == true" + - "'banner exec @\nthis is my exec banner\nthat has a multiline\nstring\n@' in result.commands" + + - name: teardown - remove exec + nxos_banner: *remove + + when: platform is match("N7K") + +- debug: msg="END nxapi/nxos_banner exec test" diff --git a/test/integration/targets/nxos_banner/tests/nxapi/basic-motd.yaml b/test/integration/targets/nxos_banner/tests/nxapi/basic-motd.yaml new file mode 100644 index 0000000000..ac94103f24 --- /dev/null +++ b/test/integration/targets/nxos_banner/tests/nxapi/basic-motd.yaml @@ -0,0 +1,29 @@ +--- +- debug: msg="START nxapi/nxos_banner motd test" + +- name: setup - remove motd + nxos_banner: &remove + banner: motd + state: absent + provider: "{{ nxapi }}" + +- name: Set motd + nxos_banner: &motd + banner: motd + text: | + this is my motd banner + that has a multiline + string + state: present + provider: "{{ nxapi }}" + register: result + +- assert: + that: + - "result.changed == true" + - "'banner motd @\nthis is my motd banner\nthat has a multiline\nstring\n@' in result.commands" + +- name: teardown - remove motd + nxos_banner: *remove + +- debug: msg="END nxapi/nxos_banner motd test" diff --git a/test/integration/targets/nxos_banner/tests/nxapi/basic-no-motd.yaml b/test/integration/targets/nxos_banner/tests/nxapi/basic-no-motd.yaml new file mode 100644 index 0000000000..69072f24cc --- /dev/null +++ b/test/integration/targets/nxos_banner/tests/nxapi/basic-no-motd.yaml @@ -0,0 +1,25 @@ +--- +- debug: msg="START nxapi/nxos_banner no-motd test" + +- name: Setup + nxos_banner: + banner: motd + text: | + Junk motd banner + over multiple lines + state: present + provider: "{{ nxapi }}" + +- name: remove motd + nxos_banner: &rm-motd + banner: motd + state: absent + provider: "{{ nxapi }}" + register: result + +- assert: + that: + - "result.changed == true" + - "'no banner motd' in result.commands" + +- debug: msg="END nxapi/nxos_banner no-motd test"