OSDN Git Service

python/machine: Handle termination cases without QMP
authorJohn Snow <jsnow@redhat.com>
Thu, 27 Oct 2022 18:58:36 +0000 (14:58 -0400)
committerJohn Snow <jsnow@redhat.com>
Wed, 4 Jan 2023 18:46:05 +0000 (13:46 -0500)
If we request a shutdown of a VM without a QMP console, we'll just hang
waiting. Not ideal.

Add in code that attempts graceful termination in these cases.  Tested
lightly; it appears to work and I doubt we rely on this case anywhere,
but it's a corner you're allowed to wedge yourself in, so it should be
handled.

Signed-off-by: John Snow <jsnow@redhat.com>
python/qemu/machine/machine.py

index 6f1374a..748a0d8 100644 (file)
@@ -547,6 +547,12 @@ class QEMUMachine:
             finally:
                 # Regardless, we want to quiesce the connection.
                 self._close_qmp_connection()
+        elif not self._quit_issued:
+            LOG.debug(
+                "Not anticipating QEMU quit and no QMP connection present, "
+                "issuing SIGTERM"
+            )
+            self._subp.terminate()
 
         # May raise subprocess.TimeoutExpired
         LOG.debug(