diff mbox series

[v11,7/8] qemu.py: launch vm only if it's not running

Message ID 20171114102246.22221-8-apahim@redhat.com
State New
Headers show
Series scripts/qemu.py fixes and cleanups | expand

Commit Message

Amador Pahim Nov. 14, 2017, 10:22 a.m. UTC
If we allow launching VM again we will loose track of the first launched
VM.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Amador Pahim <apahim@redhat.com>
---
 scripts/qemu.py | 3 +++
 1 file changed, 3 insertions(+)

Comments

Eduardo Habkost Jan. 19, 2018, 5:51 p.m. UTC | #1
On Tue, Nov 14, 2017 at 11:22:45AM +0100, Amador Pahim wrote:
> If we allow launching VM again we will loose track of the first launched
> VM.
> 
> Reviewed-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Amador Pahim <apahim@redhat.com>
> ---
>  scripts/qemu.py | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/scripts/qemu.py b/scripts/qemu.py
> index 305d7bd098..0b0b61be39 100644
> --- a/scripts/qemu.py
> +++ b/scripts/qemu.py
> @@ -207,6 +207,9 @@ class QEMUMachine(object):
>          Launch the VM and make sure we cleanup and expose the
>          command line/output in case of exception
>          """
> +        if self.is_running():
> +            raise QEMUMachineError('VM already running')

Patch 8/8 seems to make this redundant, as is_running() can't
return True if _launched is True.

I suggest replacing this and patch 8/8 with a single check:

        if self._launched:
            raise QEMUMachineError('VM already launched')
diff mbox series

Patch

diff --git a/scripts/qemu.py b/scripts/qemu.py
index 305d7bd098..0b0b61be39 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -207,6 +207,9 @@  class QEMUMachine(object):
         Launch the VM and make sure we cleanup and expose the
         command line/output in case of exception
         """
+        if self.is_running():
+            raise QEMUMachineError('VM already running')
+
         self._iolog = None
         self._qemu_full_args = None
         try: