[elbe-devel] [PATCH v2] initvmaction: Fix initvm command stop

Olivier Dion dion at linutronix.de
Tue Aug 4 17:22:00 CEST 2020


This should fix problems that some users had with elbe-initvm-stop.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/initvmaction.py | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index a0b76e15..348c82b3 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -195,25 +195,31 @@ class StopAction(InitVMAction):
         InitVMAction.__init__(self, node)
 
     def execute(self, _initvmdir, _opt, _args):
+
         if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
             print('Initvm is not running.')
             sys.exit(20)
-        else:
-            while True:
-                try:
-                    self.initvm.shutdown()
-                except libvirt.libvirtError as e:
-                    # ignore that initvm is already shutoff or is currently
-                    # shutting down but raise all other errors
-                    if (self.initvm_state() != libvirt.VIR_DOMAIN_SHUTOFF and
-                        self.initvm_state() != libvirt.VIR_DOMAIN_SHUTDOWN):
-                        raise e
-                sys.stdout.write("*")
-                sys.stdout.flush()
-                if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
-                    print("\nInitvm shut off.")
-                    break
-                time.sleep(1)
+
+        while True:
+
+            sys.stdout.write("*")
+            sys.stdout.flush()
+            time.sleep(1)
+
+            state = self.initvm_state()
+
+            if state == libvirt.VIR_DOMAIN_SHUTDOWN:
+                continue
+
+            if state == libvirt.VIR_DOMAIN_SHUTOFF:
+                break
+
+            try:
+                self.initvm.shutdown()
+            except libvirt.libvirtError as e:
+                raise e
+
+        print("\nInitvm shutoff")
 
 
 @InitVMAction.register('attach')
-- 
2.28.0



More information about the elbe-devel mailing list