From 2e90cfb8c3ba65c87c1a544a4e0c7cd92d5dd17a Mon Sep 17 00:00:00 2001
From: Nikos Skalkotos <skalkoto@grnet.gr>
Date: Mon, 26 May 2014 10:47:17 +0300
Subject: [PATCH] Add an attribute in OSBase to host mount errors
Add the _mount_error attribute in OSBase. If mount fails, the error
message is written there.
---
image_creator/os_type/__init__.py | 10 ++++++++--
image_creator/os_type/freebsd.py | 2 +-
image_creator/os_type/unix.py | 2 +-
image_creator/os_type/unsupported.py | 2 +-
image_creator/os_type/windows/__init__.py | 6 +++++-
5 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py
index 524ca32..ba1f6e3 100644
--- a/image_creator/os_type/__init__.py
+++ b/image_creator/os_type/__init__.py
@@ -199,6 +199,9 @@ class OSBase(object):
self.meta = {}
self.mounted = False
+ # This will host the error if mount fails
+ self._mount_error = ""
+
# Many guestfs compilations don't support scrub
self._scrub_support = True
try:
@@ -340,7 +343,9 @@ class OSBase(object):
try:
if not self.mount(readonly=False):
- raise FatalError("Unable to mount the media read-write")
+ msg = "Unable to mount the media read-write. Reason: %s" % \
+ self._mount_error
+ raise FatalError(msg)
enabled = [task for task in self.list_syspreps() if task.enabled]
@@ -365,6 +370,7 @@ class OSBase(object):
mount_type = 'read-only' if readonly else 'read-write'
self.out.output("Mounting the media %s ..." % mount_type, False)
+ self._mount_error = ""
if not self._do_mount(readonly):
return False
@@ -466,7 +472,7 @@ class OSBase(object):
self.image.g.mount_options(
'ro' if readonly else 'rw', self.root, '/')
except RuntimeError as msg:
- self.out.warn("unable to mount the root partition: %s" % msg)
+ self._mount_error = str(msg)
return False
return True
diff --git a/image_creator/os_type/freebsd.py b/image_creator/os_type/freebsd.py
index ce875dd..dce0458 100644
--- a/image_creator/os_type/freebsd.py
+++ b/image_creator/os_type/freebsd.py
@@ -118,7 +118,7 @@ class Freebsd(Unix):
self.image.g.mount_vfs(mopts, 'ufs', dev, mp)
except RuntimeError as msg:
if mp in critical_mpoints:
- self.out.warn('unable to mount %s. Reason: %s' % (mp, msg))
+ self._mount_error = str(msg)
return False
else:
self.out.warn('%s (ignored)' % msg)
diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py
index ce90964..00ede28 100644
--- a/image_creator/os_type/unix.py
+++ b/image_creator/os_type/unix.py
@@ -63,7 +63,7 @@ class Unix(OSBase):
self.image.g.mount_options(mopts, dev, mp)
except RuntimeError as msg:
if mp in critical_mpoints:
- self.out.warn('unable to mount %s. Reason: %s' % (mp, msg))
+ self._mount_error = str(msg)
return False
else:
self.out.warn('%s (ignored)' % msg)
diff --git a/image_creator/os_type/unsupported.py b/image_creator/os_type/unsupported.py
index 918f094..93b711f 100644
--- a/image_creator/os_type/unsupported.py
+++ b/image_creator/os_type/unsupported.py
@@ -31,7 +31,7 @@ class Unsupported(OSBase):
def _do_mount(self, readonly):
"""Mount partitions in correct order"""
- self.out.warn('not supported on this media.')
+ self._mount_error = "not supported on this media"
return False
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
diff --git a/image_creator/os_type/windows/__init__.py b/image_creator/os_type/windows/__init__.py
index 69c898a..66acd5c 100644
--- a/image_creator/os_type/windows/__init__.py
+++ b/image_creator/os_type/windows/__init__.py
@@ -315,8 +315,12 @@ class Windows(OSBase):
timeout = self.sysprep_params['boot_timeout'].value
shutdown_timeout = self.sysprep_params['shutdown_timeout'].value
- self.mount(readonly=False)
try:
+ if not self.mount(readonly=False):
+ msg = "Unable to mount the media read-write. Reason: %s" % \
+ self._mount_error
+ raise FatalError(msg)
+
virtio_state = self._virtio_state()
if len(virtio_state['viostor']) == 0:
raise FatalError(
--
GitLab