Skip to content

Commit

Permalink
[sonic_installer] dont fail package migration (#1591)
Browse files Browse the repository at this point in the history
- What I did
Do not fail when user is doing downgrade. Fix #7518

- How I did it
Ignoring failures.

- How to verify it
On master image install 202012 image.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak authored May 6, 2021
1 parent 615e531 commit 9a88cb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sonic_installer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def run_command(command):
sys.exit(proc.returncode)

# Run bash command and return output, raise if it fails
def run_command_or_raise(argv):
def run_command_or_raise(argv, raise_exception=True):
click.echo(click.style("Command: ", fg='cyan') + click.style(' '.join(argv), fg='green'))

proc = subprocess.Popen(argv, text=True, stdout=subprocess.PIPE)
out, _ = proc.communicate()

if proc.returncode != 0:
if proc.returncode != 0 and raise_exception:
raise SonicRuntimeException("Failed to run command '{0}'".format(argv))

return out.rstrip("\n")
16 changes: 10 additions & 6 deletions sonic_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ def mount_squash_fs(squashfs_path, mount_point):
run_command_or_raise(["mount", "-t", "squashfs", squashfs_path, mount_point])


def umount(mount_point, read_only=True, recursive=False, force=True, remove_dir=True):
def umount(mount_point, read_only=True, recursive=False, force=True, remove_dir=True, raise_exception=True):
flags = []
if read_only:
flags.append("-r")
if force:
flags.append("-f")
if recursive:
flags.append("-R")
run_command_or_raise(["umount", *flags, mount_point])
run_command_or_raise(["umount", *flags, mount_point], raise_exception=raise_exception)
if remove_dir:
run_command_or_raise(["rm", "-rf", mount_point])
run_command_or_raise(["rm", "-rf", mount_point], raise_exception=raise_exception)


def mount_overlay_fs(lowerdir, upperdir, workdir, mount_point):
Expand Down Expand Up @@ -350,14 +350,18 @@ def get_path(path):
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("chroot {} {} stop".format(new_image_mount, DOCKER_CTL_SCRIPT))
umount(new_image_mount, recursive=True, read_only=False, remove_dir=False)
umount(new_image_mount)
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)


# Main entrypoint
Expand Down

0 comments on commit 9a88cb6

Please sign in to comment.