diff --git a/lib/ansible/modules/network/nxos/_nxos_portchannel.py b/lib/ansible/modules/network/nxos/_nxos_portchannel.py index 68f8e224794..838dbd65f7a 100644 --- a/lib/ansible/modules/network/nxos/_nxos_portchannel.py +++ b/lib/ansible/modules/network/nxos/_nxos_portchannel.py @@ -138,22 +138,6 @@ def get_custom_value(arg, config, module): return value -def execute_show_command(command, module): - device_info = get_capabilities(module) - network_api = device_info.get('network_api', 'nxapi') - - if network_api == 'cliconf': - if 'show port-channel summary' in command: - command += ' | json' - cmds = [command] - body = run_commands(module, cmds) - elif network_api == 'nxapi': - cmds = [command] - body = run_commands(module, cmds) - - return body - - def get_portchannel_members(pchannel): try: members = pchannel['TABLE_member']['ROW_member'] @@ -187,13 +171,13 @@ def get_portchannel_mode(interface, protocol, module, netcfg): def get_portchannel(module, netcfg=None): - command = 'show port-channel summary' + command = 'show port-channel summary | json' portchannel = {} portchannel_table = {} members = [] try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] pc_table = body['TABLE_channel']['ROW_channel'] if isinstance(pc_table, dict): diff --git a/lib/ansible/modules/network/nxos/_nxos_switchport.py b/lib/ansible/modules/network/nxos/_nxos_switchport.py index 1540440e5e8..6f798b13c97 100644 --- a/lib/ansible/modules/network/nxos/_nxos_switchport.py +++ b/lib/ansible/modules/network/nxos/_nxos_switchport.py @@ -133,13 +133,13 @@ def get_interface_mode(interface, module): Returns: str: 'layer2' or 'layer3' """ - command = 'show interface ' + interface + command = 'show interface {0} | json'.format(interface) intf_type = get_interface_type(interface) mode = 'unknown' interface_table = {} try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] interface_table = body['TABLE_interface']['ROW_interface'] except (KeyError, AttributeError, IndexError): return mode @@ -167,9 +167,9 @@ def interface_is_portchannel(interface, module): intf_type = get_interface_type(interface) if intf_type == 'ethernet': - command = 'show interface ' + interface + command = 'show interface {0} | json'.format(interface) try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] interface_table = body['TABLE_interface']['ROW_interface'] except (KeyError, AttributeError, IndexError): interface_table = None @@ -194,10 +194,10 @@ def get_switchport(port, module): dictionary with k/v pairs for L2 vlan config """ - command = 'show interface {0} switchport'.format(port) + command = 'show interface {0} switchport | json'.format(port) try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] sp_table = body['TABLE_interface']['ROW_interface'] except (KeyError, AttributeError, IndexError): sp_table = None @@ -358,11 +358,11 @@ def vlan_range_to_list(vlans): def get_list_of_vlans(module): - command = 'show vlan' + command = 'show vlan | json' vlan_list = [] try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] vlan_table = body['TABLE_vlanbrief']['ROW_vlanbrief'] except (KeyError, AttributeError, IndexError): return [] @@ -405,21 +405,6 @@ def apply_value_map(value_map, resource): return resource -def execute_show_command(command, module, command_type='cli_show'): - device_info = get_capabilities(module) - network_api = device_info.get('network_api', 'nxapi') - - if network_api == 'cliconf': - command += ' | json' - cmds = [command] - body = run_commands(module, cmds) - elif network_api == 'nxapi': - cmds = [command] - body = run_commands(module, cmds) - - return body - - def flatten_list(command_lists): flat_command_list = [] for command in command_lists: diff --git a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py index 6558106cfa8..b456a574bed 100644 --- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py +++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py @@ -212,12 +212,12 @@ def state_present(module, existing, proposed, candidate): elif key == 'ingress-replication protocol' and value != existing_commands.get(key): evalue = existing_commands.get(key) dvalue = PARAM_TO_DEFAULT_KEYMAP.get('ingress_replication', 'default') - if evalue: - if value != dvalue: - if evalue != dvalue: - commands.append('no {0} {1}'.format(key, evalue)) - commands.append('{0} {1}'.format(key, value)) - else: + if value != dvalue: + if evalue and evalue != dvalue: + commands.append('no {0} {1}'.format(key, evalue)) + commands.append('{0} {1}'.format(key, value)) + else: + if evalue: commands.append('no {0} {1}'.format(key, evalue)) elif value is True: diff --git a/test/integration/targets/nxos_command/tests/common/contains.yaml b/test/integration/targets/nxos_command/tests/cli/contains.yaml similarity index 93% rename from test/integration/targets/nxos_command/tests/common/contains.yaml rename to test/integration/targets/nxos_command/tests/cli/contains.yaml index d524010e22b..bb6868af309 100644 --- a/test/integration/targets/nxos_command/tests/common/contains.yaml +++ b/test/integration/targets/nxos_command/tests/cli/contains.yaml @@ -9,7 +9,6 @@ wait_for: - "result[0] contains NX-OS" - "result[1].TABLE_interface.ROW_interface.interface contains mgmt" - provider: "{{ connection }}" register: result - assert: diff --git a/test/integration/targets/nxos_command/tests/nxapi/contains.yaml b/test/integration/targets/nxos_command/tests/nxapi/contains.yaml new file mode 100644 index 00000000000..fc053932d87 --- /dev/null +++ b/test/integration/targets/nxos_command/tests/nxapi/contains.yaml @@ -0,0 +1,19 @@ +--- +- debug: msg="START common/contains.yaml on connection={{ ansible_connection }}" + +- name: test contains operator + nxos_command: + commands: + - { command: 'show version', output: 'text' } + - { command: 'show interface mgmt0', output: 'json' } + wait_for: + - "result[0] contains NX-OS" + - "result[1].TABLE_interface.ROW_interface.interface contains mgmt" + provider: "{{ connection }}" + register: result + +- assert: + that: + - "result.changed == false" + +- debug: msg="END common/contains.yaml on connection={{ ansible_connection }}" diff --git a/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml b/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml index 0a70c9cdde3..c639387ed3e 100644 --- a/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml @@ -34,7 +34,6 @@ force: 'true' provider: "{{ connection }}" state: absent - timeout: 60 - block: - name: Configure port-channel mode active @@ -45,7 +44,6 @@ force: 'true' provider: "{{ connection }}" state: present - timeout: 60 register: result - assert: &true @@ -68,7 +66,6 @@ force: 'true' provider: "{{ connection }}" state: present - timeout: 60 register: result - assert: *true @@ -91,7 +88,6 @@ feature: lacp provider: "{{ connection }}" state: disabled - timeout: 60 always: - name: Delete port-channel diff --git a/test/integration/targets/nxos_smoke/tests/common/common_config.yaml b/test/integration/targets/nxos_smoke/tests/common/common_config.yaml index ef55917118e..c551f12cc31 100644 --- a/test/integration/targets/nxos_smoke/tests/common/common_config.yaml +++ b/test/integration/targets/nxos_smoke/tests/common/common_config.yaml @@ -30,7 +30,6 @@ - name: delete backup files file: path: "{{ item.path }}" - provider: "{{ connection }}" state: absent with_items: "{{backup_files.files|default([])}}"