mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix nxos_reload timeout and add integration tests (#49632)
* Fix timeout and add tests * Correct module name
This commit is contained in:
parent
b47cde9d4c
commit
0e4a7b0889
7 changed files with 101 additions and 6 deletions
|
@ -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():
|
||||
|
|
2
test/integration/targets/nxos_reboot/defaults/main.yaml
Normal file
2
test/integration/targets/nxos_reboot/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
2
test/integration/targets/nxos_reboot/meta/main.yml
Normal file
2
test/integration/targets/nxos_reboot/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nxos_tests
|
27
test/integration/targets/nxos_reboot/tasks/cli.yaml
Normal file
27
test/integration/targets/nxos_reboot/tasks/cli.yaml
Normal file
|
@ -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
|
5
test/integration/targets/nxos_reboot/tasks/main.yaml
Normal file
5
test/integration/targets/nxos_reboot/tasks/main.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- include: cli.yaml
|
||||
tags: cli
|
||||
- include: nxapi.yaml
|
||||
tags: nxapi
|
35
test/integration/targets/nxos_reboot/tasks/nxapi.yaml
Normal file
35
test/integration/targets/nxos_reboot/tasks/nxapi.yaml
Normal file
|
@ -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
|
|
@ -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"
|
Loading…
Reference in a new issue