This is a fix for issue #473.

The current implementation of get_pid() in libvirt_vm is
reminiscent of the kvm_vm implementation, where self.process
is an expect object. In libvirt_vm, process is a PID (int),
therefore the same rules can't be applied. Re-create the
implementation in a cleaner way.

Signed-off-by: Lucas Meneghel Rodrigues <l...@redhat.com>
---
 client/virt/libvirt_vm.py |   29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/client/virt/libvirt_vm.py b/client/virt/libvirt_vm.py
index b0e029d..4e27482 100644
--- a/client/virt/libvirt_vm.py
+++ b/client/virt/libvirt_vm.py
@@ -1513,21 +1513,28 @@ class VM(virt_vm.BaseVM):
             count += 1
         raise virt_vm.VMMACAddressMissingError(nic_index)
 
+
     def get_pid(self):
         """
-        Return the VM's PID.  If the VM is dead return None.
+        Return the VM's PID.
 
-        @note: This works under the assumption that self.process.get_pid()
-        returns the PID of the parent shell process.
+        @return: int with PID. If VM is not alive, returns None.
         """
-        try:
-            filename = "/var/run/libvirt/qemu/%s.pid" % self.name
-            if not self.params.get("type") == "unattended_install":
-                if os.path.exists(filename):
-                    vm_pid = int(open(filename).read())
-            return vm_pid
-        except (TypeError, IndexError, ValueError):
-            return None
+        pid_file = "/var/run/libvirt/qemu/%s.pid" % self.name
+        pid = None
+        if os.path.exists(pid_file):
+            try:
+                pid_file_contents = open(pid_file).read()
+                pid = int(pid_file_contents)
+            except IOError:
+                logging.error("Could not read %s to get PID", pid_file)
+            except TypeError:
+                logging.error("PID file %s has invalid contents: '%s'",
+                              pid_file, pid_file_contents)
+        else:
+            logging.debug("PID file %s not present", pid_file)
+
+        return pid
 
 
     def get_shell_pid(self):
-- 
1.7.10.4

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to