This is just an refactor to separate the exception handler from the actual launch procedure, improving the readability and making future maintenances in this piece of code easier.
Signed-off-by: Amador Pahim <apa...@redhat.com> --- scripts/qemu.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 2bd81afcf2..7f890ff8e5 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -167,10 +167,10 @@ class QEMUMachine(object): self._remove_if_exists(self._created_files.pop()) def launch(self): - '''Launch the VM and establish a QMP connection''' - self._iolog = None - self._qemu_full_args = None - devnull = open(os.path.devnull, 'rb') + ''' + Try to launch the VM and make sure we cleanup and expose the + command line/output in case of exception. + ''' if self.is_running(): raise QEMULaunchError('VM already running') @@ -178,15 +178,7 @@ class QEMUMachine(object): raise QEMULaunchError('Shutdown pending after previous launch') 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_fd, - stderr=subprocess.STDOUT, - shell=False) - self._post_launch() + self._launch() self._pending_shutdown = True except: self.shutdown() @@ -199,6 +191,21 @@ class QEMUMachine(object): raise + def _launch(self): + '''Launch the VM and establish a QMP connection''' + self._iolog = None + self._qemu_full_args = None + 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_fd, + stderr=subprocess.STDOUT, + shell=False) + self._post_launch() + def shutdown(self): '''Terminate the VM and clean up''' if self.is_running(): -- 2.13.5