devicedisk: Raise proper error on invalid source_volume (bz 1445198)

https://bugzilla.redhat.com/show_bug.cgi?id=1445198
This commit is contained in:
Cole Robinson 2017-04-27 15:44:46 -04:00
parent cd0e3a897c
commit 7a4acfcd0c
2 changed files with 8 additions and 1 deletions

View File

@ -616,6 +616,7 @@ c.add_invalid("--disk /dev/default-pool/backingl3.img") # Colliding storage via
c.add_invalid("--disk %(DIR)s,device=cdrom") # Dir without floppy
c.add_invalid("--disk %(EXISTIMG1)s,driver_name=foobar,driver_type=foobaz") # Unknown driver name and type options (as of 1.0.0)
c.add_invalid("--disk source_pool=rbd-ceph,source_volume=vol1") # Collision with existing VM, via source pool/volume
c.add_invalid("--disk source_pool=default-pool,source_volume=idontexist") # trying to lookup non-existent volume, hit specific error code
c.add_invalid("--disk size=1 --security model=foo,type=bar") # Libvirt will error on the invalid security params, which should trigger the code path to clean up the disk images we created.

View File

@ -481,6 +481,7 @@ class VirtualDisk(VirtualDevice):
def __init__(self, *args, **kwargs):
VirtualDevice.__init__(self, *args, **kwargs)
self._source_volume_err = None
self._storage_backend = None
self.storage_was_created = False
@ -768,6 +769,7 @@ class VirtualDisk(VirtualDevice):
path = None
vol_object = None
parent_pool = None
self._source_volume_err = None
typ = self._get_default_type()
if self.type == VirtualDisk.TYPE_NETWORK:
@ -783,7 +785,8 @@ class VirtualDisk(VirtualDevice):
parent_pool = conn.storagePoolLookupByName(self.source_pool)
vol_object = parent_pool.storageVolLookupByName(
self.source_volume)
except:
except Exception, e:
self._source_volume_err = str(e)
logging.debug("Error fetching source pool=%s vol=%s",
self.source_pool, self.source_volume, exc_info=True)
@ -840,6 +843,9 @@ class VirtualDisk(VirtualDevice):
def validate(self):
if self.path is None:
if self._source_volume_err:
raise RuntimeError(self._source_volume_err)
if not self.can_be_empty():
raise ValueError(_("Device type '%s' requires a path") %
self.device)