From 199e9593bfcc35b369d9b436a5fbe8ee15eb383b Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 2 Jul 2019 19:55:54 -0400 Subject: [PATCH] storage: test default_source_name --- tests/storage-xml/pool-disk.xml | 1 - tests/storage-xml/pool-rbd.xml | 7 +++++++ tests/storage.py | 12 +++++++++--- virtinst/storage.py | 26 +++++++++++--------------- 4 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 tests/storage-xml/pool-rbd.xml diff --git a/tests/storage-xml/pool-disk.xml b/tests/storage-xml/pool-disk.xml index fda2b506..8b4f20fc 100644 --- a/tests/storage-xml/pool-disk.xml +++ b/tests/storage-xml/pool-disk.xml @@ -1,7 +1,6 @@ pool-disk - diff --git a/tests/storage-xml/pool-rbd.xml b/tests/storage-xml/pool-rbd.xml new file mode 100644 index 00000000..cc463a1f --- /dev/null +++ b/tests/storage-xml/pool-rbd.xml @@ -0,0 +1,7 @@ + + pool-rbd + + + rbd + + diff --git a/tests/storage.py b/tests/storage.py index be32ccce..1eae9d8a 100644 --- a/tests/storage.py +++ b/tests/storage.py @@ -36,8 +36,9 @@ def createPool(conn, ptype, poolname=None, fmt=None, target_path=None, pool_inst.target_path = target_path or "/some/target/path" if fmt and pool_inst.supports_format(): pool_inst.format = fmt - if source_name and pool_inst.supports_source_name(): - pool_inst.source_name = source_name + if pool_inst.supports_source_name(): + pool_inst.source_name = (source_name or + pool_inst.default_source_name()) if iqn and pool_inst.supports_iqn(): pool_inst.iqn = iqn @@ -159,7 +160,7 @@ class TestStorage(unittest.TestCase): def testDiskPool(self): poolobj = createPool(self.conn, StoragePool.TYPE_DISK, - "pool-disk", fmt="dos") + "pool-disk", fmt="auto") invol = createVol(self.conn, poolobj) createVol(self.conn, poolobj, volname=invol.name() + "input", input_vol=invol) @@ -186,6 +187,11 @@ class TestStorage(unittest.TestCase): StoragePool.TYPE_GLUSTER, "pool-gluster") removePool(poolobj) + def testRBDPool(self): + poolobj = createPool(self.conn, + StoragePool.TYPE_RBD, "pool-rbd") + removePool(poolobj) + def testMisc(self): # Misc coverage testing vol = StorageVolume(self.conn) diff --git a/virtinst/storage.py b/virtinst/storage.py index 32d5468e..d81750d7 100644 --- a/virtinst/storage.py +++ b/virtinst/storage.py @@ -286,25 +286,21 @@ class StoragePool(_StorageObject): source_path = property(_get_source, _set_source) def default_source_name(self): - srcname = None - if not self.supports_source_name(): - srcname = None - elif self.type == StoragePool.TYPE_NETFS: - srcname = self.name - elif self.type == StoragePool.TYPE_RBD: - srcname = "rbd" - elif self.type == StoragePool.TYPE_GLUSTER: - srcname = "gv0" - elif ("target_path" in self._propstore and - self.target_path and - self.target_path.startswith(_DEFAULT_LVM_TARGET_BASE)): + return None + + if self.type == StoragePool.TYPE_RBD: + return "rbd" + if self.type == StoragePool.TYPE_GLUSTER: + return "gv0" + + if ("target_path" in self._propstore and + self.target_path and + self.target_path.startswith(_DEFAULT_LVM_TARGET_BASE)): # If there is a target path, parse it for an expected VG # location, and pull the name from there vg = self.target_path[len(_DEFAULT_LVM_TARGET_BASE):] - srcname = vg.split("/", 1)[0] - - return srcname + return vg.split("/", 1)[0] ##############