@@ -28,7 +28,7 @@ from shlex import quote
2828import xml .etree .ElementTree as ET
2929
3030# Constants
31- VERSION = "0.1.5 "
31+ VERSION = "0.1.6 "
3232ZYPPER_PID_FILE = "/run/zypp.pid"
3333VALID_CMD = ["dup" , "run" , "rollback" ]
3434VALID_OPT = ["--reboot" , "--apply" , "--shell" , "--continue" , "--no-verify" , \
@@ -100,8 +100,9 @@ def get_atomic_snap(snapper_root_config, status):
100100# Function to verify snapshot by booting it up as a container
101101def verify_snapshot ():
102102 logging .debug ("Booting container" )
103- cmd = ["systemd-nspawn" , "--directory" , TMP_MOUNT_DIR , "--ephemeral" , "--boot" ]
104- subprocess .Popen (cmd , stdout = subprocess .DEVNULL , stderr = subprocess .STDOUT )
103+ cmd = ["systemd-nspawn" , "--directory" , TMP_MOUNT_DIR , "--ephemeral" , "--boot" , \
104+ "systemd.mask=local-fs.target" , "systemd.mask=auditd.service" , "systemd.mask=kdump.service" ]
105+ proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
105106 logging .debug ("Getting container id" )
106107 container_id = None
107108 for _ in range (10 ):
@@ -131,19 +132,22 @@ def verify_snapshot():
131132 break
132133 time .sleep (1 )
133134 if not startup_finished :
134- logging .warn ("Timeout waiting for bootup of ephemeral container from snapshot" )
135- logging . debug ( f"systemd-analyze time output: \n { out } " )
136- out , ret = shell_exec (f"LC_ALL=C machinectl --quiet shell { container_id } /usr/bin/bash -c 'systemctl --quiet --no-pager list-jobs' " )
137- logging . debug ( f"systemctl list-jobs output: \n { out } " )
138- logging . debug ( "Getting failed systemd units" )
139- 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 -' " )
140- try :
141- out = json . loads ( out )
142- except json . JSONDecodeError :
143- logging . error ( "Could not decode JSON output of failed systemd units. Cancelling task..." )
144- logging .debug (f"systemctl --failed output:\n { out } " )
135+ logging .error ("Timeout waiting for bootup of ephemeral container from snapshot. Cancelling task... " )
136+ # stop container and get the process output for debugging
137+ shell_exec (f"machinectl stop { container_id } " )
138+ # wait for container to stop
139+ while True :
140+ out , ret = shell_exec (f"LC_ALL=C machinectl --quiet show { container_id } " )
141+ if ret != 0 :
142+ break
143+ time . sleep ( 1 )
144+ out , err = proc . communicate ( )
145+ logging .debug (f"Container console output:\n { out . decode () } " )
145146 cleanup ()
146147 sys .exit ()
148+ 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 -'" )
150+ out = json .loads (out )
147151 failed_units = [item ["unit" ] for item in out ]
148152 logging .debug (f"Number of failed units = { len (failed_units )} " )
149153 logging .debug (f"Failed units = { ', ' .join (failed_units )} " )
@@ -353,7 +357,7 @@ if COMMAND in ["dup", "run"]:
353357 # warn user when rebasing from old snapshot
354358 # thus losing changes to snapshots made in the interim
355359 if not continue_num and base_snap != default_snap :
356- logging .warn (f"This snapshot is being created from a different base ({ base_snap } ) " \
360+ logging .warning (f"This snapshot is being created from a different base ({ base_snap } ) " \
357361 f"than the previous default snapshot ({ default_snap } ) and does not " \
358362 f"contain the changes from the latter." )
359363 # create new read-write snapshot to perform atomic update in
@@ -516,7 +520,7 @@ elif COMMAND == "rollback":
516520 invalid_opts = OPT .copy ()
517521 invalid_opts .remove ("--debug" ) if "--debug" in OPT else None
518522 if invalid_opts :
519- logging .warn (f"Options { ', ' .join (invalid_opts )!r} do not apply to rollback command" )
523+ logging .warning (f"Options { ', ' .join (invalid_opts )!r} do not apply to rollback command" )
520524 if rollback_num :
521525 logging .info (f"Rolling back to snapshot { rollback_num } " )
522526 os .system (f"snapper rollback -c number { rollback_num } " )
0 commit comments