From mboxrd@z Thu Jan 1 00:00:00 1970 From: 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> 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: In-Reply-To: <1276439625-32472-4-git-send-email-mgoldish@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org Currently get_pid() returns the pid of the parent shell process. Make it return the pid of the VM itself, and use vm.get_shell_pid() when the pid of the parent shell process is required. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_vm.py | 26 +++++++++++++++++++++----- client/tests/kvm/tests/timedrift.py | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) 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 -- 1.5.4.1