From 9fc409e1269cc0eda8a860fe59482b96ffe0c42e Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Wed, 13 Sep 2017 01:21:46 -0400 Subject: [PATCH] Fix nxos_mtu nxapi failure (#30153) (cherry picked from commit cef7ed03103a28c62a6145abe7aa0d78a6eebf90) --- lib/ansible/modules/network/nxos/_nxos_mtu.py | 25 ++++++++++--------- .../nxos_mtu/tests/common/set_mtu.yaml | 14 ++++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/ansible/modules/network/nxos/_nxos_mtu.py b/lib/ansible/modules/network/nxos/_nxos_mtu.py index 8117260ed3a..8402a567b56 100644 --- a/lib/ansible/modules/network/nxos/_nxos_mtu.py +++ b/lib/ansible/modules/network/nxos/_nxos_mtu.py @@ -125,15 +125,17 @@ from ansible.module_utils.nxos import load_config, run_commands from ansible.module_utils.nxos import nxos_argument_spec, check_args from ansible.module_utils.basic import AnsibleModule -def execute_show_command(command, module, command_type='cli_show'): - if module.params['transport'] == 'cli': - if 'show run' not in command: - command += ' | json' - cmds = [command] - body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': - cmds = [command] - body = run_commands(module, cmds) +def execute_show_command(command, module): + if 'show run' not in command: + output = 'json' + else: + output = 'text' + cmds = [{ + 'command': command, + 'output': output, + }] + + body = run_commands(module, cmds) return body @@ -169,7 +171,7 @@ def get_system_mtu(module): command = 'show run all | inc jumbomtu' sysmtu = '' - body = execute_show_command(command, module, command_type='cli_show_ascii') + body = execute_show_command(command, module) if body: sysmtu = str(body[0].split(' ')[-1]) @@ -237,8 +239,7 @@ def is_default(interface, module): command = 'show run interface {0}'.format(interface) try: - body = execute_show_command( - command, module, command_type='cli_show_ascii')[0] + body = execute_show_command(command, module)[0] if body == 'DNE': return 'DNE' else: diff --git a/test/integration/targets/nxos_mtu/tests/common/set_mtu.yaml b/test/integration/targets/nxos_mtu/tests/common/set_mtu.yaml index 4f60043917f..e944babe43c 100644 --- a/test/integration/targets/nxos_mtu/tests/common/set_mtu.yaml +++ b/test/integration/targets/nxos_mtu/tests/common/set_mtu.yaml @@ -1,18 +1,20 @@ --- - debug: msg="START {{ connection.transport }}/set_mtu.yaml" +- set_fact: testint="{{ nxos_int1 }}" + - name: setup nxos_config: lines: - no switchport - no mtu - parents: interface Ethernet3/1 + parents: "interface {{ testint }}" match: none provider: "{{ connection }}" - name: configure interface mtu nxos_mtu: - interface: Ethernet3/1 + interface: "{{ testint }}" mtu: 2000 provider: "{{ connection }}" register: result @@ -23,7 +25,7 @@ - name: verify interface mtu nxos_mtu: - interface: Ethernet3/1 + interface: "{{ testint }}" mtu: 2000 provider: "{{ connection }}" register: result @@ -34,7 +36,7 @@ - name: configure invalid (odd) interface mtu nxos_mtu: - interface: Ethernet3/1 + interface: "{{ testint }}" mtu: 2001 provider: "{{ connection }}" register: result @@ -46,7 +48,7 @@ - name: configure invalid (large) mtu setting nxos_mtu: - interface: Ethernet3/1 + interface: "{{ testint }}" mtu: 100000 provider: "{{ connection }}" register: result @@ -59,7 +61,7 @@ - name: teardown nxos_config: lines: no mtu - parents: interface Ethernet3/1 + parents: "interface {{ testint }}" match: none provider: "{{ connection }}"