QEMU VM guest-ping fix
[csit.git] / resources / libraries / python / QemuUtils.py
index 7f74106..282b157 100644 (file)
 
 """QEMU utilities library."""
 
+from time import time, sleep
 import json
 import re
-from time import time, sleep
+
 from robot.api import logger
+
 from resources.libraries.python.ssh import SSH
 from resources.libraries.python.constants import Constants
 from resources.libraries.python.topology import NodeType
@@ -122,7 +124,7 @@ class QemuUtils(object):
         """Set node to run QEMU on.
 
         :param node: Node to run QEMU on.
-        :param node: dict
+        :type node: dict
         """
         self._node = node
         self._ssh = SSH()
@@ -212,7 +214,7 @@ class QemuUtils(object):
         logger.trace(stdout)
         if not stdout:
             return {}
-        return json.loads(stdout)
+        return json.loads(stdout.split('\n', 1)[0])
 
     def _wait_until_vm_boot(self, timeout=300):
         """Wait until QEMU VM is booted.
@@ -234,6 +236,9 @@ class QemuUtils(object):
             # Non-error return - VM booted
             elif out.get('return') is not None:
                 break
+            # Skip error and wait
+            elif out.get('error') is not None:
+                sleep(5)
             else:
                 raise RuntimeError('QGA guest-ping unexpected output {}'.format(
                     out))
@@ -303,7 +308,7 @@ class QemuUtils(object):
     def qemu_start(self):
         """Start QEMU and wait until VM boot.
 
-        :return: VM node info
+        :return: VM node info.
         :rtype: dict
         .. note:: First set at least node to run QEMU on.
         .. warning:: Starts only one VM on the node.