storage: Add lots of coverage testing and exemptions

This commit is contained in:
Cole Robinson 2019-07-02 19:38:09 -04:00
parent f64655a843
commit 9d7b20d3de
4 changed files with 58 additions and 30 deletions

View File

@ -211,6 +211,11 @@
</source>
<target dev="vdo" bus="virtio"/>
</disk>
<disk type="file" device="disk">
<driver name="qemu" type="raw"/>
<source file="/var/lib/libvirt/images/disk.img"/>
<target dev="vdp" bus="virtio"/>
</disk>
<controller type="usb" index="0" model="ich9-ehci1">
<address type="pci" domain="0" bus="0" slot="4" function="7"/>
</controller>

View File

@ -602,6 +602,7 @@ vcpus.vcpu1.id=2,vcpus.vcpu1.enabled=yes
--disk path=/dev/disk-pool/diskvol7,device=lun,bus=scsi,reservations.managed=no,reservations.source.type=unix,reservations.source.path=/var/run/test/pr-helper0.sock,reservations.source.mode=client,\
source.reservations.managed=no,source.reservations.source.type=unix,source.reservations.source.path=/var/run/test/pr-helper0.sock,source.reservations.source.mode=client
--disk vol=iscsi-direct/unit:0:0:1
--disk size=.0001,format=raw
--network user,mac=12:34:56:78:11:22,portgroup=foo,link_state=down,rom_bar=on,rom_file=/tmp/foo
--network bridge=foobar,model=virtio,driver_name=qemu,driver_queues=3,filterref=foobar,rom.bar=off,rom.file=/some/rom,source.portgroup=foo
@ -1297,6 +1298,7 @@ c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file virt-install --file
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --file %(NEWCLONEIMG3)s --force-copy=hdc") # XML w/ disks, force copy a readonly target
c.add_valid("--original-xml " + _CLONE_UNMANAGED + " --file %(NEWCLONEIMG1)s --file %(NEWCLONEIMG2)s --force-copy=fda") # XML w/ disks, force copy a target with no media
c.add_valid("--original-xml " + _CLONE_MANAGED + " --file %(NEWIMG1)s") # XML w/ managed storage, specify managed path
c.add_valid("--original-xml " + _CLONE_MANAGED + " --file %(NEWIMG1)s --reflink") # XML w/ managed storage, specify managed path
c.add_valid("--original-xml " + _CLONE_NOEXIST + " --file %(EXISTIMG1)s --preserve") # XML w/ managed storage, specify managed path across pools# Libvirt test driver doesn't support cloning across pools# XML w/ non-existent storage, with --preserve
c.add_valid("--connect %(URI-TEST-FULL)s -o test -n test-clone --auto-clone --replace") # Overwriting existing VM
c.add_invalid("-o test foobar") # Positional arguments error

View File

@ -186,6 +186,31 @@ class TestStorage(unittest.TestCase):
StoragePool.TYPE_GLUSTER, "pool-gluster")
removePool(poolobj)
def testMisc(self):
# Misc coverage testing
vol = StorageVolume(self.conn)
self.assertTrue(vol.is_size_conflict()[0] is False)
fullconn = utils.URIs.open_testdriver_cached()
glusterpool = fullconn.storagePoolLookupByName("gluster-pool")
diskpool = fullconn.storagePoolLookupByName("disk-pool")
glustervol = StorageVolume(fullconn)
glustervol.pool = glusterpool
self.assertTrue(glustervol.supports_format() is True)
diskvol = StorageVolume(fullconn)
diskvol.pool = diskpool
self.assertTrue(diskvol.supports_format() is False)
glusterpool.destroy()
StoragePool.ensure_pool_is_running(glusterpool)
# Check pool collision detection
self.assertEqual(
StoragePool.find_free_name(fullconn, "gluster-pool"),
"gluster-pool-1")
##############################
# Tests for pool-sources API #

View File

