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 <mgoldish@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html