From patchwork Mon Sep 14 08:46:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 47258 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8E8o0jw022033 for ; Mon, 14 Sep 2009 08:50:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754908AbZINItz (ORCPT ); Mon, 14 Sep 2009 04:49:55 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754891AbZINIty (ORCPT ); Mon, 14 Sep 2009 04:49:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50732 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754828AbZINItx (ORCPT ); Mon, 14 Sep 2009 04:49:53 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8E8nu54019209; Mon, 14 Sep 2009 04:49:56 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8E8nt9G024309; Mon, 14 Sep 2009 04:49:56 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n8E8nocL018130; Mon, 14 Sep 2009 04:49:54 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 3/4] KVM test: kvm_vm.py: wrap VM.destroy() in a try-finally block Date: Mon, 14 Sep 2009 11:46:47 +0300 Message-Id: <1252918008-2742-3-git-send-email-mgoldish@redhat.com> In-Reply-To: <1252918008-2742-2-git-send-email-mgoldish@redhat.com> References: <1252918008-2742-1-git-send-email-mgoldish@redhat.com> <1252918008-2742-2-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This makes the function a little shorter or at least a little cleaner. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_vm.py | 84 ++++++++++++++++++++++---------------------- 1 files changed, 42 insertions(+), 42 deletions(-) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index f728104..89a31df 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -502,55 +502,55 @@ class VM: using a shell command before trying to end the qemu process with a 'quit' or a kill signal. """ - # Is it already dead? - if self.is_dead(): - logging.debug("VM is already down") - if self.process: - self.process.close() - return + try: + # Is it already dead? + if self.is_dead(): + logging.debug("VM is already down") + return - logging.debug("Destroying VM with PID %d..." % self.process.get_pid()) + logging.debug("Destroying VM with PID %d..." % + self.process.get_pid()) - if gracefully and self.params.get("shutdown_command"): - # Try to destroy with shell command - logging.debug("Trying to shutdown VM with shell command...") - session = self.remote_login() - if session: - try: - # Send the shutdown command - session.sendline(self.params.get("shutdown_command")) - logging.debug("Shutdown command sent; waiting for VM to go " - "down...") - if kvm_utils.wait_for(self.is_dead, 60, 1, 1): - logging.debug("VM is down") - self.process.close() - return - finally: - session.close() - - # Try to destroy with a monitor command - logging.debug("Trying to kill VM with monitor command...") - (status, output) = self.send_monitor_cmd("quit", block=False) - # Was the command sent successfully? - if status == 0: + if gracefully and self.params.get("shutdown_command"): + # Try to destroy with shell command + logging.debug("Trying to shutdown VM with shell command...") + session = self.remote_login() + if session: + try: + # Send the shutdown command + session.sendline(self.params.get("shutdown_command")) + logging.debug("Shutdown command sent; waiting for VM " + "to go down...") + if kvm_utils.wait_for(self.is_dead, 60, 1, 1): + logging.debug("VM is down") + return + finally: + session.close() + + # Try to destroy with a monitor command + logging.debug("Trying to kill VM with monitor command...") + status, output = self.send_monitor_cmd("quit", block=False) + # Was the command sent successfully? + if status == 0: + # Wait for the VM to be really dead + if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0.5): + logging.debug("VM is down") + return + + # If the VM isn't dead yet... + logging.debug("Cannot quit normally; sending a kill to close the " + "deal...") + kvm_utils.kill_process_tree(self.process.get_pid(), 9) # Wait for the VM to be really dead if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0.5): logging.debug("VM is down") - self.process.close() return - # If the VM isn't dead yet... - logging.debug("Cannot quit normally; sending a kill to close the " - "deal...") - kvm_utils.kill_process_tree(self.process.get_pid(), 9) - # Wait for the VM to be really dead - if kvm_utils.wait_for(self.is_dead, 5, 0.5, 0.5): - logging.debug("VM is down") - self.process.close() - return - - logging.error("Process %s is a zombie!" % self.process.get_pid()) - self.process.close() + logging.error("Process %s is a zombie!" % self.process.get_pid()) + + finally: + if self.process: + self.process.close() def is_alive(self):