From 0d53b7ac02b9e1c318cc6173574fc21d7a1190aa Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:19:04 +0300 Subject: [PATCH] [sonic_installer] don't print errors when installing an image not supporting app ext (#1719) FIXES: https://github.com/Azure/sonic-buildimage/issues/8149 #### What I did Don't print errors if installing app.ext incompatible image. #### How I did it Check for docker.sh existance and take an assumption that if it exists then it is app.ext compatible. #### How to verify it From master image install 202012 image and verify no errors in logs. --- sonic_installer/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sonic_installer/main.py b/sonic_installer/main.py index fde23dd5edb3..322aac8220e7 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -22,6 +22,7 @@ SYSLOG_IDENTIFIER = "sonic-installer" LOG_ERR = logger.Logger.LOG_PRIORITY_ERROR +LOG_WARN = logger.Logger.LOG_PRIORITY_WARNING LOG_NOTICE = logger.Logger.LOG_PRIORITY_NOTICE # Global Config object @@ -332,6 +333,7 @@ def migrate_sonic_packages(bootloader, binary_image_version): echo_and_log("Error: SONiC package migration cannot proceed due to missing docker folder", LOG_ERR, fg="red") return + docker_started = False with bootloader.get_rootfs_path(new_image_dir) as new_image_squashfs_path: try: mount_squash_fs(new_image_squashfs_path, new_image_mount) @@ -342,22 +344,25 @@ def migrate_sonic_packages(bootloader, binary_image_version): mount_bind(new_image_docker_dir, new_image_docker_mount) mount_procfs_chroot(new_image_mount) mount_sysfs_chroot(new_image_mount) + # Assume if docker.sh script exists we are installing Application Extension compatible image. + if not os.path.exists(os.path.join(new_image_mount, os.path.relpath(DOCKER_CTL_SCRIPT, os.path.abspath(os.sep)))): + echo_and_log("Warning: SONiC Application Extension is not supported in this image", LOG_WARN, fg="yellow") + return run_command_or_raise(["chroot", new_image_mount, DOCKER_CTL_SCRIPT, "start"]) + docker_started = True run_command_or_raise(["cp", packages_path, os.path.join(new_image_mount, tmp_dir, packages_file)]) run_command_or_raise(["touch", os.path.join(new_image_mount, "tmp", DOCKERD_SOCK)]) run_command_or_raise(["mount", "--bind", os.path.join(VAR_RUN_PATH, DOCKERD_SOCK), os.path.join(new_image_mount, "tmp", DOCKERD_SOCK)]) run_command_or_raise(["chroot", new_image_mount, "sh", "-c", "command -v {}".format(SONIC_PACKAGE_MANAGER)]) - except SonicRuntimeException as err: - echo_and_log("Warning: SONiC Application Extension is not supported in this image: {}".format(err), LOG_ERR, fg="red") - else: run_command_or_raise(["chroot", new_image_mount, SONIC_PACKAGE_MANAGER, "migrate", os.path.join("/", tmp_dir, packages_file), "--dockerd-socket", os.path.join("/", tmp_dir, DOCKERD_SOCK), "-y"]) finally: - run_command_or_raise(["chroot", new_image_mount, DOCKER_CTL_SCRIPT, "stop"], raise_exception=False) + if docker_started: + run_command_or_raise(["chroot", new_image_mount, DOCKER_CTL_SCRIPT, "stop"], raise_exception=False) umount(new_image_mount, recursive=True, read_only=False, remove_dir=False, raise_exception=False) umount(new_image_mount, raise_exception=False)