1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fix nxos_gir issues (#41809)

* fix nxos_gir issues

* review comments
This commit is contained in:
saichint 2018-06-27 21:41:45 -07:00 committed by Trishna Guha
parent 0752dc12b7
commit bd9b8b422d
2 changed files with 127 additions and 111 deletions

View file

@ -74,9 +74,14 @@ options:
system_mode_maintenance_on_reload_reset_reason: system_mode_maintenance_on_reload_reset_reason:
description: description:
- Boots the switch into maintenance mode automatically in the - Boots the switch into maintenance mode automatically in the
event of a specified system crash. event of a specified system crash. Note that not all reset
reasons are applicable for all platforms. Also if reset
reason is set to match_any, it is not idempotent as it turns
on all reset reasons. If reset reason is match_any and state
is absent, it turns off all the reset reasons.
choices: ['hw_error','svc_failure','kern_failure','wdog_timeout', choices: ['hw_error','svc_failure','kern_failure','wdog_timeout',
'fatal_error','lc_failure','match_any','manual_reload'] 'fatal_error','lc_failure','match_any','manual_reload',
'any_other', 'maintenance']
state: state:
description: description:
- Specify desired state of the resource. - Specify desired state of the resource.
@ -159,23 +164,10 @@ from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argume
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module, command_type='cli_show_ascii'):
cmds = [command]
device_info = get_capabilities(module)
network_api = device_info.get('network_api', 'nxapi')
if network_api == 'cliconf':
body = run_commands(module, cmds)
elif network_api == 'nxapi':
body = run_commands(module, cmds)
return body
def get_system_mode(module): def get_system_mode(module):
command = 'show system mode' command = {'command': 'show system mode', 'output': 'text'}
body = execute_show_command(command, module)[0] body = run_commands(module, [command])[0]
if 'normal' in body.lower(): if body and 'normal' in body.lower():
mode = 'normal' mode = 'normal'
else: else:
mode = 'maintenance' mode = 'maintenance'
@ -183,15 +175,15 @@ def get_system_mode(module):
def get_maintenance_timeout(module): def get_maintenance_timeout(module):
command = 'show maintenance timeout' command = {'command': 'show maintenance timeout', 'output': 'text'}
body = execute_show_command(command, module)[0] body = run_commands(module, [command])[0]
timeout = body.split()[4] timeout = body.split()[4]
return timeout return timeout
def get_reset_reasons(module): def get_reset_reasons(module):
command = 'show maintenance on-reload reset-reasons' command = {'command': 'show maintenance on-reload reset-reasons', 'output': 'text'}
body = execute_show_command(command, module)[0] body = run_commands(module, [command])[0]
return body return body
@ -224,8 +216,13 @@ def get_commands(module, state, mode):
commands.append('no system mode maintenance timeout {0}'.format( commands.append('no system mode maintenance timeout {0}'.format(
module.params['system_mode_maintenance_timeout'])) module.params['system_mode_maintenance_timeout']))
elif module.params['system_mode_maintenance_shutdown'] is True: elif (module.params['system_mode_maintenance_shutdown'] and
mode == 'normal'):
commands.append('system mode maintenance shutdown') commands.append('system mode maintenance shutdown')
elif (module.params[
'system_mode_maintenance_shutdown'] is False and
mode == 'maintenance'):
commands.append('no system mode maintenance')
elif module.params['system_mode_maintenance_on_reload_reset_reason']: elif module.params['system_mode_maintenance_on_reload_reset_reason']:
reset_reasons = get_reset_reasons(module) reset_reasons = get_reset_reasons(module)
@ -259,7 +256,8 @@ def main():
system_mode_maintenance_on_reload_reset_reason=dict(required=False, system_mode_maintenance_on_reload_reset_reason=dict(required=False,
choices=['hw_error', 'svc_failure', 'kern_failure', choices=['hw_error', 'svc_failure', 'kern_failure',
'wdog_timeout', 'fatal_error', 'lc_failure', 'wdog_timeout', 'fatal_error', 'lc_failure',
'match_any', 'manual_reload']), 'match_any', 'manual_reload', 'any_other',
'maintenance']),
state=dict(choices=['absent', 'present', 'default'], state=dict(choices=['absent', 'present', 'default'],
default='present', required=False) default='present', required=False)
) )

View file

