X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FQemuUtils.py;h=d105dae89a756e34db7fdf722c7ed9071f4914a6;hp=7f741061773d5d27126aa2d82d8a7e5c5dcd2dda;hb=76798663ee3e71defd75bdf0d1e32d8242e38e33;hpb=43277be7e77afe0363f62c97c687bcfa506ee4b8 diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py index 7f74106177..d105dae89a 100644 --- a/resources/libraries/python/QemuUtils.py +++ b/resources/libraries/python/QemuUtils.py @@ -13,10 +13,12 @@ """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() @@ -194,6 +196,21 @@ class QemuUtils(object): self._node['host'])) return json.loads(out_list[2]) + def _qemu_qga_flush(self): + """Flush the QGA parser state + """ + qga_cmd = 'printf "\xFF" | sudo -S nc ' \ + '-q 1 -U ' + self.__QGA_SOCK + (ret_code, stdout, stderr) = self._ssh.exec_command(qga_cmd) + if 0 != int(ret_code): + logger.debug('QGA execute failed {0}'.format(stderr)) + raise RuntimeError('QGA execute "{0}" failed on {1}'.format(cmd, + self._node['host'])) + logger.trace(stdout) + if not stdout: + return {} + return json.loads(stdout.split('\n', 1)[0]) + def _qemu_qga_exec(self, cmd): """Execute QGA command. @@ -212,7 +229,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. @@ -227,6 +244,7 @@ class QemuUtils(object): if time() - start > timeout: raise RuntimeError('timeout, VM {0} not booted on {1}'.format( self._qemu_opt['disk_image'], self._node['host'])) + self._qemu_qga_flush() out = self._qemu_qga_exec('guest-ping') # Empty output - VM not booted yet if not out: @@ -234,6 +252,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 +324,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.