From 74947168e378739f450017b5c38bdcbc6a02295b Mon Sep 17 00:00:00 2001 From: rahushen Date: Wed, 12 Jul 2017 13:19:02 -0400 Subject: [PATCH] Add nxos_command IT and generalize UT (#26617) * Add nxos_command IT sanity * generalize nxos_command UT for different NXOS platforms --- .../nxos_command/tests/cli/sanity.yaml | 74 +++++++++++++++++++ .../nxos_command/tests/nxapi/sanity.yaml | 74 +++++++++++++++++++ .../modules/network/nxos/test_nxos_command.py | 4 +- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 test/integration/targets/nxos_command/tests/cli/sanity.yaml create mode 100644 test/integration/targets/nxos_command/tests/nxapi/sanity.yaml diff --git a/test/integration/targets/nxos_command/tests/cli/sanity.yaml b/test/integration/targets/nxos_command/tests/cli/sanity.yaml new file mode 100644 index 00000000000..f5e60f8e024 --- /dev/null +++ b/test/integration/targets/nxos_command/tests/cli/sanity.yaml @@ -0,0 +1,74 @@ +--- +- debug: msg="START TRANSPORT:CLI nxos_command sanity test" + +- name: "Disable feature BGP" + nxos_feature: + feature: bgp + state: disabled + provider: "{{ cli }}" + +- block: + - name: "Run show running-config bgp - should fail" + nxos_command: + commands: + - sh running-config bgp + provider: "{{ cli }}" + ignore_errors: yes + register: result + + - assert: &fail + that: + - "result.failed == true" + - "'Invalid command' in result.msg" + + - name: "Enable feature BGP" + nxos_feature: + feature: bgp + state: enabled + provider: "{{ cli }}" + + - name: "Configure BGP defaults" + nxos_bgp: &configure_default + asn: 65535 + router_id: 1.1.1.1 + state: present + provider: "{{ cli }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Run show running-config bgp - should pass" + nxos_command: + commands: + - sh running-config bgp + provider: "{{ cli }}" + register: result + + - assert: + that: + - "result.failed == false" + - "'65535' in result.stdout[0]" + + - name: "Run an invalid command - should fail" + nxos_command: + commands: + - show interface bief + provider: "{{ cli }}" + ignore_errors: yes + register: result + + - assert: *fail + + rescue: + - debug: msg="nxos_command sanity test failure detected" + + always: + - name: "Disable feature bgp" + nxos_feature: + feature: bgp + state: disabled + provider: "{{ cli }}" + + - debug: msg="END TRANSPORT:CLI nxos_command sanity test" diff --git a/test/integration/targets/nxos_command/tests/nxapi/sanity.yaml b/test/integration/targets/nxos_command/tests/nxapi/sanity.yaml new file mode 100644 index 00000000000..47e3cce0f85 --- /dev/null +++ b/test/integration/targets/nxos_command/tests/nxapi/sanity.yaml @@ -0,0 +1,74 @@ +--- +- debug: msg="START TRANSPORT:NXAPI nxos_command sanity test" + +- name: "Disable feature BGP" + nxos_feature: + feature: bgp + state: disabled + provider: "{{ nxapi }}" + +- block: + - name: "Run show running-config bgp - should fail" + nxos_command: + commands: + - sh running-config bgp + provider: "{{ nxapi }}" + ignore_errors: yes + register: result + + - assert: &fail + that: + - "result.failed == true" + - "'Input CLI command error' in result.msg" + + - name: "Enable feature BGP" + nxos_feature: + feature: bgp + state: enabled + provider: "{{ nxapi }}" + + - name: "Configure BGP defaults" + nxos_bgp: &configure_default + asn: 65535 + router_id: 1.1.1.1 + state: present + provider: "{{ nxapi }}" + register: result + + - assert: &true + that: + - "result.changed == true" + + - name: "Run show running-config bgp - should pass" + nxos_command: + commands: + - sh running-config bgp + provider: "{{ nxapi }}" + register: result + + - assert: + that: + - "result.failed == false" + - "'65535' in result.stdout[0]" + + - name: "Run an invalid command - should fail" + nxos_command: + commands: + - show interface bief + provider: "{{ nxapi }}" + ignore_errors: yes + register: result + + - assert: *fail + + rescue: + - debug: msg="nxos_command sanity test failure detected" + + always: + - name: "Disable feature bgp" + nxos_feature: + feature: bgp + state: disabled + provider: "{{ nxapi }}" + + - debug: msg="END TRANSPORT:NXAPI nxos_command sanity test" diff --git a/test/units/modules/network/nxos/test_nxos_command.py b/test/units/modules/network/nxos/test_nxos_command.py index fac4604f05d..ee073ac0038 100644 --- a/test/units/modules/network/nxos/test_nxos_command.py +++ b/test/units/modules/network/nxos/test_nxos_command.py @@ -67,7 +67,7 @@ class TestNxosCommandModule(TestNxosModule): self.assertTrue(result['stdout'][0].startswith('Cisco')) def test_nxos_command_wait_for(self): - wait_for = 'result[0] contains "Cisco NX-OS"' + wait_for = 'result[0] contains "NX-OS"' set_module_args(dict(commands=['show version'], wait_for=wait_for)) self.execute_module() @@ -91,7 +91,7 @@ class TestNxosCommandModule(TestNxosModule): def test_nxos_command_match_all(self): wait_for = ['result[0] contains "Cisco"', - 'result[0] contains "system image file"'] + 'result[0] contains "image file"'] set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all')) self.execute_module()