From patchwork Sun Jun 13 14:33:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 105813 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5DEYRr5026976 for ; Sun, 13 Jun 2010 14:34:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753888Ab0FMOeU (ORCPT ); Sun, 13 Jun 2010 10:34:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14677 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753860Ab0FMOeO (ORCPT ); Sun, 13 Jun 2010 10:34:14 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5DEYDUQ017375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 13 Jun 2010 10:34:13 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5DEYD8d014917; Sun, 13 Jun 2010 10:34:13 -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 o5DEY6v0030030; Sun, 13 Jun 2010 10:34:12 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 05/14] KVM test: kvm_vm.py: make get_pid() return the pid of the VM itself Date: Sun, 13 Jun 2010 17:33:36 +0300 Message-Id: <1276439625-32472-5-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276439625-32472-4-git-send-email-mgoldish@redhat.com> References: <1276439625-32472-1-git-send-email-mgoldish@redhat.com> <1276439625-32472-2-git-send-email-mgoldish@redhat.com> <1276439625-32472-3-git-send-email-mgoldish@redhat.com> <1276439625-32472-4-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 13 Jun 2010 14:34:31 +0000 (UTC) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 67a13d7..9d3539f 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -594,8 +594,7 @@ class VM: self.destroy() return False - logging.debug("VM appears to be alive with PID %d", - self.process.get_pid()) + logging.debug("VM appears to be alive with PID %s", self.get_pid()) return True finally: @@ -704,8 +703,7 @@ class VM: logging.debug("VM is already down") return - logging.debug("Destroying VM with PID %d..." % - self.process.get_pid()) + logging.debug("Destroying VM with PID %s...", self.get_pid()) if gracefully and self.params.get("shutdown_command"): # Try to destroy with shell command @@ -853,7 +851,25 @@ class VM: def get_pid(self): """ - Return the VM's PID. + Return the VM's PID. If the VM is dead return None. + + @note: This works under the assumption that self.process.get_pid() + returns the PID of the parent shell process. + """ + try: + children = commands.getoutput("ps --ppid=%d -o pid=" % + self.process.get_pid()).split() + return int(children[0]) + except (TypeError, IndexError, ValueError): + return None + + + def get_shell_pid(self): + """ + Return the PID of the parent shell process. + + @note: This works under the assumption that self.process.get_pid() + returns the PID of the parent shell process. """ return self.process.get_pid() diff --git a/client/tests/kvm/tests/timedrift.py b/client/tests/kvm/tests/timedrift.py index 9cb7489..bb23830 100644 --- a/client/tests/kvm/tests/timedrift.py +++ b/client/tests/kvm/tests/timedrift.py @@ -80,7 +80,7 @@ def run_timedrift(test, params, env): try: # Set the VM's CPU affinity - prev_affinity = set_cpu_affinity(vm.get_pid(), cpu_mask) + prev_affinity = set_cpu_affinity(vm.get_shell_pid(), cpu_mask) try: # Open shell sessions with the guest