diff --git a/lib/ansible/module_utils/network/nxos/nxos.py b/lib/ansible/module_utils/network/nxos/nxos.py index 79195be0d73..1b54648deca 100644 --- a/lib/ansible/module_utils/network/nxos/nxos.py +++ b/lib/ansible/module_utils/network/nxos/nxos.py @@ -429,6 +429,12 @@ class LocalNxapi: def load_config(self, commands, return_error=False, opts=None, replace=None): """Sends the ordered set of commands to the device """ + + if opts is None: + opts = {} + + responses = [] + if replace: device_info = self.get_device_info() if '9K' not in device_info.get('network_os_platform', ''): @@ -436,12 +442,30 @@ class LocalNxapi: commands = 'config replace {0}'.format(replace) commands = to_list(commands) - msg = self.send_request(commands, output='config', check_status=True, - return_error=return_error, opts=opts) + try: + resp = self.send_request(commands, output='config', check_status=True, + return_error=return_error, opts=opts) + except ValueError as exc: + code = getattr(exc, 'code', 1) + message = getattr(exc, 'err', exc) + err = to_text(message, errors='surrogate_then_replace') + if opts.get('ignore_timeout') and code: + responses.append(code) + return responses + elif code and 'no graceful-restart' in err: + if 'ISSU/HA will be affected if Graceful Restart is disabled' in err: + msg = [''] + responses.extend(msg) + return responses + else: + self._module.fail_json(msg=err) + elif code: + self._module.fail_json(msg=err) + if return_error: - return msg + return resp else: - return [] + return responses.extend(resp) def get_diff(self, candidate=None, running=None, diff_match='line', diff_ignore_lines=None, path=None, diff_replace='line'): diff = {} diff --git a/lib/ansible/modules/network/nxos/nxos_install_os.py b/lib/ansible/modules/network/nxos/nxos_install_os.py index ac43ba1d24f..5f0e4e16a43 100644 --- a/lib/ansible/modules/network/nxos/nxos_install_os.py +++ b/lib/ansible/modules/network/nxos/nxos_install_os.py @@ -222,6 +222,8 @@ def parse_show_install(data): ud['server_error'] = True elif data == -32603: ud['server_error'] = True + elif data == 1: + ud['server_error'] = True return ud else: ud['list_data'] = data.split('\n') diff --git a/test/integration/targets/nxos_install_os/defaults/main.yaml b/test/integration/targets/nxos_install_os/defaults/main.yaml index 99533903e55..abd1068ba22 100644 --- a/test/integration/targets/nxos_install_os/defaults/main.yaml +++ b/test/integration/targets/nxos_install_os/defaults/main.yaml @@ -1,2 +1,2 @@ --- -testcase: "upgrade" +testcase: " {{ testcase }}" diff --git a/test/integration/targets/nxos_install_os/meta/main.yml b/test/integration/targets/nxos_install_os/meta/main.yml index ae741cbdc71..58de46745f0 100644 --- a/test/integration/targets/nxos_install_os/meta/main.yml +++ b/test/integration/targets/nxos_install_os/meta/main.yml @@ -1,2 +1,3 @@ dependencies: - - prepare_nxos_tests + # Prepare nxos tests is not required for this test. + #- prepare_nxos_tests diff --git a/test/integration/targets/nxos_install_os/tasks/main.yaml b/test/integration/targets/nxos_install_os/tasks/main.yaml index ec1cfa5019e..60614acac3e 100644 --- a/test/integration/targets/nxos_install_os/tasks/main.yaml +++ b/test/integration/targets/nxos_install_os/tasks/main.yaml @@ -1,5 +1,12 @@ --- -- { include: network_cli.yaml, tags: ['cli'] } -- { include: network_local.yaml, tags: ['local'] } -- { include: httpapi.yaml, tags: ['httpapi'] } -- { include: nxapi.yaml, tags: ['nxapi'] } +# Upgrade using SSH +- include: network_cli.yaml + when: connection_type == 'network_cli' +- include: network_local.yaml + when: connection_type == 'cli_local' + +# Upgrade using NX-API +- include: httpapi.yaml + when: connection_type == 'httpapi' +- include: nxapi.yaml + when: connection_type == 'nxapi_local' 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 index 7f8383f76dd..e1c57cad956 100644 --- 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 @@ -5,14 +5,20 @@ - include: targets/nxos_install_os/tasks/upgrade/enable_scp_server.yaml +- name: 'Remove SSH known_hosts file before scp of image file' + nxos_command: + commands: 'run bash rm /var/home/admin/.ssh/known_hosts' + provider: "{{ connection }}" + ignore_errors: yes + - name: "Copy {{ si }} to bootflash" nxos_file_copy: file_pull: True file_pull_timeout: 1200 remote_file: "{{image_dir}}{{ si }}" - remote_scp_server: 192.168.1.1 - remote_scp_server_user: scp_user - remote_scp_server_password: scp_password + remote_scp_server: "{{ remote_scp_server }}" + remote_scp_server_user: "{{ remote_scp_user }}" + remote_scp_server_password: "{{ remote_scp_password }}" register: result #- name: "Copy {{ si }} to bootflash" @@ -33,9 +39,9 @@ file_pull: True file_pull_timeout: 1200 remote_file: "{{image_dir}}{{ ki }}" - remote_scp_server: 192.168.1.1 - remote_scp_server_user: scp_user - remote_scp_server_password: scp_password + remote_scp_server: "{{ remote_scp_server }}" + remote_scp_server_user: "{{ remote_scp_user }}" + remote_scp_server_password: "{{ remote_scp_password }}" when: ki is defined register: result 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 index d3b4dd89618..9b647f459b5 100644 --- a/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml @@ -8,12 +8,20 @@ register: result when: not force -- name: "Set OS image {{ si }} boot pointers" +- name: "Remove old boot pointers if any" nxos_config: lines: - no boot nxos - no boot kickstart - no boot system + match: line + provider: "{{ connection }}" + ignore_errors: yes + when: force + +- name: "Set OS image {{ si }} boot pointers" + nxos_config: + lines: - "boot nxos bootflash:{{ si }}" - copy run start match: line @@ -21,8 +29,10 @@ when: force - name: "Boot image {{ si }} using reload" - nxos_command: - commands: 'terminal dont-ask ; reload' + nxos_config: + lines: + - 'terminal dont-ask' + - 'reload' provider: "{{ connection }}" ignore_errors: yes when: force diff --git a/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml index 6c4eab04717..ff1f5a66199 100644 --- a/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml +++ b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro.yaml @@ -7,13 +7,13 @@ - set_fact: image_dir='/auto/fe_ssr/agents-ci/agents_images/release_images/greensboro/REL_7_0_3_I7_4/' - set_fact: checkmode='no' -- set_fact: issu='yes' -- set_fact: copy_images=False +- set_fact: issu='desired' +- set_fact: copy_images=True # Set boot pointers and reload - set_fact: force=False -- set_fact: delete_files=False +- set_fact: delete_files=True - set_fact: delete_image_list: - nxos*.bin diff --git a/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml new file mode 100644 index 00000000000..c6c3ebdd1a7 --- /dev/null +++ b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_greensboro_force.yaml @@ -0,0 +1,41 @@ +--- +- debug: msg="START connection={{ ansible_connection }} nxos_os_install upgrade" +- debug: msg="Using provider={{ connection.transport }}" + when: connection is defined + +# Set directory pointer to software images +- set_fact: image_dir='/auto/fe_ssr/agents-ci/agents_images/release_images/greensboro/REL_7_0_3_I7_4/' + +- set_fact: checkmode='no' +- set_fact: issu='desired' +- set_fact: copy_images=True + +# Set boot pointers and reload +- set_fact: force=True + +- set_fact: delete_files=True +- set_fact: + delete_image_list: + - nxos*.bin + +#---------------------------------------------------------# +# Remove incompatible features # +#---------------------------------------------------------# +- name: Unconfigure features that will conflict with upgrade + nxos_config: + lines: + - terminal dont-ask + - no feature nv overlay + - no nxapi ssl protocols + - no nxapi ssl ciphers weak + match: none + provider: "{{ connection }}" + ignore_errors: yes + +#---------------------------------------------------------# +# Upgrade Device # +#---------------------------------------------------------# +- set_fact: si='nxos.7.0.3.I7.4.bin' + +- name: Upgrade N9k Device to Greensboro Release Image + include: targets/nxos_install_os/tasks/upgrade/main_os_install.yaml diff --git a/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml index 1eda79c74ad..cad82502978 100644 --- a/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml +++ b/test/integration/targets/nxos_install_os/tests/common/upgrade_n9k_hamilton.yaml @@ -8,12 +8,12 @@ - set_fact: checkmode='no' - set_fact: issu='desired' -- set_fact: copy_images=False +- set_fact: copy_images=True # Set boot pointers and reload - set_fact: force=False -- set_fact: delete_files=False +- set_fact: delete_files=True - set_fact: delete_image_list: - nxos*.bin