@ -142,7 +142,7 @@ class StoragePool(_StorageObject):
except Exception as e:
if conn.support.is_error_nosupport(e):
return []
raise
raise # pragma: no cover
ret = []
sources = _EnumerateSources(conn, xml)
@ -188,7 +188,7 @@ class StoragePool(_StorageObject):
defpool.target_path = path
defpool.install(build=True, create=True, autostart=True)
return defpool
except Exception as e:
except Exception as e: # pragma: no cover
raise RuntimeError(
_("Couldn't create default storage pool '%s': %s") %
(path, str(e)))
@ -249,7 +249,7 @@ class StoragePool(_StorageObject):
except libvirt.libvirtError:
return
raise ValueError(_("Name '%s' already in use by another pool." %
name))
name)) # pragma: no cover
def default_target_path(self):
if not self.supports_target_path():
@ -441,29 +441,29 @@ class StoragePool(_StorageObject):
try:
pool = self.conn.storagePoolDefineXML(xml, 0)
except Exception as e:
except Exception as e: # pragma: no cover
raise RuntimeError(_("Could not define storage pool: %s") % str(e))
errmsg = None
if build:
try:
pool.build(libvirt.VIR_STORAGE_POOL_BUILD_NEW)
except Exception as e:
except Exception as e: # pragma: no cover
errmsg = _("Could not build storage pool: %s") % str(e)
if create and not errmsg:
try:
pool.create(0)
except Exception as e:
except Exception as e: # pragma: no cover
errmsg = _("Could not start storage pool: %s") % str(e)
if autostart and not errmsg:
try:
pool.setAutostart(True)
except Exception as e:
except Exception as e: # pragma: no cover
errmsg = _("Could not set pool autostart flag: %s") % str(e)
if errmsg:
if errmsg: # pragma: no cover
# Try and clean up the leftover pool
try:
pool.undefine()
@ -556,13 +556,6 @@ class StorageVolume(_StorageObject):
def _get_input_vol(self):
return self._input_vol
def _set_input_vol(self, vol):
if vol is None:
self._input_vol = None
return
if not isinstance(vol, libvirt.virStorageVol):
raise ValueError(_("input_vol must be a virStorageVol"))
self._input_vol = vol
input_vol = property(_get_input_vol, _set_input_vol)
@ -598,10 +591,10 @@ class StorageVolume(_StorageObject):
except libvirt.libvirtError:
return
raise ValueError(_("Name '%s' already in use by another volume." %
name))
name)) # pragma: no cover
def _get_vol_type(self):
if self.type:
if self.type: # pragma: no cover
if self.type == "file":
return self.TYPE_FILE
elif self.type == "block":
@ -640,7 +633,7 @@ class StorageVolume(_StorageObject):
from . import diskbackend
vol, pool = diskbackend.manage_path(self.conn, self.backing_store)
if not vol:
if not vol: # pragma: no cover
log.debug("Didn't find any volume for backing_store")
return None
@ -651,13 +644,13 @@ class StorageVolume(_StorageObject):
log.debug("Found backing store volume XML:\n%s",
volxml.get_xml())
if volxml.supports_format():
log.debug("Returning format=%s", volxml.format)
return volxml.format
if not volxml.supports_format(): # pragma: no cover
log.debug("backing_store volume doesn't appear to have "
"a file format we can specify, returning None")
return None
log.debug("backing_store volume doesn't appear to have "
"a file format we can specify, returning None")
return None
log.debug("Returning format=%s", volxml.format)
return volxml.format
######################
@ -718,7 +711,6 @@ class StorageVolume(_StorageObject):
createflags = 0
if (self.format == "qcow2" and
not self.backing_store and
not self.conn.is_really_test() and
self.conn.support.pool_metadata_prealloc(self.pool)):
createflags |= libvirt.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
if self.capacity == self.allocation:
@ -736,6 +728,11 @@ class StorageVolume(_StorageObject):
meter.start(size=self.capacity,
text=_("Allocating '%s'") % self.name)
if self.conn.is_really_test():
# Test suite doesn't support any flags, so reset them
createflags = 0
cloneflags = 0
if self.input_vol:
vol = self.pool.createXMLFrom(xml, self.input_vol, cloneflags)
else:
@ -745,8 +742,7 @@ class StorageVolume(_StorageObject):
self._install_finished.set()
t.join()
meter.end(self.capacity)
log.debug("Storage volume '%s' install complete.",
self.name)
log.debug("Storage volume '%s' install complete.", self.name)
return vol
except Exception as e:
log.debug("Error creating storage volume", exc_info=True)
@ -762,8 +758,8 @@ class StorageVolume(_StorageObject):
try:
if not vol:
vol = self.pool.storageVolLookupByName(self.name)
vol.info()
break
vol.info() # pragma: no cover
break # pragma: no cover
except Exception:
if self._install_finished.wait(.2):
break
@ -772,7 +768,7 @@ class StorageVolume(_StorageObject):
log.debug("Couldn't lookup storage volume in prog thread.")
return
while True:
while True: # pragma: no cover
ignore, ignore, alloc = vol.info()
meter.update(alloc)
if self._install_finished.wait(1):