Skip to content
Snippets Groups Projects
Commit 4445d421 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

windows: Fix a bug in the VirtIO installation code

Make sure the guestfs VM is killed before we launch the VM that
installs the VirtIO drivers.
parent 7dfcf976
No related branches found
No related tags found
No related merge requests found
...@@ -721,6 +721,7 @@ class Windows(OSBase): ...@@ -721,6 +721,7 @@ class Windows(OSBase):
self.out.output("failed! See: `%s' for the full output" % log.name) self.out.output("failed! See: `%s' for the full output" % log.name)
if i < retries - 1: if i < retries - 1:
self.out.output("retrying ...", False) self.out.output("retrying ...", False)
time.sleep(1)
raise FatalError("Connection to the Windows VM failed after %d retries" raise FatalError("Connection to the Windows VM failed after %d retries"
% retries) % retries)
...@@ -866,8 +867,17 @@ class Windows(OSBase): ...@@ -866,8 +867,17 @@ class Windows(OSBase):
tmp = uuid.uuid4().hex tmp = uuid.uuid4().hex
self.image.g.mkdir_p("%s/%s" % (self.systemroot, tmp)) self.image.g.mkdir_p("%s/%s" % (self.systemroot, tmp))
self._add_cleanup('virtio', self.image.g.rm_rf,
"%s/%s" % (self.systemroot, tmp)) # This is a hack. We create a function here and pass it to
# _add_cleanup because self.image.g may change and the _add_cleanup
# will cache it which is wrong. For older versions of the guestfs
# library we recreate the g handler in enable_guestfs() and the
# program will crash if cleanup retains an older value for the
# guestfs handler.
def remove_tmp():
self.image.g.rm_rf("%s/%s" % (self.systemroot, tmp))
self._add_cleanup('virtio', remove_tmp)
for fname in os.listdir(dirname): for fname in os.listdir(dirname):
full_path = os.path.join(dirname, fname) full_path = os.path.join(dirname, fname)
...@@ -929,38 +939,43 @@ class Windows(OSBase): ...@@ -929,38 +939,43 @@ class Windows(OSBase):
def _boot_virtio_vm(self): def _boot_virtio_vm(self):
"""Boot the media and install the VirtIO drivers""" """Boot the media and install the VirtIO drivers"""
timeout = self.sysprep_params['boot_timeout'].value old_windows = self.check_version(6, 1) <= 0
shutdown_timeout = self.sysprep_params['shutdown_timeout'].value self.image.disable_guestfs()
virtio_timeout = self.sysprep_params['virtio_timeout'].value
self.out.output("Starting Windows VM ...", False)
booted = False
try: try:
if self.check_version(6, 1) <= 0: timeout = self.sysprep_params['boot_timeout'].value
self.vm.start() shutdown_timeout = self.sysprep_params['shutdown_timeout'].value
else: virtio_timeout = self.sysprep_params['virtio_timeout'].value
self.vm.interface = 'ide' self.out.output("Starting Windows VM ...", False)
self.vm.start(extra_disk=('/dev/null', 'virtio')) booted = False
self.vm.interface = 'virtio' try:
if old_windows:
self.out.success("started (console on VNC display: %d)" % self.vm.start()
self.vm.display) else:
self.out.output("Waiting for Windows to boot ...", False) self.vm.interface = 'ide'
if not self.vm.wait_on_serial(timeout): self.vm.start(extra_disk=('/dev/null', 'virtio'))
raise FatalError("Windows VM booting timed out!") self.vm.interface = 'virtio'
self.out.success('done')
booted = True self.out.success("started (console on VNC display: %d)" %
self.out.output("Installing new drivers ...", False) self.vm.display)
if not self.vm.wait_on_serial(virtio_timeout): self.out.output("Waiting for Windows to boot ...", False)
raise FatalError("Windows VirtIO installation timed out!") if not self.vm.wait_on_serial(timeout):
self.out.success('done') raise FatalError("Windows VM booting timed out!")
self.out.output('Shutting down ...', False) self.out.success('done')
(_, stderr, rc) = self.vm.wait(shutdown_timeout) booted = True
if rc != 0 or "terminating on signal" in stderr: self.out.output("Installing new drivers ...", False)
raise FatalError("Windows VM died unexpectedly!\n\n" if not self.vm.wait_on_serial(virtio_timeout):
"(rc=%d)\n%s" % (rc, stderr)) raise FatalError("Windows VirtIO installation timed out!")
self.out.success('done') self.out.success('done')
self.out.output('Shutting down ...', False)
(_, stderr, rc) = self.vm.wait(shutdown_timeout)
if rc != 0 or "terminating on signal" in stderr:
raise FatalError("Windows VM died unexpectedly!\n\n"
"(rc=%d)\n%s" % (rc, stderr))
self.out.success('done')
finally:
self.vm.stop(shutdown_timeout if booted else 1, fatal=False)
finally: finally:
self.vm.stop(shutdown_timeout if booted else 1, fatal=False) self.image.enable_guestfs()
with self.mount(readonly=True, silent=True): with self.mount(readonly=True, silent=True):
self.virtio_state = self.compute_virtio_state() self.virtio_state = self.compute_virtio_state()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment