diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index e38c1351e8b2edf2b9ef4a96e5706dc57e8fab41..8585bc2482fae685cff4d50ec38ffcc5cf560394 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -212,6 +212,7 @@ class OSBase(object): # This will host the error if mount fails self._mount_error = "" self._mount_warnings = [] + self._mounted = False # Many guestfs compilations don't support scrub self._scrub_support = True @@ -357,6 +358,10 @@ class OSBase(object): self.out.output() + @property + def ismounted(self): + return self._mounted + def mount(self, readonly=False, silent=False, fatal=True): """Returns a context manager for mounting an image""" @@ -374,17 +379,30 @@ class OSBase(object): parent._mount_error = "" del parent._mount_warnings[:] - if not parent._do_mount(readonly) and fatal: + try: + parent._mounted = parent._do_mount(readonly) + except: + parent.image.g.umount_all() + raise + + if not parent.ismounted: msg = "Unable to mount the media %s. Reason: %s" % \ (mount_type, parent._mount_error) - raise FatalError(msg) + if fatal: + raise FatalError(msg) + else: + warn(msg) + for warning in parent._mount_warnings: warn(warning) - success('done') + + if parent.ismounted: + success('done') def __exit__(self, exc_type, exc_value, traceback): output("Umounting the media ...", False) parent.image.g.umount_all() + parent._mounted = False success('done') return Mount() diff --git a/image_creator/os_type/windows/__init__.py b/image_creator/os_type/windows/__init__.py index 457ef0bca88f9cbb6e566efd2ccde3fd5dadd16e..91a340a54c845926ece6f39c8aa2dbafc3af2ae3 100644 --- a/image_creator/os_type/windows/__init__.py +++ b/image_creator/os_type/windows/__init__.py @@ -525,16 +525,21 @@ class Windows(OSBase): self.out.output("Reverting media boot preparations ...", False) with self.mount(readonly=False, silent=True, fatal=False): - if disabled_uac: - self.registry.update_uac_remote_setting(0) - if not self.sysprepped: - # Reset the old password - admin = self.sysprep_params['admin'].value - self.registry.reset_passwd(admin, v_val) + if not self.ismounted: + self.out.warn("The boot changes cannot be reverted. " + "The snapshot may be in a corrupted state.") + else: + if disabled_uac: + self.registry.update_uac_remote_setting(0) - self.registry.update_firewalls(*firewall_states) - self.out.success("done") + if not self.sysprepped: + # Reset the old password + admin = self.sysprep_params['admin'].value + self.registry.reset_passwd(admin, v_val) + + self.registry.update_firewalls(*firewall_states) + self.out.success("done") def _exec_sysprep_tasks(self): """This function hosts the actual code for executing the enabled