From 7fabb28d227f68e706b6c355dfa9aa4f896f06e0 Mon Sep 17 00:00:00 2001 From: Chris Van Heuveln Date: Mon, 20 Jan 2020 02:15:49 -0500 Subject: [PATCH] nxos_gir timeout fixes (#66043) * nxos_gir timeout fixes * additional setup/teardown cleanups for sanity test * Add timeout extension comment to module header * lint * rework logic to use action plugin --- lib/ansible/modules/network/nxos/nxos_gir.py | 1 + lib/ansible/plugins/action/nxos.py | 10 ++++ .../targets/nxos_gir/tests/common/sanity.yaml | 56 ++++++++++--------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_gir.py b/lib/ansible/modules/network/nxos/nxos_gir.py index a2241b00e35..306846ff00b 100644 --- a/lib/ansible/modules/network/nxos/nxos_gir.py +++ b/lib/ansible/modules/network/nxos/nxos_gir.py @@ -29,6 +29,7 @@ version_added: "2.2" short_description: Trigger a graceful removal or insertion (GIR) of the switch. description: - Trigger a graceful removal or insertion (GIR) of the switch. + - GIR processing may take more than 2 minutes. Timeout settings are automatically extended to 200s when user timeout settings are insufficient. author: - Gabriele Gerbino (@GGabriele) notes: diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py index 0aa25c3a523..6a6db0bf835 100644 --- a/lib/ansible/plugins/action/nxos.py +++ b/lib/ansible/plugins/action/nxos.py @@ -25,6 +25,7 @@ import sys from ansible import constants as C from ansible.plugins.action.network import ActionModule as ActionNetworkModule +from ansible.module_utils.connection import Connection from ansible.module_utils.network.common.utils import load_provider from ansible.module_utils.network.nxos.nxos import nxos_provider_spec from ansible.utils.display import Display @@ -81,6 +82,15 @@ class ActionModule(ActionNetworkModule): display.warning('transport is unnecessary when using %s and will be ignored' % self._play_context.connection) del self._task.args['transport'] + if module_name == 'nxos_gir': + conn = Connection(self._connection.socket_path) + persistent_command_timeout = conn.get_option('persistent_command_timeout') + gir_timeout = 200 + if persistent_command_timeout < gir_timeout: + conn.set_option('persistent_command_timeout', gir_timeout) + msg = "timeout value extended to %ss for nxos_gir" % gir_timeout + display.warning(msg) + elif self._play_context.connection == 'local': provider = load_provider(nxos_provider_spec, self._task.args) transport = provider['transport'] or 'cli' diff --git a/test/integration/targets/nxos_gir/tests/common/sanity.yaml b/test/integration/targets/nxos_gir/tests/common/sanity.yaml index 03aa124d15a..99e3292dc74 100644 --- a/test/integration/targets/nxos_gir/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_gir/tests/common/sanity.yaml @@ -1,13 +1,20 @@ --- - debug: msg="START connection={{ ansible_connection }} nxos_gir sanity test" +- set_fact: gir_run='{{ true if (platform is not search("N35")) else false }}' -- set_fact: gir_run="true" -- set_fact: gir_run="false" - when: platform is search("N35") -#- name: "Setup" -# nxos_gir: &setup -# system_mode_maintenance: false -# ignore_errors: yes +- name: Setup0 + nxos_config: &cleanup0 + lines: + - no system mode maintenance timeout 30 + - no configure maintenance profile normal-mode + - no configure maintenance profile maintenance-mode + match: none + ignore_errors: yes + +- name: Setup1 + nxos_gir: + system_mode_maintenance: false + ignore_errors: yes - block: - name: "Put system in maintenance mode with reload reset reason" @@ -68,12 +75,12 @@ - assert: *false -# - name: "Put system in maintenance mode" -# nxos_gir: &configure_system_mode_maintenance -# system_mode_maintenance: true -# register: result -# -# - assert: *true + - name: "Put system in maintenance mode" + nxos_gir: &configure_system_mode_maintenance + system_mode_maintenance: true + register: result + + - assert: *true when: gir_run @@ -88,21 +95,18 @@ action: delete_all ignore_errors: yes - - name: "Remove other config1" - nxos_config: - lines: no configure maintenance profile normal-mode - match: none + - name: Teardown0 + nxos_config: *cleanup0 ignore_errors: yes - - name: "Remove other config2" - nxos_config: - lines: no configure maintenance profile maintenance-mode - match: none + - name: "Put system back in normal mode" + nxos_gir: + system_mode_maintenance: false + # Try again if cli is blocking while changing modes + retries: 3 + delay: 30 + register: result + until: result is not failed ignore_errors: yes -# - name: "Put system back in normal mode" -# nxos_gir: *setup -# register: result -# ignore_errors: yes - - debug: msg="END connection={{ ansible_connection }} nxos_gir sanity test"