[elbe-devel] [PATCH] initvm stop: execute libvirt stop more than once

Manuel Traut manut at linutronix.de
Wed Aug 1 12:53:37 CEST 2018


If initvm is just booting, the stop command is ignored.
Therefore issue the command in the while loop.
Hitting the poweroff button more than once shouldn't be evil.
However an exception is raised by libvirt if the target is already
shutdown. This can be safely ignored.

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/initvmaction.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index a55a211f..73eda552 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -176,9 +176,14 @@ class StopAction(InitVMAction):
             print('Initvm is not running.')
             sys.exit(20)
         else:
-            # Shutdown initvm
-            self.initvm.shutdown()
             while(True):
+                try:
+                    self.initvm.shutdown()
+                except libvirt.libvirtError as e:
+                    # ignore that initvm is already shutdown but raise all
+                    # other errors
+                    if self.initvm_state() != 5:
+                        raise e
                 sys.stdout.write("*")
                 sys.stdout.flush()
                 if self.initvm_state() == 5:
-- 
2.18.0




More information about the elbe-devel mailing list