summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-01-06 00:42:41 +0000
committerGerrit Code Review <review@openstack.org>2013-01-06 00:42:41 +0000
commitca91d3c607d82f57e736ef18be815023fd306342 (patch)
tree70682142d876569bc248a8aaf5b1f56f92cb74c5 /nova/virt
parent850e5d6bf989b15ca67396dc246e72f7de7524a8 (diff)
parent2ee83a493a91b6dd0ce79a8f6e74ac21638cff0a (diff)
Merge "improve libguestfs exception handling"
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/disk/vfs/guestfs.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/nova/virt/disk/vfs/guestfs.py b/nova/virt/disk/vfs/guestfs.py
index 66c6849d4..acea8afdf 100644
--- a/nova/virt/disk/vfs/guestfs.py
+++ b/nova/virt/disk/vfs/guestfs.py
@@ -101,6 +101,7 @@ class VFSGuestFS(vfs.VFS):
self.handle.aug_init("/", 0)
except RuntimeError, e:
+ # dereference object and implicitly close()
self.handle = None
raise exception.NovaException(
_("Error mounting %(imgfile)s with libguestfs (%(e)s)") %
@@ -111,19 +112,31 @@ class VFSGuestFS(vfs.VFS):
def teardown(self):
LOG.debug(_("Tearing down appliance"))
+
try:
- self.handle.aug_close()
- except Exception, e:
- LOG.debug(_("Failed to close augeas %s"), e)
- try:
- self.handle.shutdown()
- except Exception, e:
- LOG.debug(_("Failed to shutdown appliance %s"), e)
- try:
- self.handle.close()
- except Exception, e:
- LOG.debug(_("Failed to close guest handle %s"), e)
- self.handle = None
+ try:
+ self.handle.aug_close()
+ except RuntimeError, e:
+ LOG.warn(_("Failed to close augeas %s"), e)
+
+ try:
+ self.handle.shutdown()
+ except AttributeError:
+ # Older libguestfs versions haven't an explicit shutdown
+ pass
+ except RuntimeError, e:
+ LOG.warn(_("Failed to shutdown appliance %s"), e)
+
+ try:
+ self.handle.close()
+ except AttributeError:
+ # Older libguestfs versions haven't an explicit close
+ pass
+ except RuntimeError, e:
+ LOG.warn(_("Failed to close guest handle %s"), e)
+ finally:
+ # dereference object and implicitly close()
+ self.handle = None
@staticmethod
def _canonicalize_path(path):
@@ -157,7 +170,7 @@ class VFSGuestFS(vfs.VFS):
try:
self.handle.stat(path)
return True
- except Exception, e:
+ except RuntimeError:
return False
def set_permissions(self, path, mode):