Received: from eggs.gnu.org ([2001:4830:134:3::10]:33097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f1fHW-0002pE-Nz for qemu-devel@nongnu.org; Thu, 29 Mar 2018 17:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f1fHV-0002AL-SO for qemu-devel@nongnu.org; Thu, 29 Mar 2018 17:40:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44366) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f1fHV-00029T-JT for qemu-devel@nongnu.org; Thu, 29 Mar 2018 17:40:25 -0400 From: Eduardo Habkost Date: Thu, 29 Mar 2018 18:38:52 -0300 Message-Id: <20180329213857.15499-14-ehabkost@redhat.com> In-Reply-To: <20180329213857.15499-1-ehabkost@redhat.com> References: <20180329213857.15499-1-ehabkost@redhat.com> Subject: [Qemu-devel] [RFC 13/18] qemu.py: 'force' parameter on shutdown() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Thomas Huth , Paolo Bonzini , Cleber Rosa , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Amador Pahim This will allow test code to shut down the VM without trying to run a 'quit' QMP command. Signed-off-by: Eduardo Habkost --- scripts/qemu.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index aaba04b3c1..045dca5d02 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -279,13 +279,24 @@ class QEMUMachine(object): self._popen.wait() self._post_shutdown() - def shutdown(self): - '''Terminate the VM and clean up''' - if self.is_running(): + def shutdown(self, force=None): + '''Terminate the VM and clean up + + @param force: If True, terminate QEMU process, if False always try + clean shutdown, if None terminate QEMU process if + clean shutdown fails. + ''' + if not force and self.is_running(): try: self._qmp.cmd('quit') except: - self._popen.kill() + if force is None: + force = True + else: + raise + + if force and self.is_running(): + self._popen.kill() self.wait() -- 2.14.3