From 85a3ee1a51b378d40a44e0b69d8717b50d1a4007 Mon Sep 17 00:00:00 2001 From: xumia Date: Thu, 9 Jul 2020 07:59:30 +0000 Subject: [PATCH 01/13] Support to verify reboot for secure boot --- scripts/fast-reboot | 10 +++++---- scripts/reboot | 10 +++++---- sonic_installer/bootloader/aboot.py | 7 +++++++ sonic_installer/bootloader/bootloader.py | 26 ++++++++++++++++++++++++ sonic_installer/main.py | 10 +++++++++ 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 0d874e7f14..7ed9aa8c2f 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -32,6 +32,7 @@ EXIT_SYNCD_SHUTDOWN=11 EXIT_FAST_REBOOT_DUMP_FAILURE=12 EXIT_FILTER_FDB_ENTRIES_FAILURE=13 EXIT_NO_CONTROL_PLANE_ASSISTANT=20 +EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21 function error() { @@ -304,10 +305,11 @@ function reboot_pre_check() exit ${EXIT_FILE_SYSTEM_FULL} fi - # Make sure that the next image exists - if [[ ! -d ${IMAGE_PATH} ]]; then - debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..." - exit ${EXIT_NEXT_IMAGE_NOT_EXISTS} + # Verify reboot by sonic_installer + local message=$(sonic_installer verify-reboot) + if [ $? -ne 0 ]; then + debug "Failed to verify next reboot by running command: sonic_installer verify-reboot, result message: ${message}" + exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi # Make sure ASIC configuration has not changed between images diff --git a/scripts/reboot b/scripts/reboot index 6a030c15c9..d59f2c2ae7 100755 --- a/scripts/reboot +++ b/scripts/reboot @@ -16,6 +16,7 @@ PLAT_REBOOT="platform_reboot" REBOOT_CAUSE_FILE="/host/reboot-cause/reboot-cause.txt" VERBOSE=no EXIT_NEXT_IMAGE_NOT_EXISTS=4 +EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21 function debug() { @@ -79,10 +80,11 @@ function reboot_pre_check() fi rm ${filename} - # Make sure that the next image exists - if [[ ! -d ${IMAGE_PATH} ]]; then - VERBOSE=yes debug "Next image ${NEXT_SONIC_IMAGE} doesn't exist ..." - exit ${EXIT_NEXT_IMAGE_NOT_EXISTS} + # Verify reboot by sonic_installer + local message=$(sonic_installer verify-reboot) + if [ $? -ne 0 ]; then + VERBOSE=yes debug "Failed to verify next reboot by running command: sonic_installer verify-reboot, result message: ${message}" + exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi } diff --git a/sonic_installer/bootloader/aboot.py b/sonic_installer/bootloader/aboot.py index 1933921512..4b4091f2a4 100644 --- a/sonic_installer/bootloader/aboot.py +++ b/sonic_installer/bootloader/aboot.py @@ -129,6 +129,13 @@ def verify_binary_image(self, image_path): except subprocess.CalledProcessError: return False + def verify_reboot(self): + if not super(AbootBootloader, self).verify_reboot(): + return False + image = self.get_next_image() + image_path = self.get_image_path(image) + '/sonic.swi' + return self._verify_secureboot_image(image_path) + def _verify_secureboot_image(self, image_path): if isSecureboot(): cert = self.getCert(image_path) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index 78bd05c61c..eb368fb6ca 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -2,6 +2,15 @@ Abstract Bootloader class """ +import sys +from os import path + +from ..common import ( + HOST_PATH, + IMAGE_DIR_PREFIX, + IMAGE_PREFIX, +) + class Bootloader(object): NAME = None @@ -43,8 +52,25 @@ def verify_binary_image(self, image_path): """verify that the image is supported by the bootloader""" raise NotImplementedError + def verify_reboot(self): + """verify the image for reboot""" + image = self.get_next_image() + image_path = self.get_image_path(image) + if not path.exists(image_path): + sys.stderr.write('Next image {0} doesn\'t exist ...\n'.format(image)) + return False + return True + + def get_image_path + @classmethod def detect(cls): """returns True if the bootloader is in use""" return False + @classmethod + def get_image_path(cls, image): + """returns the image path""" + prefix = Host_PATH + '/' + IMAGE_DIR_PREFIX + return image.replace(IMAGE_PREFIX, prefix) + diff --git a/sonic_installer/main.py b/sonic_installer/main.py index 3c68bcd843..491f08a52e 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -476,5 +476,15 @@ def rollback_docker(container_name): click.echo('Done') +# verify reboot +@cli.command('verify_reboot') +def verify_reboot(): + """ Verify the image for reboot""" + bootloader = get_bootloader() + if not bootloader.verify_reboot(): + click.echo('Failed') + sys.exit(1) + click.echo('Done') + if __name__ == '__main__': cli() From bb9e2878c18ee8a4cda8fb28d45ec4c451d3662a Mon Sep 17 00:00:00 2001 From: xumia Date: Thu, 9 Jul 2020 08:31:53 +0000 Subject: [PATCH 02/13] Support to verify reboot for secure boot --- sonic_installer/bootloader/bootloader.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index eb368fb6ca..ed95a95a6a 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -61,8 +61,6 @@ def verify_reboot(self): return False return True - def get_image_path - @classmethod def detect(cls): """returns True if the bootloader is in use""" From 3a374f34b218d8a863e8a0d0a69dc78bcd2e1bd2 Mon Sep 17 00:00:00 2001 From: xumia Date: Thu, 9 Jul 2020 11:52:40 +0000 Subject: [PATCH 03/13] Fix type issue --- sonic_installer/bootloader/bootloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index ed95a95a6a..d204d55eff 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -69,6 +69,6 @@ def detect(cls): @classmethod def get_image_path(cls, image): """returns the image path""" - prefix = Host_PATH + '/' + IMAGE_DIR_PREFIX + prefix = HOST_PATH + '/' + IMAGE_DIR_PREFIX return image.replace(IMAGE_PREFIX, prefix) From b10af372026d786f784478f72c7a05da16c2f810 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 00:53:58 +0000 Subject: [PATCH 04/13] Change the verification command to verify-next-image --- scripts/fast-reboot | 6 +++--- scripts/reboot | 6 +++--- sonic_installer/bootloader/aboot.py | 11 ++++++----- sonic_installer/bootloader/bootloader.py | 6 +++--- sonic_installer/main.py | 8 ++++---- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 02af0aa227..eb3832be71 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -306,10 +306,10 @@ function reboot_pre_check() exit ${EXIT_FILE_SYSTEM_FULL} fi - # Verify reboot by sonic_installer - local message=$(sonic_installer verify-reboot) + # Verify the next image by sonic_installer + local message=$(sonic_installer verify-next-image 2>&1) if [ $? -ne 0 ]; then - debug "Failed to verify next reboot by running command: sonic_installer verify-reboot, result message: ${message}" + debug "Failed to verify next image by running command: sonic_installer verify-next-image, result message: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi diff --git a/scripts/reboot b/scripts/reboot index d59f2c2ae7..b7b4701341 100755 --- a/scripts/reboot +++ b/scripts/reboot @@ -80,10 +80,10 @@ function reboot_pre_check() fi rm ${filename} - # Verify reboot by sonic_installer - local message=$(sonic_installer verify-reboot) + # Verify the next image by sonic_installer + local message=$(sonic_installer verify-next-image 2>&1) if [ $? -ne 0 ]; then - VERBOSE=yes debug "Failed to verify next reboot by running command: sonic_installer verify-reboot, result message: ${message}" + VERBOSE=yes debug "Failed to verify the next image by running command: sonic_installer verify-next-image, result message: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi } diff --git a/sonic_installer/bootloader/aboot.py b/sonic_installer/bootloader/aboot.py index 4b4091f2a4..a985044871 100644 --- a/sonic_installer/bootloader/aboot.py +++ b/sonic_installer/bootloader/aboot.py @@ -23,6 +23,7 @@ from .bootloader import Bootloader _secureboot = None +DEFAULT_SWI_IMAGE = 'sonic.swi' # For the signature format, see: https://github.com/aristanetworks/swi-tools/tree/master/switools SWI_SIG_FILE_NAME = 'swi-signature' @@ -110,9 +111,9 @@ def remove_image(self, image): self._boot_config_set(SWI=image_path, SWI_DEFAULT=image_path) click.echo("Set next and default boot to current image %s" % current) - image_dir = image.replace(IMAGE_PREFIX, IMAGE_DIR_PREFIX) + image_path = self.get_image_path(image) click.echo('Removing image root filesystem...') - subprocess.call(['rm','-rf', os.path.join(HOST_PATH, image_dir)]) + subprocess.call(['rm','-rf', image_path]) click.echo('Image removed') def get_binary_image_version(self, image_path): @@ -129,11 +130,11 @@ def verify_binary_image(self, image_path): except subprocess.CalledProcessError: return False - def verify_reboot(self): - if not super(AbootBootloader, self).verify_reboot(): + def verify-next-image(self): + if not super(AbootBootloader, self).verify-next-image(): return False image = self.get_next_image() - image_path = self.get_image_path(image) + '/sonic.swi' + image_path = os.path.join(self.get_image_path(image), DEFAULT_SWI_IMAGE) return self._verify_secureboot_image(image_path) def _verify_secureboot_image(self, image_path): diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index d204d55eff..ef350c0fe8 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -52,8 +52,8 @@ def verify_binary_image(self, image_path): """verify that the image is supported by the bootloader""" raise NotImplementedError - def verify_reboot(self): - """verify the image for reboot""" + def verify-next-image(self): + """verify the next image for reboot""" image = self.get_next_image() image_path = self.get_image_path(image) if not path.exists(image_path): @@ -69,6 +69,6 @@ def detect(cls): @classmethod def get_image_path(cls, image): """returns the image path""" - prefix = HOST_PATH + '/' + IMAGE_DIR_PREFIX + prefix = path.join(Host_PATH, IMAGE_DIR_PREFIX) return image.replace(IMAGE_PREFIX, prefix) diff --git a/sonic_installer/main.py b/sonic_installer/main.py index 491f08a52e..3853f0b20f 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -476,12 +476,12 @@ def rollback_docker(container_name): click.echo('Done') -# verify reboot -@cli.command('verify_reboot') +# verify the next image +@cli.command('verify-next-image') def verify_reboot(): - """ Verify the image for reboot""" + """ Verify the next image for reboot""" bootloader = get_bootloader() - if not bootloader.verify_reboot(): + if not bootloader.verify-next-image(): click.echo('Failed') sys.exit(1) click.echo('Done') From db0a9d2ac445d91175efcb4f5bfa4e217328c786 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 01:23:12 +0000 Subject: [PATCH 05/13] Fix python function error --- scripts/fast-reboot | 4 ++-- scripts/reboot | 4 ++-- sonic_installer/bootloader/aboot.py | 4 ++-- sonic_installer/bootloader/bootloader.py | 2 +- sonic_installer/main.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index eb3832be71..de8a417155 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -307,9 +307,9 @@ function reboot_pre_check() fi # Verify the next image by sonic_installer - local message=$(sonic_installer verify-next-image 2>&1) + local message=$(sonic_installer verify_next_image 2>&1) if [ $? -ne 0 ]; then - debug "Failed to verify next image by running command: sonic_installer verify-next-image, result message: ${message}" + debug "Failed to verify next image by running command: sonic_installer verify_next_image, result message: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi diff --git a/scripts/reboot b/scripts/reboot index b7b4701341..f9d84b168e 100755 --- a/scripts/reboot +++ b/scripts/reboot @@ -81,9 +81,9 @@ function reboot_pre_check() rm ${filename} # Verify the next image by sonic_installer - local message=$(sonic_installer verify-next-image 2>&1) + local message=$(sonic_installer verify_next_image 2>&1) if [ $? -ne 0 ]; then - VERBOSE=yes debug "Failed to verify the next image by running command: sonic_installer verify-next-image, result message: ${message}" + VERBOSE=yes debug "Failed to verify the next image by running command: sonic_installer verify_next_image, result message: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi } diff --git a/sonic_installer/bootloader/aboot.py b/sonic_installer/bootloader/aboot.py index a985044871..3cc43a457f 100644 --- a/sonic_installer/bootloader/aboot.py +++ b/sonic_installer/bootloader/aboot.py @@ -130,8 +130,8 @@ def verify_binary_image(self, image_path): except subprocess.CalledProcessError: return False - def verify-next-image(self): - if not super(AbootBootloader, self).verify-next-image(): + def verify_next_image(self): + if not super(AbootBootloader, self).verify_next_image(): return False image = self.get_next_image() image_path = os.path.join(self.get_image_path(image), DEFAULT_SWI_IMAGE) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index ef350c0fe8..277fe2b9d2 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -52,7 +52,7 @@ def verify_binary_image(self, image_path): """verify that the image is supported by the bootloader""" raise NotImplementedError - def verify-next-image(self): + def verify_next_image(self): """verify the next image for reboot""" image = self.get_next_image() image_path = self.get_image_path(image) diff --git a/sonic_installer/main.py b/sonic_installer/main.py index 3853f0b20f..94646d86a0 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -477,11 +477,11 @@ def rollback_docker(container_name): click.echo('Done') # verify the next image -@cli.command('verify-next-image') +@cli.command('verify_next_image') def verify_reboot(): """ Verify the next image for reboot""" bootloader = get_bootloader() - if not bootloader.verify-next-image(): + if not bootloader.verify_next_image(): click.echo('Failed') sys.exit(1) click.echo('Done') From 17118afc37b3132a4e5e0930d72464a23fedde46 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 02:27:24 +0000 Subject: [PATCH 06/13] Fix Host_PATH case issue --- sonic_installer/bootloader/bootloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index 277fe2b9d2..259c81928d 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -69,6 +69,6 @@ def detect(cls): @classmethod def get_image_path(cls, image): """returns the image path""" - prefix = path.join(Host_PATH, IMAGE_DIR_PREFIX) + prefix = path.join(HOST_PATH, IMAGE_DIR_PREFIX) return image.replace(IMAGE_PREFIX, prefix) From 7da32e3100731028d8885b53bf41c87888e2f994 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 05:22:17 +0000 Subject: [PATCH 07/13] Fix some messages issue --- scripts/fast-reboot | 2 +- scripts/reboot | 2 +- sonic_installer/bootloader/bootloader.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index de8a417155..7f5e3e5e14 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -309,7 +309,7 @@ function reboot_pre_check() # Verify the next image by sonic_installer local message=$(sonic_installer verify_next_image 2>&1) if [ $? -ne 0 ]; then - debug "Failed to verify next image by running command: sonic_installer verify_next_image, result message: ${message}" + debug "Failed to verify next image: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi diff --git a/scripts/reboot b/scripts/reboot index f9d84b168e..720a43bc76 100755 --- a/scripts/reboot +++ b/scripts/reboot @@ -83,7 +83,7 @@ function reboot_pre_check() # Verify the next image by sonic_installer local message=$(sonic_installer verify_next_image 2>&1) if [ $? -ne 0 ]; then - VERBOSE=yes debug "Failed to verify the next image by running command: sonic_installer verify_next_image, result message: ${message}" + VERBOSE=yes debug "Failed to verify next image: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} fi } diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index 259c81928d..75f7c0c913 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -57,7 +57,7 @@ def verify_next_image(self): image = self.get_next_image() image_path = self.get_image_path(image) if not path.exists(image_path): - sys.stderr.write('Next image {0} doesn\'t exist ...\n'.format(image)) + sys.stdout.write('Next image {0} doesn\'t exist ...\n'.format(image)) return False return True From 7914998b3dd19ecd326d61bb26a551dd1bbc3119 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 07:36:34 +0000 Subject: [PATCH 08/13] Remove not neccessary message --- sonic_installer/bootloader/bootloader.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index 75f7c0c913..d1739ae326 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -56,10 +56,7 @@ def verify_next_image(self): """verify the next image for reboot""" image = self.get_next_image() image_path = self.get_image_path(image) - if not path.exists(image_path): - sys.stdout.write('Next image {0} doesn\'t exist ...\n'.format(image)) - return False - return True + return path.exists(image_path) @classmethod def detect(cls): From 7e50016ad5c2a6c99c7fe4ba6231a62924819313 Mon Sep 17 00:00:00 2001 From: xumia Date: Fri, 10 Jul 2020 07:59:45 +0000 Subject: [PATCH 09/13] not to import no use module --- sonic_installer/bootloader/bootloader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sonic_installer/bootloader/bootloader.py b/sonic_installer/bootloader/bootloader.py index d1739ae326..54054d4c55 100644 --- a/sonic_installer/bootloader/bootloader.py +++ b/sonic_installer/bootloader/bootloader.py @@ -2,7 +2,6 @@ Abstract Bootloader class """ -import sys from os import path from ..common import ( From 40d0222d43097a88fabcc4bde4ef4b6108a4309f Mon Sep 17 00:00:00 2001 From: xumia Date: Sat, 11 Jul 2020 00:17:03 +0000 Subject: [PATCH 10/13] Change command to use hyphens --- sonic_installer/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_installer/main.py b/sonic_installer/main.py index 94646d86a0..d9847e95a2 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -477,8 +477,8 @@ def rollback_docker(container_name): click.echo('Done') # verify the next image -@cli.command('verify_next_image') -def verify_reboot(): +@cli.command('verify-next-image') +def verify_next_image(): """ Verify the next image for reboot""" bootloader = get_bootloader() if not bootloader.verify_next_image(): From 9f86eb0c811b372955494ea293c03d2c01f00ea2 Mon Sep 17 00:00:00 2001 From: xumia Date: Sat, 11 Jul 2020 01:02:57 +0000 Subject: [PATCH 11/13] Simplify the command verify-next-image --- scripts/fast-reboot | 7 +------ scripts/reboot | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 7f5e3e5e14..3205066ce1 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -33,7 +33,6 @@ EXIT_SYNCD_SHUTDOWN=11 EXIT_FAST_REBOOT_DUMP_FAILURE=12 EXIT_FILTER_FDB_ENTRIES_FAILURE=13 EXIT_NO_CONTROL_PLANE_ASSISTANT=20 -EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21 function error() { @@ -307,11 +306,7 @@ function reboot_pre_check() fi # Verify the next image by sonic_installer - local message=$(sonic_installer verify_next_image 2>&1) - if [ $? -ne 0 ]; then - debug "Failed to verify next image: ${message}" - exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} - fi + sonic_installer verify-next-image # Make sure ASIC configuration has not changed between images ASIC_CONFIG_CHECK_SCRIPT="/usr/bin/asic_config_check" diff --git a/scripts/reboot b/scripts/reboot index 720a43bc76..889634bbf4 100755 --- a/scripts/reboot +++ b/scripts/reboot @@ -81,7 +81,7 @@ function reboot_pre_check() rm ${filename} # Verify the next image by sonic_installer - local message=$(sonic_installer verify_next_image 2>&1) + local message=$(sonic_installer verify-next-image 2>&1) if [ $? -ne 0 ]; then VERBOSE=yes debug "Failed to verify next image: ${message}" exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} From fbce19a3ead4e0d12955a4609a43685b58051de3 Mon Sep 17 00:00:00 2001 From: xumia Date: Sat, 11 Jul 2020 23:28:01 +0000 Subject: [PATCH 12/13] Add fast-reboot exit code --- scripts/fast-reboot | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 3205066ce1..bfce5add29 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -33,6 +33,7 @@ EXIT_SYNCD_SHUTDOWN=11 EXIT_FAST_REBOOT_DUMP_FAILURE=12 EXIT_FILTER_FDB_ENTRIES_FAILURE=13 EXIT_NO_CONTROL_PLANE_ASSISTANT=20 +EXIT_SONIC_INSTALLER_VERIFY_REBOOT=21 function error() { @@ -306,7 +307,12 @@ function reboot_pre_check() fi # Verify the next image by sonic_installer - sonic_installer verify-next-image + INSTALLER_VERIFY_RC=0 + sonic_installer verify-next-image > /dev/null || INSTALLER_VERIFY_RC=$? + if [[ INSTALLER_VERIFY_RC -ne 0 ]]; then + error "Failed to verify next image. Exit code: $INSTALLER_VERIFY_RC" + exit ${EXIT_SONIC_INSTALLER_VERIFY_REBOOT} + fi # Make sure ASIC configuration has not changed between images ASIC_CONFIG_CHECK_SCRIPT="/usr/bin/asic_config_check" From 3b94802b88bbe9734b3daad28448d8f20a9156b4 Mon Sep 17 00:00:00 2001 From: xumia Date: Mon, 13 Jul 2020 02:31:50 +0000 Subject: [PATCH 13/13] Improve the verification message --- sonic_installer/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_installer/main.py b/sonic_installer/main.py index d9847e95a2..ddd0bffdba 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -482,9 +482,9 @@ def verify_next_image(): """ Verify the next image for reboot""" bootloader = get_bootloader() if not bootloader.verify_next_image(): - click.echo('Failed') + click.echo('Image verification failed') sys.exit(1) - click.echo('Done') + click.echo('Image successfully verified') if __name__ == '__main__': cli()