From 0e4a7b0889773f2e77ba628ac062b95e9910065b Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Wed, 12 Dec 2018 10:32:27 -0500 Subject: [PATCH] Fix nxos_reload timeout and add integration tests (#49632) * Fix timeout and add tests * Correct module name --- .../modules/network/nxos/nxos_reboot.py | 10 +++--- .../targets/nxos_reboot/defaults/main.yaml | 2 ++ .../targets/nxos_reboot/meta/main.yml | 2 ++ .../targets/nxos_reboot/tasks/cli.yaml | 27 ++++++++++++++ .../targets/nxos_reboot/tasks/main.yaml | 5 +++ .../targets/nxos_reboot/tasks/nxapi.yaml | 35 +++++++++++++++++++ .../nxos_reboot/tests/common/sanity.yaml | 26 ++++++++++++++ 7 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 test/integration/targets/nxos_reboot/defaults/main.yaml create mode 100644 test/integration/targets/nxos_reboot/meta/main.yml create mode 100644 test/integration/targets/nxos_reboot/tasks/cli.yaml create mode 100644 test/integration/targets/nxos_reboot/tasks/main.yaml create mode 100644 test/integration/targets/nxos_reboot/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_reboot/tests/common/sanity.yaml diff --git a/lib/ansible/modules/network/nxos/nxos_reboot.py b/lib/ansible/modules/network/nxos/nxos_reboot.py index e74c719cba3..6ba5fba96fa 100644 --- a/lib/ansible/modules/network/nxos/nxos_reboot.py +++ b/lib/ansible/modules/network/nxos/nxos_reboot.py @@ -58,17 +58,15 @@ rebooted: sample: true ''' -from ansible.module_utils.network.nxos.nxos import run_commands +from ansible.module_utils.network.nxos.nxos import load_config from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule def reboot(module): - cmds = [ - {'command': 'terminal dont-ask', 'output': 'text'}, - {'command': 'reload', 'output': 'text'} - ] - run_commands(module, cmds) + cmds = 'terminal dont-ask ; reload' + opts = {'ignore_timeout': True} + load_config(module, cmds, False, opts) def main(): diff --git a/test/integration/targets/nxos_reboot/defaults/main.yaml b/test/integration/targets/nxos_reboot/defaults/main.yaml new file mode 100644 index 00000000000..5f709c5aac1 --- /dev/null +++ b/test/integration/targets/nxos_reboot/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/nxos_reboot/meta/main.yml b/test/integration/targets/nxos_reboot/meta/main.yml new file mode 100644 index 00000000000..ae741cbdc71 --- /dev/null +++ b/test/integration/targets/nxos_reboot/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_reboot/tasks/cli.yaml b/test/integration/targets/nxos_reboot/tasks/cli.yaml new file mode 100644 index 00000000000..9b62eaba65e --- /dev/null +++ b/test/integration/targets/nxos_reboot/tasks/cli.yaml @@ -0,0 +1,27 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: collect cli test cases + find: + paths: "{{ role_path }}/tests/cli" + patterns: "{{ testcase }}.yaml" + connection: local + register: cli_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ cli_cases.files }}" + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli connection={{ cli }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_reboot/tasks/main.yaml b/test/integration/targets/nxos_reboot/tasks/main.yaml new file mode 100644 index 00000000000..066027891a3 --- /dev/null +++ b/test/integration/targets/nxos_reboot/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- include: cli.yaml + tags: cli +- include: nxapi.yaml + tags: nxapi diff --git a/test/integration/targets/nxos_reboot/tasks/nxapi.yaml b/test/integration/targets/nxos_reboot/tasks/nxapi.yaml new file mode 100644 index 00000000000..7401584edf5 --- /dev/null +++ b/test/integration/targets/nxos_reboot/tasks/nxapi.yaml @@ -0,0 +1,35 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: collect nxapi test cases + find: + paths: "{{ role_path }}/tests/nxapi" + patterns: "{{ testcase }}.yaml" + connection: local + register: nxapi_cases + +- set_fact: + test_cases: + files: "{{ test_cases.files }} + {{ nxapi_cases.files }}" + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (connection=httpapi) + include: "{{ test_case_to_run }} ansible_connection=httpapi connection={{ nxapi }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + tags: nxapi_httpapi + +- name: run test cases (connection=local) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run + tags: nxapi_local diff --git a/test/integration/targets/nxos_reboot/tests/common/sanity.yaml b/test/integration/targets/nxos_reboot/tests/common/sanity.yaml new file mode 100644 index 00000000000..f7c73b28bf0 --- /dev/null +++ b/test/integration/targets/nxos_reboot/tests/common/sanity.yaml @@ -0,0 +1,26 @@ +--- +- debug: msg="START connection={{ ansible_connection }} nxos_reboot sanity test" +- debug: msg="Using provider={{ connection.transport }}" + when: ansible_connection == "local" + +- debug: msg="***WARNING*** Remove meta end_play to verify this module ***WARNING***" + +- meta: end_play + +- block: + - name: Reboot Switch + nxos_reboot: + confirm: True + provider: "{{ connection }}" + ignore_errors: yes + + always: + - name: Wait for device to come back up + wait_for: + port: 22 + state: started + timeout: 600 + delay: 60 + host: "{{ inventory_hostname }}" + + - debug: msg="END connection={{ ansible_connection }} nxos_reboot sanity test"