From edf933918dec0a5e48a6918a854626fba6421356 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Tue, 10 Jul 2018 00:01:57 +0530 Subject: [PATCH] nxos and eos bugfix pick2.6 (#42291) * fix nxos_vxlan_vtep_vni issue (#42183) Signed-off-by: Trishna Guha (cherry picked from commit 981c9f6a79404252390efc65410811bd7f483d9b) * nxos CI failures bugfix (#42240) * fix nxos_portchannel and remove deprecated param in test Signed-off-by: Trishna Guha * fix _nxos_switchport CI failures Signed-off-by: Trishna Guha * fix nxapi nxos_command test Signed-off-by: Trishna Guha * remove unsupported param nxos_smoke test Signed-off-by: Trishna Guha * fix nxos_vxlan_vtep_vni Signed-off-by: Trishna Guha * syntax error Signed-off-by: Trishna Guha (cherry picked from commit 805d13f287b7b82b9998a17752676b705a102741) * Update eos_l2_interface.py (#42270) (cherry picked from commit 51092c6ea52c2b051434d2f997dfa2167114410b) * add changelog Signed-off-by: Trishna Guha * Enforcing NXAPI default HTTP behavior (#41817) * nxos_nxapi http default behavior * Use nxos_nxapi module in prepare_nxos_tests * Refactor nxos_nxapi configure test to use yaml block * Extend nxos_nxapi https & http test cases * Removed NXOS internal release naming * Resolved ansibot sanity errors * Fix typo in prepare_nxos_tests * Address PR comments * Shippable indicates this is no longer needed * Add port change logic and testing (cherry picked from commit db7300904d03cd653fe22bde0e4d5a18cf2da10d) * update changelog Signed-off-by: Trishna Guha --- .../fragments/eos_l2_interface_fix.yaml | 2 + .../fragments/nxos_CI_failures_fix.yaml | 2 + .../nxos_nxapi_default_http_behavior_fix.yaml | 2 + .../fragments/nxos_vxlan_vtep_vni_fix.yaml | 2 + .../modules/network/eos/eos_l2_interface.py | 5 +- .../modules/network/nxos/_nxos_portchannel.py | 20 +-- .../modules/network/nxos/_nxos_switchport.py | 31 +--- .../modules/network/nxos/nxos_nxapi.py | 55 +++--- .../network/nxos/nxos_vxlan_vtep_vni.py | 5 +- .../platform/default/assert_changes.yaml | 7 - .../platform/default/assert_changes_http.yaml | 16 ++ .../default/assert_changes_https.yaml | 16 ++ .../default/assert_changes_https_http.yaml | 20 +++ .../assert_changes_https_http_ports.yaml | 20 +++ .../platform/n5k/assert_changes_http.yaml | 6 + ...changes.yaml => assert_changes_https.yaml} | 2 +- .../n5k/assert_changes_https_http.yaml | 8 + .../n5k/assert_changes_https_http_ports.yaml | 8 + .../platform/n7k/assert_changes_http.yaml | 7 + ...changes.yaml => assert_changes_https.yaml} | 2 +- .../n7k/assert_changes_https_http.yaml | 9 + .../n7k/assert_changes_https_http_ports.yaml | 9 + .../nxos_nxapi/tests/cli/configure.yaml | 158 ++++++++++++++---- .../nxos_portchannel/tests/common/sanity.yaml | 4 - .../targets/prepare_nxos_tests/tasks/main.yml | 7 +- test/sanity/validate-modules/ignore.txt | 1 - 26 files changed, 307 insertions(+), 117 deletions(-) create mode 100644 changelogs/fragments/eos_l2_interface_fix.yaml create mode 100644 changelogs/fragments/nxos_CI_failures_fix.yaml create mode 100644 changelogs/fragments/nxos_nxapi_default_http_behavior_fix.yaml create mode 100644 changelogs/fragments/nxos_vxlan_vtep_vni_fix.yaml delete mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_http.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http_ports.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_http.yaml rename test/integration/targets/nxos_nxapi/tasks/platform/n5k/{assert_changes.yaml => assert_changes_https.yaml} (75%) create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http_ports.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_http.yaml rename test/integration/targets/nxos_nxapi/tasks/platform/n7k/{assert_changes.yaml => assert_changes_https.yaml} (81%) create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http.yaml create mode 100644 test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http_ports.yaml diff --git a/changelogs/fragments/eos_l2_interface_fix.yaml b/changelogs/fragments/eos_l2_interface_fix.yaml new file mode 100644 index 00000000000..e2b1d451761 --- /dev/null +++ b/changelogs/fragments/eos_l2_interface_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix eos_l2_interface eapi (https://github.com/ansible/ansible/pull/42270). diff --git a/changelogs/fragments/nxos_CI_failures_fix.yaml b/changelogs/fragments/nxos_CI_failures_fix.yaml new file mode 100644 index 00000000000..b6fa2dd50a5 --- /dev/null +++ b/changelogs/fragments/nxos_CI_failures_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix nxos CI failures (https://github.com/ansible/ansible/pull/42240). diff --git a/changelogs/fragments/nxos_nxapi_default_http_behavior_fix.yaml b/changelogs/fragments/nxos_nxapi_default_http_behavior_fix.yaml new file mode 100644 index 00000000000..b8e80ab132d --- /dev/null +++ b/changelogs/fragments/nxos_nxapi_default_http_behavior_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix nxos_nxapi default http behavior (https://github.com/ansible/ansible/pull/41817). diff --git a/changelogs/fragments/nxos_vxlan_vtep_vni_fix.yaml b/changelogs/fragments/nxos_vxlan_vtep_vni_fix.yaml new file mode 100644 index 00000000000..a50f6626330 --- /dev/null +++ b/changelogs/fragments/nxos_vxlan_vtep_vni_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix nxos_vxlan_vtep_vni (https://github.com/ansible/ansible/pull/42240). diff --git a/lib/ansible/modules/network/eos/eos_l2_interface.py b/lib/ansible/modules/network/eos/eos_l2_interface.py index 4ebb64f4d73..a8fe9cecc48 100644 --- a/lib/ansible/modules/network/eos/eos_l2_interface.py +++ b/lib/ansible/modules/network/eos/eos_l2_interface.py @@ -207,8 +207,9 @@ def map_config_to_obj(module): instances = list() for item in set(match): - command = 'sh int {0} switchport | include Switchport' - switchport_cfg = run_commands(module, command.format(item))[0].split(':')[1].strip() + command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item), + 'output': 'text'} + switchport_cfg = run_commands(module, command)[0].split(':')[1].strip() if switchport_cfg == 'Enabled': state = 'present' else: 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_nxapi.py b/lib/ansible/modules/network/nxos/nxos_nxapi.py index 1549167a0c7..31af55a56d6 100644 --- a/lib/ansible/modules/network/nxos/nxos_nxapi.py +++ b/lib/ansible/modules/network/nxos/nxos_nxapi.py @@ -162,7 +162,8 @@ def check_args(module, warnings): def map_obj_to_commands(want, have, module): - commands = list() + send_commands = list() + commands = dict() def needs_update(x): return want.get(x) is not None and (want.get(x) != have.get(x)) @@ -170,29 +171,30 @@ def map_obj_to_commands(want, have, module): if needs_update('state'): if want['state'] == 'absent': return ['no feature nxapi'] - commands.append('feature nxapi') - - if needs_update('http') or (have.get('http') and needs_update('http_port')): - if want['http'] is True or (want['http'] is None and have['http'] is True): - port = want['http_port'] or 80 - commands.append('nxapi http port %s' % port) - elif want['http'] is False: - commands.append('no nxapi http') - - if needs_update('https') or (have.get('https') and needs_update('https_port')): - if want['https'] is True or (want['https'] is None and have['https'] is True): - port = want['https_port'] or 443 - commands.append('nxapi https port %s' % port) - elif want['https'] is False: - commands.append('no nxapi https') + send_commands.append('feature nxapi') + elif want['state'] == 'absent': + return send_commands + + for parameter in ['http', 'https']: + port_param = parameter + '_port' + if needs_update(parameter): + if want.get(parameter) is False: + commands[parameter] = 'no nxapi %s' % parameter + else: + commands[parameter] = 'nxapi %s port %s' % (parameter, want.get(port_param)) + + if needs_update(port_param) and want.get(parameter) is True: + commands[parameter] = 'nxapi %s port %s' % (parameter, want.get(port_param)) if needs_update('sandbox'): - cmd = 'nxapi sandbox' + commands['sandbox'] = 'nxapi sandbox' if not want['sandbox']: - cmd = 'no %s' % cmd - commands.append(cmd) + commands['sandbox'] = 'no %s' % commands['sandbox'] - return commands + for parameter in commands.keys(): + send_commands.append(commands[parameter]) + + return send_commands def parse_http(data): @@ -265,10 +267,10 @@ def main(): """ main entry point for module execution """ argument_spec = dict( - http=dict(aliases=['enable_http'], type='bool'), - http_port=dict(type='int'), - https=dict(aliases=['enable_https'], type='bool'), - https_port=dict(type='int'), + http=dict(aliases=['enable_http'], type='bool', default=True), + http_port=dict(type='int', default=80), + https=dict(aliases=['enable_https'], type='bool', default=False), + https_port=dict(type='int', default=443), sandbox=dict(aliases=['enable_sandbox'], type='bool'), state=dict(default='present', choices=['started', 'stopped', 'present', 'absent']) ) @@ -279,6 +281,11 @@ def main(): supports_check_mode=True) warnings = list() + warning_msg = "Module nxos_nxapi currently defaults to configure 'http port 80'. " + warning_msg += "Default behavior is changing to configure 'https port 443'" + warning_msg += " when params 'http, http_port, https, https_port' are not set in the playbook" + module.deprecate(msg=warning_msg, version="2.11") + check_args(module, warnings) result = {'changed': False, 'warnings': warnings} 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 01fddf069de..b456a574bed 100644 --- a/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py +++ b/lib/ansible/modules/network/nxos/nxos_vxlan_vtep_vni.py @@ -213,11 +213,12 @@ def state_present(module, existing, proposed, candidate): evalue = existing_commands.get(key) dvalue = PARAM_TO_DEFAULT_KEYMAP.get('ingress_replication', 'default') if value != dvalue: - if evalue != dvalue: + if evalue and evalue != dvalue: commands.append('no {0} {1}'.format(key, evalue)) commands.append('{0} {1}'.format(key, value)) else: - commands.append('no {0} {1}'.format(key, evalue)) + if evalue: + commands.append('no {0} {1}'.format(key, evalue)) elif value is True: commands.append(key) diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes.yaml deleted file mode 100644 index 918a3db46ec..00000000000 --- a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Assert configuration changes - assert: - that: - - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port - - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port|string is search("9443") - - result.stdout[0]['operation_status'].o_status == 'nxapi enabled' diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_http.yaml new file mode 100644 index 00000000000..f610431dd3b --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_http.yaml @@ -0,0 +1,16 @@ +--- +- name: Assert HTTP configuration changes + assert: + that: + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port|string is search("80") + - result.stdout[0]['operation_status'].o_status == 'nxapi enabled' + when: major_version is version('9.2', '<') + +- name: Assert HTTP configuration changes 9.2 or greater + assert: + that: + - result.stdout[0]['http_port'] + - result.stdout[0]['http_port']|string is search("80") + - result.stdout[0]['nxapi_status'] == 'nxapi enabled' + when: major_version is version('9.2', '>=') diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https.yaml new file mode 100644 index 00000000000..e89a156fcfc --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https.yaml @@ -0,0 +1,16 @@ +--- +- name: Assert HTTPS configuration changes + assert: + that: + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'].l_port|string is search("9443") + - result.stdout[0]['operation_status'].o_status == 'nxapi enabled' + when: major_version is version('9.2', '<') + +- name: Assert HTTPS configuration changes 9.2 or greater + assert: + that: + - result.stdout[0]['https_port'] + - result.stdout[0]['https_port']|string is search("9443") + - result.stdout[0]['nxapi_status'] == 'nxapi enabled' + when: major_version is version('9.2', '>=') diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http.yaml new file mode 100644 index 00000000000..b7883e2cfe6 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http.yaml @@ -0,0 +1,20 @@ +--- +- name: Assert HTTPS & HTTP configuration changes + assert: + that: + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][1].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][1].l_port|string is search("9443") + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][0].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][0].l_port|string is search("80") + - result.stdout[0]['operation_status'].o_status == 'nxapi enabled' + when: major_version is version('9.2', '<') + +- name: Assert HTTPS & HTTP configuration changes 9.2 or greater + assert: + that: + - result.stdout[0]['https_port'] + - result.stdout[0]['https_port']|string is search("9443") + - result.stdout[0]['http_port'] + - result.stdout[0]['http_port']|string is search("80") + - result.stdout[0]['nxapi_status'] == 'nxapi enabled' + when: major_version is version('9.2', '>=') diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http_ports.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http_ports.yaml new file mode 100644 index 00000000000..05fe2fd0481 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http_ports.yaml @@ -0,0 +1,20 @@ +--- +- name: Assert HTTPS & HTTP configuration changes + assert: + that: + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][1].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][1].l_port|string is search("500") + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][0].l_port + - result.stdout[0]['TABLE_listen_on_port']['ROW_listen_on_port'][0].l_port|string is search("99") + - result.stdout[0]['operation_status'].o_status == 'nxapi enabled' + when: major_version is version('9.2', '<') + +- name: Assert HTTPS & HTTP configuration changes 9.2 or greater + assert: + that: + - result.stdout[0]['https_port'] + - result.stdout[0]['https_port']|string is search("500") + - result.stdout[0]['http_port'] + - result.stdout[0]['http_port']|string is search("99") + - result.stdout[0]['nxapi_status'] == 'nxapi enabled' + when: major_version is version('9.2', '>=') diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_http.yaml new file mode 100644 index 00000000000..2f79127f1e1 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_http.yaml @@ -0,0 +1,6 @@ +--- +- name: Assert HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is not defined + - result.stdout[0].http_port|string is search("80") diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https.yaml similarity index 75% rename from test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes.yaml rename to test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https.yaml index ec66efd0ac4..a934a1fa81e 100644 --- a/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes.yaml +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https.yaml @@ -1,5 +1,5 @@ --- -- name: Assert configuration changes +- name: Assert HTTPS configuration changes assert: that: - result.stdout[0].http_port is not defined diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http.yaml new file mode 100644 index 00000000000..4dded98cf27 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http.yaml @@ -0,0 +1,8 @@ +--- +- name: Assert HTTPS && HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is defined + - result.stdout[0].http_port is defined + - result.stdout[0].https_port|string is search("9443") + - result.stdout[0].http_port|string is search("80") diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http_ports.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http_ports.yaml new file mode 100644 index 00000000000..09c69d677b7 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http_ports.yaml @@ -0,0 +1,8 @@ +--- +- name: Assert HTTPS && HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is defined + - result.stdout[0].http_port is defined + - result.stdout[0].https_port|string is search("500") + - result.stdout[0].http_port|string is search("99") diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_http.yaml new file mode 100644 index 00000000000..fbfba2fd45b --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_http.yaml @@ -0,0 +1,7 @@ +--- +- name: Assert HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is not defined + - result.stdout[0].http_port|string is search("80") + - result.stdout[0].sandbox_status == 'Enabled' diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https.yaml similarity index 81% rename from test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes.yaml rename to test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https.yaml index aed68e302ae..83d954aac9e 100644 --- a/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes.yaml +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https.yaml @@ -1,5 +1,5 @@ --- -- name: Assert configuration changes +- name: Assert HTTPS configuration changes assert: that: - result.stdout[0].http_port is not defined diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http.yaml new file mode 100644 index 00000000000..1db6d488dd0 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http.yaml @@ -0,0 +1,9 @@ +--- +- name: Assert HTTPS & HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is defined + - result.stdout[0].http_port is defined + - result.stdout[0].https_port|string is search("9443") + - result.stdout[0].http_port|string is search("80") + - result.stdout[0].sandbox_status == 'Enabled' diff --git a/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http_ports.yaml b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http_ports.yaml new file mode 100644 index 00000000000..48611ef8141 --- /dev/null +++ b/test/integration/targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http_ports.yaml @@ -0,0 +1,9 @@ +--- +- name: Assert HTTPS & HTTP configuration changes + assert: + that: + - result.stdout[0].https_port is defined + - result.stdout[0].http_port is defined + - result.stdout[0].https_port|string is search("500") + - result.stdout[0].http_port|string is search("99") + - result.stdout[0].sandbox_status == 'Enabled' diff --git a/test/integration/targets/nxos_nxapi/tests/cli/configure.yaml b/test/integration/targets/nxos_nxapi/tests/cli/configure.yaml index 54b08cb2a84..ea4fa13df13 100644 --- a/test/integration/targets/nxos_nxapi/tests/cli/configure.yaml +++ b/test/integration/targets/nxos_nxapi/tests/cli/configure.yaml @@ -8,39 +8,135 @@ nxos_nxapi: state: absent -- name: Configure NXAPI - nxos_nxapi: - enable_http: no - enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" - enable_https: yes - https_port: 9443 - register: result +- block: + - name: Configure NXAPI HTTPS + nxos_nxapi: &configure_https + enable_http: no + enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" + enable_https: yes + https_port: 9443 + register: result -- nxos_command: - commands: - - show nxapi | json - register: result + - nxos_command: + commands: + - show nxapi | json + register: result -- include: targets/nxos_nxapi/tasks/platform/n7k/assert_changes.yaml - when: platform is match('N7K') + - include: targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https.yaml + when: platform is match('N7K') -- include: targets/nxos_nxapi/tasks/platform/n5k/assert_changes.yaml - when: platform is match('N5K') + - include: targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https.yaml + when: platform is match('N5K') -- include: targets/nxos_nxapi/tasks/platform/default/assert_changes.yaml - when: not ( platform is search('N7K')) and not (platform is search('N5K')) and not (platform is search('N35')) + - include: targets/nxos_nxapi/tasks/platform/default/assert_changes_https.yaml + when: not ( platform is search('N7K')) and not (platform is search('N5K')) and not (platform is search('N35')) -- name: Configure NXAPI again - nxos_nxapi: - enable_http: no - enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" - enable_https: yes - https_port: 9443 - register: result - -- name: Assert configuration is idempotent - assert: - that: - - result.changed == false - -- debug: msg="END cli/configure.yaml" + - name: Configure NXAPI HTTPS again + nxos_nxapi: *configure_https + register: result + + - name: Assert configuration is idempotent + assert: &assert_false + that: + - result.changed == false + + + - name: Configure NXAPI HTTPS & HTTP + nxos_nxapi: &configure_https_http + enable_http: yes + enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" + enable_https: yes + https_port: 9443 + register: result + + - nxos_command: + commands: + - show nxapi | json + register: result + + - include: targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http.yaml + when: platform is match('N7K') + + - include: targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http.yaml + when: platform is match('N5K') + + - include: targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http.yaml + when: not ( platform is search('N7K')) and not (platform is search('N5K')) and not (platform is search('N35')) + + - name: Configure NXAPI HTTPS & HTTP again + nxos_nxapi: *configure_https_http + register: result + + - name: Assert configuration is idempotent + assert: *assert_false + + - name: Configure different NXAPI HTTPS & HTTP ports + nxos_nxapi: &configure_https_http_ports + enable_http: yes + enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" + enable_https: yes + http_port: 99 + https_port: 500 + register: result + + - nxos_command: + commands: + - show nxapi | json + register: result + + - include: targets/nxos_nxapi/tasks/platform/n7k/assert_changes_https_http_ports.yaml + when: platform is match('N7K') + + - include: targets/nxos_nxapi/tasks/platform/n5k/assert_changes_https_http_ports.yaml + when: platform is match('N5K') + + - include: targets/nxos_nxapi/tasks/platform/default/assert_changes_https_http_ports.yaml + when: not ( platform is search('N7K')) and not (platform is search('N5K')) and not (platform is search('N35')) + + - name: Configure different NXAPI HTTPS & HTTP ports again + nxos_nxapi: *configure_https_http_ports + register: result + + - name: Assert configuration is idempotent + assert: *assert_false + + - name: Configure NXAPI HTTP + nxos_nxapi: &configure_http + enable_http: yes + enable_sandbox: "{{nxapi_sandbox_option|default(omit)}}" + enable_https: no + register: result + + - nxos_command: + commands: + - show nxapi | json + register: result + + - include: targets/nxos_nxapi/tasks/platform/n7k/assert_changes_http.yaml + when: platform is match('N7K') + + - include: targets/nxos_nxapi/tasks/platform/n5k/assert_changes_http.yaml + when: platform is match('N5K') + + - include: targets/nxos_nxapi/tasks/platform/default/assert_changes_http.yaml + when: not ( platform is search('N7K')) and not (platform is search('N5K')) and not (platform is search('N35')) + + - name: Configure NXAPI HTTP again + nxos_nxapi: *configure_http + register: result + + - name: Assert configuration is idempotent + assert: *assert_false + + always: + - name: Cleanup - Disable NXAPI + nxos_nxapi: + state: absent + register: result + + - name: Cleanup - Re-enable NXAPI + nxos_nxapi: + state: present + register: result + + - debug: msg="END cli/configure.yaml" diff --git a/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml b/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml index 5941f8b9799..83a4d9de92d 100644 --- a/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_portchannel/tests/common/sanity.yaml @@ -30,7 +30,6 @@ members: ["{{ testint1 }}", "{{ testint2 }}"] force: 'true' state: absent - timeout: 60 - block: - name: Configure port-channel mode active @@ -40,7 +39,6 @@ mode: active force: 'true' state: present - timeout: 60 register: result - assert: &true @@ -62,7 +60,6 @@ mode: passive force: 'true' state: present - timeout: 60 register: result - assert: *true @@ -84,7 +81,6 @@ nxos_feature: feature: lacp state: disabled - timeout: 60 always: - name: Delete port-channel diff --git a/test/integration/targets/prepare_nxos_tests/tasks/main.yml b/test/integration/targets/prepare_nxos_tests/tasks/main.yml index 958b533a77e..9d2e5cdd6cd 100644 --- a/test/integration/targets/prepare_nxos_tests/tasks/main.yml +++ b/test/integration/targets/prepare_nxos_tests/tasks/main.yml @@ -1,14 +1,14 @@ --- -- name: Toggle feature nxapi - Enable +- name: Enable Feature Privilage nxos_config: lines: - - feature nxapi - feature privilege connection: network_cli ignore_errors: yes -- name: Set nxapi to default state +- name: Enable Feature NXAPI nxos_nxapi: + state: present connection: network_cli # Gather the list of interfaces on this device and make the list @@ -93,6 +93,7 @@ # 8.0(1) # 7.3(0)D1(1) # 7.0(3)IHD8(1) +- set_fact: major_version="{{ image_version[0:3] }}" - set_fact: imagetag="{{ image_version[0:3] }}" when: image_version is search("\d\.\d\(\d\)") - set_fact: imagetag="{{ image_version[6:8] }}" diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt index 5aa7e7ce7fe..16d29c1ad14 100644 --- a/test/sanity/validate-modules/ignore.txt +++ b/test/sanity/validate-modules/ignore.txt @@ -941,7 +941,6 @@ lib/ansible/modules/network/nxos/nxos_gir.py E326 lib/ansible/modules/network/nxos/nxos_igmp_interface.py E326 lib/ansible/modules/network/nxos/nxos_interface.py E324 lib/ansible/modules/network/nxos/nxos_lldp.py E326 -lib/ansible/modules/network/nxos/nxos_nxapi.py E324 lib/ansible/modules/network/nxos/nxos_nxapi.py E326 lib/ansible/modules/network/nxos/nxos_pim_interface.py E326 lib/ansible/modules/network/nxos/nxos_pim_rp_address.py E326