@@ -28,7 +28,7 @@ from shlex import quote
2828import xml .etree .ElementTree as ET
2929
3030# Constants
31- VERSION = "0.1.12 "
31+ VERSION = "0.1.13 "
3232ZYPPER_PID_FILE = "/run/zypp.pid"
3333VALID_CMD = ["dup" , "run" , "rollback" ]
3434VALID_OPT = ["--reboot" , "--apply" , "--shell" , "--continue" , "--no-verify" , \
@@ -146,14 +146,16 @@ def verify_snapshot():
146146 cleanup ()
147147 sys .exit ()
148148 logging .debug ("Getting failed systemd units" )
149- out , ret = shell_exec (f"LC_ALL=C machinectl --quiet shell { container_id } /usr/bin/bash -c 'systemctl --quiet --no-pager -o json --failed | cat - '" )
149+ out , ret = shell_exec (f"LC_ALL=C machinectl --quiet shell { container_id } /usr/bin/bash -c 'systemctl --quiet --no-pager -o json | cat'" )
150150 out = json .loads (out )
151- failed_units = [item ["unit" ] for item in out ]
152- logging .debug (f"Number of failed units = { len (failed_units )} " )
151+ all_units = [item ["unit" ] for item in out ]
152+ failed_units = [item ["unit" ] for item in out if item ["active" ] == "failed" ]
153+ logging .debug (f"Total number of units = { len (all_units )} ; Number of failed units = { len (failed_units )} " )
154+ logging .debug (f"All units = { ', ' .join (all_units )} " )
153155 logging .debug (f"Failed units = { ', ' .join (failed_units )} " )
154156 logging .debug ("Stopping container..." )
155157 shell_exec (f"machinectl stop { container_id } " )
156- return failed_units
158+ return all_units , failed_units
157159
158160# Function to cleanup on SIGINT or successful completion
159161def cleanup ():
@@ -401,7 +403,7 @@ chroot {TMP_MOUNT_DIR} mount -a -O no_netdev;
401403 # verify snapshot prior to performing update
402404 if not NO_VERIFY :
403405 logging .info ("Verifying snapshot prior to update..." )
404- pre_failed_units = verify_snapshot ()
406+ pre_all_units , pre_failed_units = verify_snapshot ()
405407 if COMMAND == "dup" :
406408 # check if dup has anything to do
407409 logging .info ("Checking for packages to upgrade..." )
@@ -459,11 +461,12 @@ chroot {TMP_MOUNT_DIR} bash -c "export PS1='atomic-update:\${{PWD}} # '; exec ba
459461 # verify snapshot after update
460462 if not NO_VERIFY :
461463 logging .info ("Verifying snapshot post update..." )
462- post_failed_units = verify_snapshot ()
463- new_failed_units = list ( set (post_failed_units ) - set (pre_failed_units ) )
464- if new_failed_units :
465- logging .error (f"Discarding snapshot { atomic_snap } as the following new " \
466- f"systemd units have failed since update: { ', ' .join (new_failed_units )} " )
464+ post_all_units , post_failed_units = verify_snapshot ()
465+ newly_failed_units = list ( set (post_failed_units ) - set (pre_failed_units ) )
466+ update_failed_units = [unit for unit in newly_failed_units if unit in pre_all_units ]
467+ if update_failed_units :
468+ logging .error (f"Discarding snapshot { atomic_snap } as the following " \
469+ f"systemd units have failed since update: { ', ' .join (update_failed_units )} " )
467470 shell_exec (f"snapper -c { snapper_root_config } delete { atomic_snap } " )
468471 cleanup ()
469472 sys .exit ()
0 commit comments