From 58f018e367734b50dc464be10f7cecbb5cafc0c9 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Wed, 30 May 2018 10:40:25 +0530 Subject: nxos and httpapi cherry-pick (#40859) * httpapi fix nxos (#40806) * httpapi fix nxos Signed-off-by: Trishna Guha * nxos_hsrp fix Signed-off-by: Trishna Guha (cherry picked from commit a7421e86116361b41790d663fed065ade35af54e) * fix nxos_vrf and migrate get_interface_type to module_utils (#40825) Signed-off-by: Trishna Guha (cherry picked from commit b4baa2d48455029cfe35b14195b2ca4616e540ac) * nxos_vlan fix (#40822) * nxos_vlan fix Signed-off-by: Trishna Guha * uncomment mode test as nxapi now has get_capabilities Signed-off-by: Trishna Guha (cherry picked from commit 17b6ecf1016386a68d214bf755b4eac5f65a298f) * Update nxos_install_os module (#40102) * Add nxos_install_os integration tests * Update call to check timers * Update check_ansible_timer method * Modify network_cli integration tests * Add timer check for nxos_install_os * Add comments for clear_persistent_sockets * Update connection info for tests * More updates * Restructure files for provider and non-provider testing * Update env var name and add check for ISSU switchover (cherry picked from commit 9f026309a69497630a37affbae5ccc46fe2cbd1b) --- lib/ansible/module_utils/network/nxos/nxos.py | 21 ++++++ .../modules/network/nxos/_nxos_ip_interface.py | 18 +---- .../modules/network/nxos/_nxos_switchport.py | 26 +------- lib/ansible/modules/network/nxos/nxos_hsrp.py | 45 ++----------- .../modules/network/nxos/nxos_igmp_interface.py | 18 +---- .../modules/network/nxos/nxos_install_os.py | 37 ++--------- lib/ansible/modules/network/nxos/nxos_interface.py | 22 +------ .../modules/network/nxos/nxos_l2_interface.py | 27 +------- .../modules/network/nxos/nxos_pim_interface.py | 18 +---- lib/ansible/modules/network/nxos/nxos_vlan.py | 32 +++++---- lib/ansible/modules/network/nxos/nxos_vrf.py | 17 +++-- .../modules/network/nxos/nxos_vrf_interface.py | 18 +---- lib/ansible/modules/network/nxos/nxos_vrrp.py | 18 +---- lib/ansible/plugins/action/nxos.py | 6 ++ lib/ansible/plugins/cliconf/eos.py | 5 +- lib/ansible/plugins/cliconf/nxos.py | 5 +- lib/ansible/plugins/httpapi/nxos.py | 4 ++ .../targets/nxos_install_os/defaults/main.yaml | 2 + .../targets/nxos_install_os/meta/main.yml | 2 + .../targets/nxos_install_os/tasks/httpapi.yaml | 16 +++++ .../targets/nxos_install_os/tasks/main.yaml | 5 ++ .../targets/nxos_install_os/tasks/network_cli.yaml | 16 +++++ .../nxos_install_os/tasks/network_local.yaml | 16 +++++ .../targets/nxos_install_os/tasks/nxapi.yaml | 16 +++++ .../tasks/upgrade/clear_persistent_sockets.yaml | 19 ++++++ .../tasks/upgrade/copy_kick_system_images.yaml | 41 ++++++++++++ .../tasks/upgrade/delete_files.yaml | 10 +++ .../tasks/upgrade/delete_files_provider.yaml | 11 ++++ .../tasks/upgrade/enable_scp_server.yaml | 5 ++ .../tasks/upgrade/enable_scp_server_provider.yaml | 6 ++ .../nxos_install_os/tasks/upgrade/install_os.yaml | 23 +++++++ .../tasks/upgrade/install_os_provider.yaml | 24 +++++++ .../tasks/upgrade/install_system.yaml | 24 +++++++ .../tasks/upgrade/install_system_provider.yaml | 25 +++++++ .../tasks/upgrade/install_with_kick.yaml | 25 +++++++ .../tasks/upgrade/install_with_kick_provider.yaml | 26 ++++++++ .../tasks/upgrade/main_os_install.yaml | 10 +++ .../tasks/upgrade/set_boot_pointer_and_reload.yaml | 22 +++++++ .../set_boot_pointer_and_reload_provider.yaml | 23 +++++++ .../nxos_install_os/tests/common/upgrade.yaml | 56 ++++++++++++++++ .../targets/nxos_vlan/tests/common/sanity.yaml | 77 ++++++++++++---------- 41 files changed, 557 insertions(+), 280 deletions(-) create mode 100644 test/integration/targets/nxos_install_os/defaults/main.yaml create mode 100644 test/integration/targets/nxos_install_os/meta/main.yml create mode 100644 test/integration/targets/nxos_install_os/tasks/httpapi.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/main.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/network_cli.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/network_local.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/nxapi.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/delete_files_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_os_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_system_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload.yaml create mode 100644 test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload_provider.yaml create mode 100644 test/integration/targets/nxos_install_os/tests/common/upgrade.yaml diff --git a/lib/ansible/module_utils/network/nxos/nxos.py b/lib/ansible/module_utils/network/nxos/nxos.py index 832c2bbc58..10f72a7dfd 100644 --- a/lib/ansible/module_utils/network/nxos/nxos.py +++ b/lib/ansible/module_utils/network/nxos/nxos.py @@ -479,3 +479,24 @@ def normalize_interface(name): proper_interface = name return proper_interface + + +def get_interface_type(interface): + """Gets the type of interface + """ + if interface.upper().startswith('ET'): + return 'ethernet' + elif interface.upper().startswith('VL'): + return 'svi' + elif interface.upper().startswith('LO'): + return 'loopback' + elif interface.upper().startswith('MG'): + return 'management' + elif interface.upper().startswith('MA'): + return 'management' + elif interface.upper().startswith('PO'): + return 'portchannel' + elif interface.upper().startswith('NV'): + return 'nve' + else: + return 'unknown' diff --git a/lib/ansible/modules/network/nxos/_nxos_ip_interface.py b/lib/ansible/modules/network/nxos/_nxos_ip_interface.py index fcb19d9288..f4c5581bdb 100644 --- a/lib/ansible/modules/network/nxos/_nxos_ip_interface.py +++ b/lib/ansible/modules/network/nxos/_nxos_ip_interface.py @@ -179,6 +179,7 @@ except ImportError: from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule @@ -209,23 +210,6 @@ def execute_show_command(command, module): return body -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def is_default(interface, module): command = 'show run interface {0}'.format(interface) diff --git a/lib/ansible/modules/network/nxos/_nxos_switchport.py b/lib/ansible/modules/network/nxos/_nxos_switchport.py index a82b1c8d18..1540440e5e 100644 --- a/lib/ansible/modules/network/nxos/_nxos_switchport.py +++ b/lib/ansible/modules/network/nxos/_nxos_switchport.py @@ -119,34 +119,10 @@ commands: from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule -def get_interface_type(interface): - """Gets the type of interface - Args: - interface (str): full name of interface, i.e. Ethernet1/1, loopback10, - port-channel20, vlan20 - Returns: - type of interface: ethernet, svi, loopback, management, portchannel, - or unknown - """ - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def get_interface_mode(interface, module): """Gets current mode of interface: layer2 or layer3 Args: diff --git a/lib/ansible/modules/network/nxos/nxos_hsrp.py b/lib/ansible/modules/network/nxos/nxos_hsrp.py index 84f6b4658a..a108fbe56c 100644 --- a/lib/ansible/modules/network/nxos/nxos_hsrp.py +++ b/lib/ansible/modules/network/nxos/nxos_hsrp.py @@ -148,6 +148,7 @@ commands: from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule @@ -159,21 +160,6 @@ PARAM_TO_DEFAULT_KEYMAP = { } -def execute_show_command(command, module): - 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 apply_key_map(key_map, table): new_dict = {} for key in table: @@ -187,29 +173,12 @@ def apply_key_map(key_map, table): return new_dict -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def get_interface_mode(interface, intf_type, module): - command = 'show interface {0}'.format(interface) + command = 'show interface {0} | json'.format(interface) interface = {} mode = 'unknown' try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] except IndexError: return None @@ -224,7 +193,7 @@ def get_interface_mode(interface, intf_type, module): def get_hsrp_group(group, interface, module): - command = 'show hsrp group {0} all'.format(group) + command = 'show hsrp group {0} all | json'.format(group) hsrp = {} hsrp_key = { @@ -240,9 +209,9 @@ def get_hsrp_group(group, interface, module): } try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command])[0] hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail'] - except (AttributeError, IndexError, TypeError): + except (AttributeError, IndexError, TypeError, KeyError): return {} if isinstance(hsrp_table, dict): @@ -365,7 +334,7 @@ def is_default(interface, module): command = 'show run interface {0}'.format(interface) try: - body = execute_show_command(command, module)[0] + body = run_commands(module, [command], check_rc=False)[0] if 'invalid' in body.lower(): return 'DNE' else: diff --git a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py index 712ad2e2b5..a3dc1b26e1 100644 --- a/lib/ansible/modules/network/nxos/nxos_igmp_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_igmp_interface.py @@ -191,6 +191,7 @@ changed: from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule import re @@ -227,23 +228,6 @@ def get_interface_mode(interface, intf_type, module): return mode -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def apply_key_map(key_map, table): new_dict = {} for key, value in table.items(): diff --git a/lib/ansible/modules/network/nxos/nxos_install_os.py b/lib/ansible/modules/network/nxos/nxos_install_os.py index dc0b60bcb9..6c7af20524 100644 --- a/lib/ansible/modules/network/nxos/nxos_install_os.py +++ b/lib/ansible/modules/network/nxos/nxos_install_os.py @@ -35,13 +35,9 @@ notes: - N9k 7.0(3)I4(6), 7.0(3)I5(3), 7.0(3)I6(1), 7.0(3)I7(1), 7.0(3)F2(2), 7.0(3)F3(2) - N3k 6.0(2)A8(6), 6.0(2)A8(8), 7.0(3)I6(1), 7.0(3)I7(1) - N7k 7.3(0)D1(1), 8.0(1), 8.2(1) - - This module executes longer then the default ansible timeout value and - will generate errors unless the module timeout parameter is set to a - value of 500 seconds or higher. - The example time is sufficent for most upgrades but this can be - tuned higher based on specific upgrade time requirements. - The module will exit with a failure message if the timer is - not set to 500 seconds or higher. + - This module requires both the ANSIBLE_PERSISTENT_CONNECT_TIMEOUT and + ANSIBLE_PERSISTENT_COMMAND_TIMEOUT timers to be set to 600 seconds or higher. + The module will exit if the timers are not set properly. - Do not include full file paths, just the name of the file(s) stored on the top level flash directory. - This module attempts to install the software immediately, @@ -81,7 +77,6 @@ EXAMPLES = ''' nxos_install_os: system_image_file: nxos.7.0.3.I6.1.bin issu: desired - provider: "{{ connection | combine({'timeout': 500}) }}" - name: Wait for device to come back up with new image wait_for: @@ -129,25 +124,6 @@ from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_arg from ansible.module_utils.basic import AnsibleModule -def check_ansible_timer(module): - '''Check Ansible Timer Values''' - msg = "The 'timeout' provider param value for this module to execute\n" - msg = msg + 'properly is too low.\n' - msg = msg + 'Upgrades can take a long time so the value needs to be set\n' - msg = msg + 'to the recommended value of 500 seconds or higher in the\n' - msg = msg + 'ansible playbook for the nxos_install_os module.\n' - msg = msg + '\n' - msg = msg + 'provider: "{{ connection | combine({\'timeout\': 500}) }}"' - data = module.params.get('provider') - timer_low = False - if data.get('timeout') is None: - timer_low = True - if data.get('timeout') is not None and data.get('timeout') < 500: - timer_low = True - if timer_low: - module.fail_json(msg=msg.split('\n')) - - # Output options are 'text' or 'json' def execute_show_command(module, command, output='text'): cmds = [{ @@ -276,6 +252,9 @@ def parse_show_install(data): if re.search(r'Install has been successful', x): ud['upgrade_succeeded'] = True break + if re.search(r'Switching over onto standby', x): + ud['upgrade_succeeded'] = True + break # We get these messages when the upgrade is non-disruptive and # we loose connection with the switchover but far enough along that @@ -539,10 +518,6 @@ def main(): warnings = list() check_args(module, warnings) - # This module will error out if the Ansible task timeout value is not - # tuned high enough. - check_ansible_timer(module) - # Get system_image_file(sif), kickstart_image_file(kif) and # issu settings from module params. sif = module.params['system_image_file'] diff --git a/lib/ansible/modules/network/nxos/nxos_interface.py b/lib/ansible/modules/network/nxos/nxos_interface.py index 8de5aa4312..e98da4b679 100644 --- a/lib/ansible/modules/network/nxos/nxos_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_interface.py @@ -203,6 +203,7 @@ from copy import deepcopy from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, normalize_interface +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.utils import conditional, remove_default_spec @@ -231,27 +232,6 @@ def search_obj_in_list(name, lst): return None -def get_interface_type(interface): - """Gets the type of interface - """ - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - elif interface.upper().startswith('NV'): - return 'nve' - else: - return 'unknown' - - def get_interfaces_dict(module): """Gets all active interfaces on a given switch """ diff --git a/lib/ansible/modules/network/nxos/nxos_l2_interface.py b/lib/ansible/modules/network/nxos/nxos_l2_interface.py index bb7ba8892f..cb71d5871b 100644 --- a/lib/ansible/modules/network/nxos/nxos_l2_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_l2_interface.py @@ -120,36 +120,11 @@ import re from copy import deepcopy from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands -from ansible.module_utils.network.nxos.nxos import nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, get_interface_type from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.utils import remove_default_spec -def get_interface_type(name): - """Gets the type of interface - Args: - interface (str): full name of interface, i.e. Ethernet1/1, loopback10, - port-channel20, vlan20 - Returns: - type of interface: ethernet, svi, loopback, management, portchannel, - or unknown - """ - if name.upper().startswith('ET'): - return 'ethernet' - elif name.upper().startswith('VL'): - return 'svi' - elif name.upper().startswith('LO'): - return 'loopback' - elif name.upper().startswith('MG'): - return 'management' - elif name.upper().startswith('MA'): - return 'management' - elif name.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def get_interface_mode(name, module): """Gets current mode of interface: layer2 or layer3 Args: diff --git a/lib/ansible/modules/network/nxos/nxos_pim_interface.py b/lib/ansible/modules/network/nxos/nxos_pim_interface.py index aa6e80a782..3eb041fd85 100644 --- a/lib/ansible/modules/network/nxos/nxos_pim_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_pim_interface.py @@ -135,6 +135,7 @@ import re from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.six import string_types @@ -200,23 +201,6 @@ def local_existing(gexisting): return gexisting, jp_bidir, isauth -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def get_interface_mode(interface, intf_type, module): mode = 'unknown' command = 'show interface {0}'.format(interface) diff --git a/lib/ansible/modules/network/nxos/nxos_vlan.py b/lib/ansible/modules/network/nxos/nxos_vlan.py index 94eded7192..152c9c0958 100644 --- a/lib/ansible/modules/network/nxos/nxos_vlan.py +++ b/lib/ansible/modules/network/nxos/nxos_vlan.py @@ -454,21 +454,31 @@ def parse_vni(module, vlan_id): return str(vni) +def get_vlan_int(interfaces): + vlan_int = [] + for i in interfaces.split(','): + if 'eth' in i.lower() and '-' in i: + int_range = i.split('-') + stop = int((int_range)[1]) + start = int(int_range[0].split('/')[1]) + eth = int_range[0].split('/')[0] + for r in range(start, stop + 1): + vlan_int.append(eth + '/' + str(r)) + else: + vlan_int.append(i) + return vlan_int + + def parse_interfaces(module, vlan): vlan_int = [] interfaces = vlan.get('vlanshowplist-ifidx') if interfaces: - for i in interfaces.split(','): - if 'eth' in i.lower() and '-' in i: - int_range = i.split('-') - stop = int((int_range)[1]) - start = int(int_range[0].split('/')[1]) - eth = int_range[0].split('/')[0] - for r in range(start, stop + 1): - vlan_int.append(eth + '/' + str(r)) - else: - vlan_int.append(i) - + if isinstance(interfaces, list): + interfaces_list = [i.strip() for i in interfaces] + interfaces_str = ','.join(interfaces_list) + vlan_int = get_vlan_int(interfaces_str) + else: + vlan_int = get_vlan_int(interfaces) return vlan_int diff --git a/lib/ansible/modules/network/nxos/nxos_vrf.py b/lib/ansible/modules/network/nxos/nxos_vrf.py index 3c3aad2fcd..c5c92ed504 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf.py @@ -175,7 +175,7 @@ from copy import deepcopy from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.nxos.nxos import load_config, run_commands -from ansible.module_utils.network.nxos.nxos import nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, get_interface_type from ansible.module_utils.network.common.utils import remove_default_spec @@ -262,7 +262,8 @@ def map_obj_to_commands(updates, module): if interfaces and interfaces[0] != 'default': for i in interfaces: commands.append('interface {0}'.format(i)) - commands.append('no switchport') + if get_interface_type(i) in ('ethernet', 'portchannel'): + commands.append('no switchport') commands.append('vrf member {0}'.format(name)) else: @@ -296,7 +297,8 @@ def map_obj_to_commands(updates, module): commands.append('vrf context {0}'.format(name)) commands.append('exit') commands.append('interface {0}'.format(i)) - commands.append('no switchport') + if get_interface_type(i) in ('ethernet', 'portchannel'): + commands.append('no switchport') commands.append('vrf member {0}'.format(name)) elif set(interfaces) != set(obj_in_have['interfaces']): @@ -305,7 +307,8 @@ def map_obj_to_commands(updates, module): commands.append('vrf context {0}'.format(name)) commands.append('exit') commands.append('interface {0}'.format(i)) - commands.append('no switchport') + if get_interface_type(i) in ('ethernet', 'portchannel'): + commands.append('no switchport') commands.append('vrf member {0}'.format(name)) superfluous_interfaces = list(set(obj_in_have['interfaces']) - set(interfaces)) @@ -313,7 +316,8 @@ def map_obj_to_commands(updates, module): commands.append('vrf context {0}'.format(name)) commands.append('exit') commands.append('interface {0}'.format(i)) - commands.append('no switchport') + if get_interface_type(i) in ('ethernet', 'portchannel'): + commands.append('no switchport') commands.append('no vrf member {0}'.format(name)) elif interfaces and interfaces[0] == 'default': if obj_in_have['interfaces']: @@ -321,7 +325,8 @@ def map_obj_to_commands(updates, module): commands.append('vrf context {0}'.format(name)) commands.append('exit') commands.append('interface {0}'.format(i)) - commands.append('no switchport') + if get_interface_type(i) in ('ethernet', 'portchannel'): + commands.append('no switchport') commands.append('no vrf member {0}'.format(name)) if purge: diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index c08e87b8f6..65a4323a11 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -82,6 +82,7 @@ import re from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule @@ -97,23 +98,6 @@ def execute_show_command(command, module): return run_commands(module, cmds)[0] -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def get_interface_mode(interface, intf_type, module): command = 'show interface {0}'.format(interface) interface = {} diff --git a/lib/ansible/modules/network/nxos/nxos_vrrp.py b/lib/ansible/modules/network/nxos/nxos_vrrp.py index cc5f954d9f..a1f393a3ec 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrrp.py +++ b/lib/ansible/modules/network/nxos/nxos_vrrp.py @@ -118,6 +118,7 @@ commands: from ansible.module_utils.network.nxos.nxos import load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities, nxos_argument_spec +from ansible.module_utils.network.nxos.nxos import get_interface_type from ansible.module_utils.basic import AnsibleModule @@ -154,23 +155,6 @@ def apply_key_map(key_map, table): return new_dict -def get_interface_type(interface): - if interface.upper().startswith('ET'): - return 'ethernet' - elif interface.upper().startswith('VL'): - return 'svi' - elif interface.upper().startswith('LO'): - return 'loopback' - elif interface.upper().startswith('MG'): - return 'management' - elif interface.upper().startswith('MA'): - return 'management' - elif interface.upper().startswith('PO'): - return 'portchannel' - else: - return 'unknown' - - def is_default(interface, module): command = 'show run interface {0}'.format(interface) diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py index db190355ae..ebb5465e7b 100644 --- a/lib/ansible/plugins/action/nxos.py +++ b/lib/ansible/plugins/action/nxos.py @@ -55,6 +55,12 @@ class ActionModule(_ActionModule): elif self._play_context.connection == 'local': self._task.args['username'] = self._play_context.connection_user + if self._task.action == 'nxos_install_os': + if C.PERSISTENT_COMMAND_TIMEOUT < 600 or C.PERSISTENT_CONNECT_TIMEOUT < 600: + msg = 'PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT' + msg += ' must be set to 600 seconds or higher when using nxos_install_os module' + return {'failed': True, 'msg': msg} + if self._play_context.connection in ('network_cli', 'httpapi'): provider = self._task.args.get('provider', {}) if any(provider.values()): diff --git a/lib/ansible/plugins/cliconf/eos.py b/lib/ansible/plugins/cliconf/eos.py index 22239cac5c..5a8e973620 100644 --- a/lib/ansible/plugins/cliconf/eos.py +++ b/lib/ansible/plugins/cliconf/eos.py @@ -94,8 +94,11 @@ class Cliconf(CliconfBase): def get_capabilities(self): result = {} result['rpc'] = self.get_base_rpc() - result['network_api'] = 'cliconf' result['device_info'] = self.get_device_info() + if isinstance(self._connection, NetworkCli): + result['network_api'] = 'cliconf' + else: + result['network_api'] = 'eapi' return json.dumps(result) # Imported from module_utils diff --git a/lib/ansible/plugins/cliconf/nxos.py b/lib/ansible/plugins/cliconf/nxos.py index 01e492717e..5172ac751c 100644 --- a/lib/ansible/plugins/cliconf/nxos.py +++ b/lib/ansible/plugins/cliconf/nxos.py @@ -95,8 +95,11 @@ class Cliconf(CliconfBase): def get_capabilities(self): result = {} result['rpc'] = self.get_base_rpc() - result['network_api'] = 'cliconf' result['device_info'] = self.get_device_info() + if isinstance(self._connection, NetworkCli): + result['network_api'] = 'cliconf' + else: + result['network_api'] = 'nxapi' return json.dumps(result) # Migrated from module_utils diff --git a/lib/ansible/plugins/httpapi/nxos.py b/lib/ansible/plugins/httpapi/nxos.py index 2a49257823..d6cfc4fe1d 100644 --- a/lib/ansible/plugins/httpapi/nxos.py +++ b/lib/ansible/plugins/httpapi/nxos.py @@ -89,9 +89,13 @@ class HttpApi: out = to_text(exc) out = to_list(out) + if not out[0]: + return out + for index, response in enumerate(out): if response[0] == '{': out[index] = json.loads(response) + return out diff --git a/test/integration/targets/nxos_install_os/defaults/main.yaml b/test/integration/targets/nxos_install_os/defaults/main.yaml new file mode 100644 index 0000000000..99533903e5 --- /dev/null +++ b/test/integration/targets/nxos_install_os/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "upgrade" diff --git a/test/integration/targets/nxos_install_os/meta/main.yml b/test/integration/targets/nxos_install_os/meta/main.yml new file mode 100644 index 0000000000..ae741cbdc7 --- /dev/null +++ b/test/integration/targets/nxos_install_os/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nxos_tests diff --git a/test/integration/targets/nxos_install_os/tasks/httpapi.yaml b/test/integration/targets/nxos_install_os/tasks/httpapi.yaml new file mode 100644 index 0000000000..28c543fba2 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/httpapi.yaml @@ -0,0 +1,16 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (ansible_connection=httpapi) + include: "{{ test_case_to_run }} ansible_connection=httpapi" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_install_os/tasks/main.yaml b/test/integration/targets/nxos_install_os/tasks/main.yaml new file mode 100644 index 0000000000..ec1cfa5019 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- { include: network_cli.yaml, tags: ['cli'] } +- { include: network_local.yaml, tags: ['local'] } +- { include: httpapi.yaml, tags: ['httpapi'] } +- { include: nxapi.yaml, tags: ['nxapi'] } diff --git a/test/integration/targets/nxos_install_os/tasks/network_cli.yaml b/test/integration/targets/nxos_install_os/tasks/network_cli.yaml new file mode 100644 index 0000000000..e69ab5e2fe --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/network_cli.yaml @@ -0,0 +1,16 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (ansible_connection=network_cli) + include: "{{ test_case_to_run }} ansible_connection=network_cli" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_install_os/tasks/network_local.yaml b/test/integration/targets/nxos_install_os/tasks/network_local.yaml new file mode 100644 index 0000000000..b138208c55 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/network_local.yaml @@ -0,0 +1,16 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test case (ansible_connection=local transport=ssh) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ cli }}" + with_first_found: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_install_os/tasks/nxapi.yaml b/test/integration/targets/nxos_install_os/tasks/nxapi.yaml new file mode 100644 index 0000000000..51e03b8daf --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/nxapi.yaml @@ -0,0 +1,16 @@ +--- +- name: collect common test cases + find: + paths: "{{ role_path }}/tests/common" + patterns: "{{ testcase }}.yaml" + connection: local + register: test_cases + +- name: set test_items + set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: run test cases (ansible_connection=local transport=nxapi) + include: "{{ test_case_to_run }} ansible_connection=local connection={{ nxapi }}" + with_items: "{{ test_items }}" + loop_control: + loop_var: test_case_to_run diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml new file mode 100644 index 0000000000..1e62116e7c --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml @@ -0,0 +1,19 @@ +--- +# This playbook is only provided for reference as a brute force way to +# clear persistent connections on an Ansible server. This was a workaround +# for a problem with meta: reset_connection but should not be used in +# ansible release 2.6 or later. +- name: Clean up sockets with file module + file: + state: absent + path: "{{ home }}/.ansible/pc/" + delegate_to: 127.0.0.1 + +- name: "Display socket info after delete" + shell: "/bin/ls {{ home }}/.ansible" + args: + executable: /bin/bash + delegate_to: 127.0.0.1 + register: output + +- debug: msg="Local Socket Info {{ output['stdout_lines'] }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml new file mode 100644 index 0000000000..b043b1e35e --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml @@ -0,0 +1,41 @@ +--- +- set_fact: ignore_errors_httpapi='no' +- set_fact: ignore_errors_httpapi='yes' + when: ansible_connection == 'httpapi' + +- include: targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml + when: connection is not defined + +- include: targets/nxos_install_os/tasks/upgrade/enable_scp_server_provider.yaml + when: connection is defined + +- name: "Copy {{ si }} to bootflash" + nxos_file_copy: + local_file: "{{image_dir}}{{ si }}" + file_system: "bootflash:" + register: result + ignore_errors: "{{ ignore_errors_httpapi }}" + +- name: "Copy {{ si }} to bootflash" + nxos_file_copy: + local_file: "{{image_dir}}{{ si }}" + file_system: "bootflash:" + register: result + ignore_errors: "{{ ignore_errors_httpapi }}" + +- debug: + msg: "{{ item.key }} {{ item.value }}" + with_dict: "{{ result }}" + +- name: "Copy {{ ki }} to bootflash" + nxos_file_copy: + local_file: "{{image_dir}}/{{ ki }}" + file_system: "bootflash:" + register: result + when: ki is defined + ignore_errors: "{{ ignore_errors_httpapi }}" + +- debug: + msg: "{{ item.key }} {{ item.value }}" + with_dict: "{{ result }}" + when: ki is defined diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml new file mode 100644 index 0000000000..27157b690b --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files.yaml @@ -0,0 +1,10 @@ +--- +- name: "Delete Files To Make Room On Bootflash" + nxos_config: &remove_file + lines: + - terminal dont-ask + - allow delete boot-image + - "delete {{ item }}" + match: none + ignore_errors: yes + with_items: "{{ delete_image_list }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files_provider.yaml new file mode 100644 index 0000000000..0ba4280402 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/delete_files_provider.yaml @@ -0,0 +1,11 @@ +--- + - name: "Delete Files To Make Room On Bootflash using provider" + nxos_config: &remove_file + lines: + - terminal dont-ask + - allow delete boot-image + - "delete {{ item }}" + match: none + provider: "{{ connection }}" + ignore_errors: yes + with_items: "{{ delete_image_list }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml new file mode 100644 index 0000000000..f8a4e54e34 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml @@ -0,0 +1,5 @@ +--- +- name: "Setup - Turn on feature scp-server" + nxos_feature: + feature: scp-server + state: enabled diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server_provider.yaml new file mode 100644 index 0000000000..d1da1833bf --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/enable_scp_server_provider.yaml @@ -0,0 +1,6 @@ +--- +- name: "Setup - Turn on feature scp-server using provider" + nxos_feature: + feature: scp-server + state: enabled + provider: "{{ connection }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml new file mode 100644 index 0000000000..37c861435b --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml @@ -0,0 +1,23 @@ +--- +- include: targets/nxos_install_os/tasks/upgrade/delete_files.yaml + when: delete_image_list is defined + +- include: targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml + +- include: targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml + when: ki is defined and combined is undefined + +- include: targets/nxos_install_os/tasks/upgrade/install_system.yaml + when: combined is defined + +# Only needed when - meta: reset_connection does not work. Fixed in 2.6 +#- include: targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml + +- meta: reset_connection + +- name: "Check installed OS for newly installed version {{ tv }}" + nxos_command: + commands: ['show version | json'] + register: output + +- debug: msg="Version detected {{ output['stdout_lines'][0]['kickstart_ver_str'] }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_os_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_os_provider.yaml new file mode 100644 index 0000000000..9600101a92 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_os_provider.yaml @@ -0,0 +1,24 @@ +--- +- include: targets/nxos_install_os/tasks/upgrade/delete_files_provider.yaml + when: delete_image_list is defined + +- include: targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml + +- include: targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml + when: ki is defined and combined is undefined + +- include: targets/nxos_install_os/tasks/upgrade/install_system_provider.yaml + when: combined is defined + +# Only needed when - meta: reset_connection does not work. Fixed in 2.6 +#- include: targets/nxos_install_os/tasks/upgrade/clear_persistent_sockets.yaml + +- meta: reset_connection + +- name: "Check installed OS for newly installed version {{ tv }}" + nxos_command: + commands: ['show version | json'] + provider: "{{ connection }}" + register: output + +- debug: msg="Version detected {{ output['stdout_lines'][0]['kickstart_ver_str'] }}" diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml new file mode 100644 index 0000000000..ec1b34fccf --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml @@ -0,0 +1,24 @@ +--- +- name: "Install OS image {{ si }}" + check_mode: "{{ checkmode }}" + nxos_install_os: + system_image_file: "{{ si }}" + issu: "{{ issu }}" + register: result + +- debug: msg=" {{ result['install_state'] }}" + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + when: result.changed and not checkmode + +- debug: msg='Wait 5 mins to allow system to stabilize' + when: result.changed and not checkmode +- pause: + seconds: 300 + when: result.changed and not checkmode diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_system_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_system_provider.yaml new file mode 100644 index 0000000000..e8aee7b5f4 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_system_provider.yaml @@ -0,0 +1,25 @@ +--- +- name: "Install OS image {{ si }} using provider" + check_mode: "{{ checkmode }}" + nxos_install_os: + system_image_file: "{{ si }}" + issu: "{{ issu }}" + provider: "{{ connection }}" + register: result + +- debug: msg=" {{ result['install_state'] }}" + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + when: result.changed and not checkmode + +- debug: msg='Wait 5 mins to allow system to stabilize' + when: result.changed and not checkmode +- pause: + seconds: 300 + when: result.changed and not checkmode diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml new file mode 100644 index 0000000000..3599da1b10 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml @@ -0,0 +1,25 @@ +--- +- name: "Install OS image {{ si }}" + check_mode: "{{ checkmode }}" + nxos_install_os: + system_image_file: "{{ si }}" + kickstart_image_file: "{{ ki }}" + issu: "{{ issu }}" + register: result + +- debug: msg=" {{ result['install_state'] }}" + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + when: result.changed and not checkmode + +- debug: msg='Wait 5 mins to allow system to stabilize' + when: result.changed and not checkmode +- pause: + seconds: 300 + when: result.changed and not checkmode diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml new file mode 100644 index 0000000000..07aefbf077 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml @@ -0,0 +1,26 @@ +--- +- name: "Install OS image {{ si }} using provider" + check_mode: "{{ checkmode }}" + nxos_install_os: + system_image_file: "{{ si }}" + kickstart_image_file: "{{ ki }}" + issu: "{{ issu }}" + provider: "{{ connection }}" + register: result + +- debug: msg=" {{ result['install_state'] }}" + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + when: result.changed and not checkmode + +- debug: msg='Wait 5 mins to allow system to stabilize' + when: result.changed and not checkmode +- pause: + seconds: 300 + when: result.changed and not checkmode diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml new file mode 100644 index 0000000000..cc4bd30ab0 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/main_os_install.yaml @@ -0,0 +1,10 @@ +--- +- debug: msg="***WARNING*** Remove meta end_play to verify this module ***WARNING***" + +- meta: end_play + +- include: targets/nxos_install_os/tasks/upgrade/install_os.yaml + when: connection is not defined + +- include: targets/nxos_install_os/tasks/upgrade/install_os_provider.yaml + when: connection is defined diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload.yaml new file mode 100644 index 0000000000..b4422b140f --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload.yaml @@ -0,0 +1,22 @@ +--- +- name: "Reload to upgrade to OS image {{ si }}" + nxos_config: + lines: + - terminal dont-ask + - no boot nxos + - "boot nxos bootflash:{{ si }}" + - reload + match: none + ignore_errors: yes + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + +- debug: msg='Wait 5 mins to allow system to stabilize' +- pause: + seconds: 300 diff --git a/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload_provider.yaml b/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload_provider.yaml new file mode 100644 index 0000000000..24e45094f6 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/set_boot_pointer_and_reload_provider.yaml @@ -0,0 +1,23 @@ +--- +- name: "Reload to upgrade to OS image {{ si }} using provider" + nxos_config: + lines: + - terminal dont-ask + - no boot nxos + - "boot nxos bootflash:{{ si }}" + - reload + match: none + provider: "{{ connection }}" + ignore_errors: yes + +- name: Wait for device to come back up with new image + wait_for: + port: 22 + state: started + timeout: 500 + delay: 60 + host: "{{ inventory_hostname }}" + +- debug: msg='Wait 5 mins to allow system to stabilize' +- pause: + seconds: 300 diff --git a/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml b/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml new file mode 100644 index 0000000000..9f1ef8e2ff --- /dev/null +++ b/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml @@ -0,0 +1,56 @@ +--- +- debug: msg="START connection={{ ansible_connection }} nxos_os_install upgrade" +- debug: msg="Using provider={{ connection.transport }}" + when: connection is defined + +- set_fact: checkmode='no' +- set_fact: issu='desired' + +- set_fact: image_dir='/Users/mwiebe/Projects/nxos_ansible/images/' + +- set_fact: + delete_image_list: + - nxos.7.0.3.I7.2.bin + - nxos.7.0.3.I7.3.bin + +#---------------------------------------------------------# +# Upgrade to 6.0(2)U6(1a) # +#---------------------------------------------------------# + +- set_fact: si='n3000-uk9.6.0.2.U6.1a.bin' +- set_fact: ki='n3000-uk9-kickstart.6.0.2.U6.1a.bin' + +- name: Upgrade to U6.1a + include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + +#---------------------------------------------------------# +# Upgrade to 6.0(2)U6(2a) # +#---------------------------------------------------------# + +- set_fact: si='n3000-uk9.6.0.2.U6.2a.bin' +- set_fact: ki='n3000-uk9-kickstart.6.0.2.U6.2a.bin' + +- name: Upgrade to U6.2a + include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + +#---------------------------------------------------------# +# Upgrade to 6.0(2)U6(3a) # +#---------------------------------------------------------# + +- set_fact: si='n3000-uk9.6.0.2.U6.3a.bin' +- set_fact: ki='n3000-uk9-kickstart.6.0.2.U6.3a.bin' + +- name: Upgrade to U6.3a + include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + +#---------------------------------------------------------# +# Upgrade to 7.0(3)I7(3) # +#---------------------------------------------------------# + +- set_fact: si='nxos.7.0.3.I7.2.bin' +- set_fact: combined='true' + +- name: Upgrade to 7.0.3.I7.2 + include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml + +- debug: msg="END connection={{ ansible_connection }} nxos_os_install upgrade" diff --git a/test/integration/targets/nxos_vlan/tests/common/sanity.yaml b/test/integration/targets/nxos_vlan/tests/common/sanity.yaml index 92941ab2f1..54351275d6 100644 --- a/test/integration/targets/nxos_vlan/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_vlan/tests/common/sanity.yaml @@ -7,6 +7,13 @@ - set_fact: testint2="{{ nxos_int2 }}" - block: + - name: Install and Enable FabricPath feature set + nxos_config: + lines: + - install feature-set fabricpath + - feature-set fabricpath + when: platform is search('N5K|N7K') + - name: "Enable feature vn segment" nxos_config: commands: @@ -114,41 +121,41 @@ when: platform is search('N3K|N7K') # Uncomment this once the get_capabilities() work on nxapi as well -# - name: Change mode -# nxos_vlan: &mode1 -# vlan_id: 50 -# mode: fabricpath -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *true -# when: platform is search('N5k|N7K') -# -# - name: "mode1 Idempotence" -# nxos_vlan: *mode1 -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *false -# when: platform is search('N5k|N7K') -# -# - name: Change mode again -# nxos_vlan: &mode2 -# vlan_id: 50 -# mode: ce -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *true -# when: platform is search('N5k|N7K') -# -# - name: "mode2 Idempotence" -# nxos_vlan: *mode2 -# register: result -# when: platform is search('N5k|N7K') -# -# - assert: *false -# when: platform is search('N5k|N7K') + - name: Change mode + nxos_vlan: &mode1 + vlan_id: 50 + mode: fabricpath + register: result + when: platform is search('N5K|N7K') + + - assert: *true + when: platform is search('N5K|N7K') + + - name: "mode1 Idempotence" + nxos_vlan: *mode1 + register: result + when: platform is search('N5K|N7K') + + - assert: *false + when: platform is search('N5K|N7K') + + - name: Change mode again + nxos_vlan: &mode2 + vlan_id: 50 + mode: ce + register: result + when: platform is search('N5K|N7K') + + - assert: *true + when: platform is search('N5K|N7K') + + - name: "mode2 Idempotence" + nxos_vlan: *mode2 + register: result + when: platform is search('N5K|N7K') + + - assert: *false + when: platform is search('N5K|N7K') - name: Ensure VLAN is NOT on the device nxos_vlan: &no_vlan -- cgit v1.2.1