Fix generate check when arnied is absent
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 24 Jun 2025 08:48:57 +0000 (10:48 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 24 Jun 2025 10:43:24 +0000 (12:43 +0200)
src/arnied_wrapper.py

index cfbf0b2..2a7cef8 100644 (file)
@@ -403,12 +403,15 @@ def wait_for_generate(timeout: int = 300, vm=None) -> bool:
     cmd1 = f"{BIN_ARNIED_HELPER} --is-scheduled-or-running GENERATE"
     cmd2 = f"{BIN_ARNIED_HELPER} --is-scheduled-or-running GENERATE_OFFLINE"
     end_time = time.monotonic() + timeout - 0.5
-    while run_cmd(cmd=cmd1, ignore_errors=True, vm=vm).returncode == 0 \
-            or run_cmd(cmd=cmd2, ignore_errors=True, vm=vm).returncode == 0:
-        # one of them is scheduled or running, so check timeout and wait
-        if time.monotonic() > end_time:
-            log.warning("Timeout waiting for generate to start/finish")
-            return False
+
+    while time.monotonic() < end_time:
+        # from docu of arnied_helper:
+        # --is-scheduled-or-running PROGNAME      Exit code 0 if scheduled or running, 1 otherwise
+        if run_cmd(cmd=cmd1, ignore_errors=True, vm=vm).returncode == 1 \
+                and run_cmd(cmd=cmd2, ignore_errors=True, vm=vm).returncode == 1:
+            # both commands succeeded and indicate that neither program is running nor scheduled
+            return True
         log.debug("Waiting for generate to start/finish...")
         time.sleep(1)
-    return True
\ No newline at end of file
+    log.warning("Timeout waiting for generate to start/finish")
+    return False