Blob Blame History Raw
From 6ee28a662c511063cd5edc32b6a613aa84cff3b9 Mon Sep 17 00:00:00 2001
From: Pavel Hrdina <phrdina@redhat.com>
Date: Thu, 27 Apr 2017 15:44:46 -0400
Subject: devicedisk: Raise proper error on invalid source_volume (bz 1445198)

From: Cole Robinson <crobinso@redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=1445198
(cherry picked from commit 7a4acfcd0cd9fa300fbbc0551cd5c20000b8d583)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1445198

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 tests/clitest.py       | 1 +
 virtinst/devicedisk.py | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/clitest.py b/tests/clitest.py
index 7a10264e..20dccd77 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -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.
 
 
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
index 2736c9a8..01e26e18 100644
--- a/virtinst/devicedisk.py
+++ b/virtinst/devicedisk.py
@@ -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)
-- 
2.12.2