tests: Add a clone test for importing nvram directory

Need to use some callback magic to fake it like there's a file in
an existing directory
This commit is contained in:
Cole Robinson 2017-07-18 15:42:11 -04:00
parent a9903ae0e0
commit 1a09a05dc7
5 changed files with 73 additions and 8 deletions

View File

@ -0,0 +1,23 @@
<domain type='kvm'>
<name>clone-orig</name>
<uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='cdrom'/>
<loader readonly='yes' type='pflash'>/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram-newpool/clone-orig-vars.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -0,0 +1,23 @@
<domain type="kvm">
<name>clone-new</name>
<uuid>12345678-1234-1234-1234-123456789012</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="i686" machine="pc">hvm</type>
<boot dev="cdrom"/>
<loader readonly="yes" type="pflash">/usr/share/ovmf/ovmf-efi.fd</loader>
<nvram>/nvram-newpool/clone-new_VARS.fd</nvram>
</os>
<features>
<acpi/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
</devices>
</domain>

View File

@ -183,3 +183,7 @@ class TestClone(unittest.TestCase):
def testCloneNvramAuto(self):
base = "nvram-auto"
self._clone_helper(base)
def testCloneNvramNewpool(self):
base = "nvram-newpool"
self._clone_helper(base)

View File

@ -98,6 +98,19 @@ def openconn(uri):
for key, value in _conn_cache[uri].items():
conn._fetch_cache[key] = value[:]
def cb_cache_new_pool(poolobj):
# Used by clonetest.py nvram-newpool test
if poolobj.name() == "nvram-newpool":
from virtinst import StorageVolume
vol = StorageVolume(conn)
vol.pool = poolobj
vol.name = "clone-orig-vars.fd"
vol.capacity = 1024 * 1024
vol.install()
conn._cache_new_pool_raw(poolobj)
conn.cb_cache_new_pool = cb_cache_new_pool
return conn

View File

@ -239,14 +239,7 @@ class VirtualConnection(object):
self._fetch_cache[key] = self._fetch_all_vols_raw()
return self._fetch_cache[key][:]
def cache_new_pool(self, poolobj):
"""
Insert the passed poolobj into our cache
"""
if self.cb_cache_new_pool:
# pylint: disable=not-callable
return self.cb_cache_new_pool(poolobj)
def _cache_new_pool_raw(self, poolobj):
# Make sure cache is primed
if self._FETCH_KEY_POOLS not in self._fetch_cache:
# Nothing cached yet, so next poll will pull in latest bits,
@ -259,6 +252,15 @@ class VirtualConnection(object):
vollist = self._fetch_cache[self._FETCH_KEY_VOLS]
vollist.extend(self._fetch_vols_raw(poolxmlobj))
def cache_new_pool(self, poolobj):
"""
Insert the passed poolobj into our cache
"""
if self.cb_cache_new_pool:
# pylint: disable=not-callable
return self.cb_cache_new_pool(poolobj)
return self._cache_new_pool_raw(poolobj)
def _fetch_all_nodedevs_raw(self):
ignore, ignore, ret = pollhelpers.fetch_nodedevs(
self, {}, lambda obj, ignore: obj)