From c53e3ca8e9834259b79c6b8dec9cf8219c4ae113 Mon Sep 17 00:00:00 2001 From: Mike Wiebe Date: Wed, 31 Oct 2018 05:23:43 -0400 Subject: [PATCH] Add force disruptive option (#47694) * Use expect module to copy files * Add force option for disruptive upgrades * Revert changes to copy_kick_system_images.yaml --- .../modules/network/nxos/nxos_install_os.py | 26 ++++++++++++++++--- .../tasks/upgrade/install_os.yaml | 1 + .../tasks/upgrade/install_os_provider.yaml | 1 + .../nxos_install_os/tests/common/upgrade.yaml | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_install_os.py b/lib/ansible/modules/network/nxos/nxos_install_os.py index 22ecb8b0757..eb80847fab6 100644 --- a/lib/ansible/modules/network/nxos/nxos_install_os.py +++ b/lib/ansible/modules/network/nxos/nxos_install_os.py @@ -345,12 +345,32 @@ def massage_install_data(data): def build_install_cmd_set(issu, image, kick, type): commands = ['terminal dont-ask'] + + # Different NX-OS plaforms behave differently for + # disruptive and non-disruptive upgrade paths. + # + # 1) Combined kickstart/system image: + # * Use option 'non-disruptive' for issu. + # * Omit option non-disruptive' for distruptive upgrades. + # 2) Separate kickstart + system images. + # * Omit hidden 'force' option for issu. + # * Use hidden 'force' option for disruptive upgrades. if re.search(r'required|desired|yes', issu): - issu_cmd = 'non-disruptive' + if kick is None: + issu_cmd = 'non-disruptive' + else: + issu_cmd = '' else: - issu_cmd = '' + if kick is None: + issu_cmd = '' + else: + issu_cmd = 'force' + if type == 'impact': rootcmd = 'show install all impact' + # The force option is not available for the impact command. + if kick: + issu_cmd = '' else: rootcmd = 'install all' if kick is None: @@ -358,7 +378,7 @@ def build_install_cmd_set(issu, image, kick, type): '%s nxos %s %s' % (rootcmd, image, issu_cmd)) else: commands.append( - '%s system %s kickstart %s' % (rootcmd, image, kick)) + '%s %s system %s kickstart %s' % (rootcmd, issu_cmd, image, kick)) return commands 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 index 37c861435be..6dc811cdc7a 100644 --- a/test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml +++ b/test/integration/targets/nxos_install_os/tasks/upgrade/install_os.yaml @@ -3,6 +3,7 @@ when: delete_image_list is defined - include: targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml + when: copy_images is defined - include: targets/nxos_install_os/tasks/upgrade/install_with_kick.yaml when: ki is defined and combined is undefined 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 index 9600101a92d..b8381aa002c 100644 --- 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 @@ -3,6 +3,7 @@ when: delete_image_list is defined - include: targets/nxos_install_os/tasks/upgrade/copy_kick_system_images.yaml + when: copy_images is defined - include: targets/nxos_install_os/tasks/upgrade/install_with_kick_provider.yaml when: ki is defined and combined is undefined diff --git a/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml b/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml index 9f1ef8e2ffa..8444cb67475 100644 --- a/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml +++ b/test/integration/targets/nxos_install_os/tests/common/upgrade.yaml @@ -5,6 +5,7 @@ - set_fact: checkmode='no' - set_fact: issu='desired' +- set_fact: copy_images='yes' - set_fact: image_dir='/Users/mwiebe/Projects/nxos_ansible/images/'