Skip to content

Commit 9a88cb6

Browse files
[sonic_installer] dont fail package migration (sonic-net#1591)
- What I did Do not fail when user is doing downgrade. Fix sonic-net#7518 - How I did it Ignoring failures. - How to verify it On master image install 202012 image. Signed-off-by: Stepan Blyschak <[email protected]>
1 parent 615e531 commit 9a88cb6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

sonic_installer/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def run_command(command):
3131
sys.exit(proc.returncode)
3232

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

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

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

4343
return out.rstrip("\n")

sonic_installer/main.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ def mount_squash_fs(squashfs_path, mount_point):
232232
run_command_or_raise(["mount", "-t", "squashfs", squashfs_path, mount_point])
233233

234234

235-
def umount(mount_point, read_only=True, recursive=False, force=True, remove_dir=True):
235+
def umount(mount_point, read_only=True, recursive=False, force=True, remove_dir=True, raise_exception=True):
236236
flags = []
237237
if read_only:
238238
flags.append("-r")
239239
if force:
240240
flags.append("-f")
241241
if recursive:
242242
flags.append("-R")
243-
run_command_or_raise(["umount", *flags, mount_point])
243+
run_command_or_raise(["umount", *flags, mount_point], raise_exception=raise_exception)
244244
if remove_dir:
245-
run_command_or_raise(["rm", "-rf", mount_point])
245+
run_command_or_raise(["rm", "-rf", mount_point], raise_exception=raise_exception)
246246

247247

248248
def mount_overlay_fs(lowerdir, upperdir, workdir, mount_point):
@@ -350,14 +350,18 @@ def get_path(path):
350350
run_command_or_raise(["mount", "--bind",
351351
os.path.join(VAR_RUN_PATH, DOCKERD_SOCK),
352352
os.path.join(new_image_mount, "tmp", DOCKERD_SOCK)])
353+
run_command_or_raise(["chroot", new_image_mount, "sh", "-c", "command -v {}".format(SONIC_PACKAGE_MANAGER)])
354+
except SonicRuntimeException as err:
355+
echo_and_log("Warning: SONiC Application Extension is not supported in this image: {}".format(err), LOG_ERR, fg="red")
356+
else:
353357
run_command_or_raise(["chroot", new_image_mount, SONIC_PACKAGE_MANAGER, "migrate",
354358
os.path.join("/", tmp_dir, packages_file),
355359
"--dockerd-socket", os.path.join("/", tmp_dir, DOCKERD_SOCK),
356360
"-y"])
357361
finally:
358-
run_command("chroot {} {} stop".format(new_image_mount, DOCKER_CTL_SCRIPT))
359-
umount(new_image_mount, recursive=True, read_only=False, remove_dir=False)
360-
umount(new_image_mount)
362+
run_command_or_raise(["chroot", new_image_mount, DOCKER_CTL_SCRIPT, "stop"], raise_exception=False)
363+
umount(new_image_mount, recursive=True, read_only=False, remove_dir=False, raise_exception=False)
364+
umount(new_image_mount, raise_exception=False)
361365

362366

363367
# Main entrypoint

0 commit comments

Comments
 (0)