[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/21] qemu.py: refactor launch()
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 13/21] qemu.py: refactor launch() |
Date: |
Mon, 5 Feb 2018 21:08:52 -0200 |
From: Amador Pahim <address@hidden>
This is just a refactor to separate the exception handler from the
actual launch procedure, improving the readability and making future
maintenances in this piece of code easier.
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Eduardo Habkost <address@hidden>
Signed-off-by: Amador Pahim <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
scripts/qemu.py | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index 8d539206c4..0333d1e7fa 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -205,20 +205,14 @@ class QEMUMachine(object):
self._temp_dir = None
def launch(self):
- '''Launch the VM and establish a QMP connection'''
+ """
+ Launch the VM and make sure we cleanup and expose the
+ command line/output in case of exception
+ """
self._iolog = None
self._qemu_full_args = None
- devnull = open(os.path.devnull, 'rb')
try:
- self._pre_launch()
- self._qemu_full_args = (self._wrapper + [self._binary] +
- self._base_args() + self._args)
- self._popen = subprocess.Popen(self._qemu_full_args,
- stdin=devnull,
- stdout=self._qemu_log_file,
- stderr=subprocess.STDOUT,
- shell=False)
- self._post_launch()
+ self._launch()
except:
if self.is_running():
self._popen.kill()
@@ -233,6 +227,19 @@ class QEMUMachine(object):
LOG.debug('Output: %r', self._iolog)
raise
+ def _launch(self):
+ '''Launch the VM and establish a QMP connection'''
+ devnull = open(os.path.devnull, 'rb')
+ self._pre_launch()
+ self._qemu_full_args = (self._wrapper + [self._binary] +
+ self._base_args() + self._args)
+ self._popen = subprocess.Popen(self._qemu_full_args,
+ stdin=devnull,
+ stdout=self._qemu_log_file,
+ stderr=subprocess.STDOUT,
+ shell=False)
+ self._post_launch()
+
def wait(self):
'''Wait for the VM to power off'''
self._popen.wait()
--
2.14.3
- [Qemu-devel] [PULL 04/21] qapi: adapt to moved location of StringIO module in py3, (continued)
- [Qemu-devel] [PULL 04/21] qapi: adapt to moved location of StringIO module in py3, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 06/21] qapi: remove '-q' arg to diff when comparing QAPI output, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 07/21] qapi: ensure stable sort ordering when checking QAPI entities, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 05/21] qapi: Adapt to moved location of 'maketrans' function in py3, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 08/21] qapi: force a UTF-8 locale for running Python, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 09/21] scripts: ensure signrom treats data as bytes, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 10/21] configure: allow use of python 3, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 11/21] qemu.py: remove unused import, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 12/21] qemu.py: better control of created files, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 14/21] qemu.py: always cleanup on shutdown(), Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 13/21] qemu.py: refactor launch(),
Eduardo Habkost <=
- [Qemu-devel] [PULL 15/21] qemu.py: use poll() instead of 'returncode', Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 16/21] qemu.py: cleanup redundant calls in launch(), Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 17/21] qemu.py: don't launch again before shutdown(), Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 18/21] input: add missing JIS keys to virtio input, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 19/21] ui: update keycodemapdb to get py3 fixes, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 20/21] travis: improve python version test coverage, Eduardo Habkost, 2018/02/05
- [Qemu-devel] [PULL 21/21] docker: change Fedora images to run with python3, Eduardo Habkost, 2018/02/05
- Re: [Qemu-devel] [PULL 00/21] Python queue, 2018-02-05, Peter Maydell, 2018/02/07