@ -1,101 +1,119 @@
#--- ---
#- debug: msg="START connection={{ ansible_connection }} nxos_gir sanity test" - debug: msg="START connection={{ ansible_connection }} nxos_gir sanity test"
- debug: msg="Using provider={{ connection.transport }}" - debug: msg="Using provider={{ connection.transport }}"
when: ansible_connection == "local" when: ansible_connection == "local"
#
- set_fact: gir_run="true"
- set_fact: gir_run="false"
when: platform is search("N35")
#- name: "Setup" #- name: "Setup"
# nxos_gir: &setup # nxos_gir: &setup
# system_mode_maintenance: false # system_mode_maintenance: false
# provider: "{{ connection }}"
# ignore_errors: yes # ignore_errors: yes
#
#- block: - block:
- name: "Put system in maintenance mode with reload reset reason"
nxos_gir: &reset_reason
system_mode_maintenance_on_reload_reset_reason: manual_reload
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: "Check Idempotence"
nxos_gir: *reset_reason
register: result
- assert: &false
that:
- "result.changed == false"
- name: "Remove reload reason"
nxos_gir: &remove_reason
system_mode_maintenance_on_reload_reset_reason: manual_reload
state: absent
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_gir: *remove_reason
register: result
- assert: *false
- name: "Put system in maintenance mode with timeout"
nxos_gir: &mtime
system_mode_maintenance_timeout: 30
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_gir: *mtime
register: result
- assert: *false
- name: "Remove maintenance mode timeout"
nxos_gir: &remove_timeout
system_mode_maintenance_timeout: 30
state: absent
provider: "{{ connection }}"
register: result
- assert: *true
- name: "Check Idempotence"
nxos_gir: *remove_timeout
register: result
- assert: *false
# - name: "Put system in maintenance mode" # - name: "Put system in maintenance mode"
# nxos_gir: &configure_system_mode_maintenance # nxos_gir: &configure_system_mode_maintenance
# system_mode_maintenance: true # system_mode_maintenance: true
# provider: "{{ connection }}"
# register: result # register: result
# #
# - assert: &true # - assert: *true
# that:
# - "result.changed == true" when: gir_run
#
# - name: "Check Idempotence" rescue:
# nxos_gir: *configure_system_mode_maintenance
# register: result - debug: msg="connection={{ ansible_connection }} nxos_gir failure detected"
#
# - assert: &false always:
# that:
# - "result.changed == false" - name: "Remove snapshots"
# nxos_snapshot:
action: delete_all
provider: "{{ connection }}"
ignore_errors: yes
- name: "Remove other config1"
nxos_config:
lines: no configure maintenance profile normal-mode
match: none
provider: "{{ connection }}"
ignore_errors: yes
- name: "Remove other config2"
nxos_config:
lines: no configure maintenance profile maintenance-mode
match: none
provider: "{{ connection }}"
ignore_errors: yes
# - name: "Put system back in normal mode" # - name: "Put system back in normal mode"
# nxos_gir: *setup # nxos_gir: *setup
# register: result # register: result
# # ignore_errors: yes
# - assert: *true
# - debug: msg="END connection={{ ansible_connection }} nxos_gir sanity test"
# - name: "Check Idempotence"
# nxos_gir: *setup
# register: result
#
# - assert: *false
#
# - name: "Put system in maintenance mode with reload reset reason"
# nxos_gir:
# system_mode_maintenance: true
# system_mode_maintenance_on_reload_reset_reason: manual_reload
# register: result
#
# - assert: *true
#
# - name: "Remove reload reason"
# nxos_gir: &remove_reason
# system_mode_maintenance_on_reload_reset_reason: manual_reload
# state: absent
# register: result
#
# - assert: *true
#
# - name: "Check Idempotence"
# nxos_gir: *remove_reason
# register: result
#
# - assert: *false
#
# - name: "Put system in maintenance mode with timeout"
# nxos_gir:
# system_mode_maintenance: true
# system_mode_maintenance_timeout: 30
# register: result
#
# - assert: *true
#
# - name: "Remove maintenance mode timeout"
# nxos_gir: &remove_timeout
# system_mode_maintenance_timeout: 30
# state: absent
# register: result
#
# - assert: *true
#
# - name: "Check Idempotence"
# nxos_gir: *remove_timeout
# register: result
#
# - assert: *false
#
# - name: "Put system back in normal mode"
# nxos_gir: *setup
# register: result
#
# - assert: *true
#
# rescue:
#
# - debug: msg="connection={{ ansible_connection }} nxos_gir failure detected"
#
# always:
#
# - name: "Put system back in normal mode"
# nxos_gir: *setup
# register: result
#
# - debug: msg="END connection={{ ansible_connection }} nxos_gir sanity test"