import uuid
import avocado
-from avocado.utils import cloudinit, datadrainer, network, process, ssh, vmimage
+from avocado.utils import cloudinit, datadrainer, process, ssh, vmimage
from avocado.utils.path import find_command
#: The QEMU build root directory. It may also be the source directory
self.log.info('Preparing cloudinit image')
try:
cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso')
- self.phone_home_port = network.find_free_port()
- if not self.phone_home_port:
- self.cancel('Failed to get a free port')
pubkey_content = None
if ssh_pubkey:
with open(ssh_pubkey) as pubkey:
password=self.password,
# QEMU's hard coded usermode router address
phone_home_host='10.0.2.2',
- phone_home_port=self.phone_home_port,
+ phone_home_port=self.phone_server.server_port,
authorized_key=pubkey_content)
except Exception:
self.cancel('Failed to prepare the cloudinit image')
self.vm.add_args('-drive', 'file=%s' % path)
def set_up_cloudinit(self, ssh_pubkey=None):
+ self.phone_server = cloudinit.PhoneHomeServer(('0.0.0.0', 0),
+ self.name)
cloudinit_iso = self.prepare_cloudinit(ssh_pubkey)
self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso)
logger=self.log.getChild('console'))
console_drainer.start()
self.log.info('VM launched, waiting for boot confirmation from guest')
- cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), self.name)
+ while not self.phone_server.instance_phoned_back:
+ self.phone_server.handle_request()
+
if set_up_ssh_connection:
self.log.info('Setting up the SSH connection')
self.ssh_connect(self.username, self.ssh_key)