tests: Fix running testsuite on older libvirt
If we try to run the testsuite on anything older than libvirt 3.1, it immediately throws an exception before processing any tests, due to choking on parsing drm bits from testdriver.xml. This global failure is only due to sloppy coding though. Turn all test cases that use testdriver.xml into skips in this case, so we can at least get some test coverage otherwise.
This commit is contained in:
parent
62fecb09d3
commit
6954c6774a
|
@ -24,12 +24,10 @@ from virtinst import Capabilities
|
|||
from virtinst import DomainCapabilities
|
||||
|
||||
|
||||
conn = utils.open_testdefault()
|
||||
|
||||
|
||||
class TestCapabilities(unittest.TestCase):
|
||||
def _buildCaps(self, filename):
|
||||
path = os.path.join("tests/capabilities-xml", filename)
|
||||
conn = utils.URIs.open_testdefault_cached()
|
||||
return Capabilities(conn, open(path).read())
|
||||
|
||||
def testCapsCPUFeaturesOldSyntax(self):
|
||||
|
@ -122,7 +120,7 @@ class TestCapabilities(unittest.TestCase):
|
|||
|
||||
def testDomainCapabilities(self):
|
||||
xml = open("tests/capabilities-xml/test-domcaps.xml").read()
|
||||
caps = DomainCapabilities(utils.open_testdriver(), xml)
|
||||
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
||||
|
||||
self.assertEqual(caps.os.loader.supported, True)
|
||||
self.assertEqual(caps.os.loader.get_values(),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
import logging
|
||||
import traceback
|
||||
import unittest
|
||||
|
||||
|
@ -12,15 +13,28 @@ class CheckPropsTest(unittest.TestCase):
|
|||
# pylint: disable=protected-access
|
||||
# Access to protected member, needed to unittest stuff
|
||||
|
||||
skip = False
|
||||
try:
|
||||
# Accessing an internal detail of unittest, but it's only
|
||||
# to prevent incorrect output in the case that other tests
|
||||
# failed or were skipped, which can give a false postive here
|
||||
result = self._outcome.result
|
||||
skip = bool(result.errors or result.failures or result.skipped)
|
||||
except Exception:
|
||||
logging.debug("unittest skip hack failed", exc_info=True)
|
||||
if skip:
|
||||
self.skipTest("skipping as other tests failed/skipped")
|
||||
|
||||
# If a certain environment variable is set, XMLBuilder tracks
|
||||
# every property registered and every one of those that is
|
||||
# actually altered. The test suite sets that env variable.
|
||||
#
|
||||
# test000ClearProps resets the 'set' list, and this test
|
||||
# testClearProps resets the 'set' list, and this test
|
||||
# ensures that every property we know about has been touched
|
||||
# by one of the above tests.
|
||||
fail = [p for p in virtinst.xmlbuilder._allprops
|
||||
if p not in virtinst.xmlbuilder._seenprops]
|
||||
msg = None
|
||||
try:
|
||||
self.assertEqual([], fail)
|
||||
except AssertionError:
|
||||
|
@ -30,4 +44,6 @@ class CheckPropsTest(unittest.TestCase):
|
|||
"by a previous test suite failure, or if you added\n"
|
||||
"a new property and didn't extend the test suite.\n"
|
||||
"Look into extending clitest.py and/or xmlparse.py.")
|
||||
|
||||
if msg:
|
||||
self.fail(msg)
|
||||
|
|
|
@ -227,7 +227,7 @@ class Command(object):
|
|||
conn = None
|
||||
for idx in reversed(range(len(self.argv))):
|
||||
if self.argv[idx] == "--connect":
|
||||
conn = utils.openconn(self.argv[idx + 1])
|
||||
conn = utils.URIs.openconn(self.argv[idx + 1])
|
||||
break
|
||||
|
||||
if not conn:
|
||||
|
|
|
@ -61,7 +61,7 @@ class TestClone(unittest.TestCase):
|
|||
in_content = utils.read_file(infile)
|
||||
|
||||
if not conn:
|
||||
conn = utils.open_testdriver()
|
||||
conn = utils.URIs.open_testdriver_cached()
|
||||
cloneobj = Cloner(conn)
|
||||
cloneobj.original_xml = in_content
|
||||
for force in force_list or []:
|
||||
|
@ -113,12 +113,12 @@ class TestClone(unittest.TestCase):
|
|||
connection to ensure we don't get any errors"""
|
||||
outfile = os.path.join(clonexml_dir, filebase + "-out.xml")
|
||||
outxml = utils.read_file(outfile)
|
||||
conn = utils.open_testdriver()
|
||||
conn = utils.URIs.open_testdriver_cached()
|
||||
utils.test_create(conn, outxml)
|
||||
|
||||
def testRemoteNoStorage(self):
|
||||
"""Test remote clone where VM has no storage that needs cloning"""
|
||||
conn = utils.open_test_remote()
|
||||
conn = utils.URIs.open_test_remote()
|
||||
self._clone("nostorage", conn=conn)
|
||||
self._clone("noclone-storage", conn=conn)
|
||||
|
||||
|
@ -127,7 +127,7 @@ class TestClone(unittest.TestCase):
|
|||
Test remote clone with storage needing cloning. Should fail,
|
||||
since libvirt has no storage clone api.
|
||||
"""
|
||||
conn = utils.open_test_remote()
|
||||
conn = utils.URIs.open_test_remote()
|
||||
disks = ["%s/1.img" % POOL1, "%s/2.img" % POOL1]
|
||||
try:
|
||||
self._clone("general-cfg", disks=disks, conn=conn)
|
||||
|
@ -143,7 +143,7 @@ class TestClone(unittest.TestCase):
|
|||
self._clone("managed-storage", disks=disks)
|
||||
|
||||
def testCloneStorageCrossPool(self):
|
||||
conn = utils.open_test_remote()
|
||||
conn = utils.URIs.open_test_remote()
|
||||
clone_disks_file = os.path.join(
|
||||
clonexml_dir, "cross-pool-disks-out.xml")
|
||||
disks = ["%s/new1.img" % POOL2, "%s/new2.img" % POOL1]
|
||||
|
|
|
@ -22,18 +22,18 @@ import logging
|
|||
from virtinst import Interface, InterfaceProtocol
|
||||
from tests import utils
|
||||
|
||||
conn = utils.open_testdriver()
|
||||
datadir = "tests/interface-xml"
|
||||
|
||||
|
||||
def _m(_n):
|
||||
xml = conn.interfaceLookupByName(_n).XMLDesc(0)
|
||||
return Interface(conn, parsexml=xml)
|
||||
|
||||
|
||||
class TestInterfaces(unittest.TestCase):
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdriver_cached()
|
||||
|
||||
def build_interface(self, interface_type, name):
|
||||
iobj = Interface(conn)
|
||||
iobj = Interface(self.conn)
|
||||
iobj.type = interface_type
|
||||
iobj.name = name
|
||||
|
||||
|
@ -43,11 +43,14 @@ class TestInterfaces(unittest.TestCase):
|
|||
iface_obj.mtu = 1501
|
||||
iface_obj.macaddr = "AA:AA:AA:AA:AA:AA"
|
||||
iface_obj.start_mode = Interface.INTERFACE_START_MODE_ONBOOT
|
||||
proto = InterfaceProtocol(conn)
|
||||
proto = InterfaceProtocol(self.conn)
|
||||
proto.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4
|
||||
iface_obj.add_protocol(proto)
|
||||
|
||||
def add_child_interfaces(self, iface_obj):
|
||||
def _m(_n):
|
||||
xml = self.conn.interfaceLookupByName(_n).XMLDesc(0)
|
||||
return Interface(self.conn, parsexml=xml)
|
||||
if iface_obj.type == Interface.INTERFACE_TYPE_BRIDGE:
|
||||
iface_obj.add_interface(_m("vlaneth1"))
|
||||
iface_obj.add_interface(_m("bond-brbond"))
|
||||
|
@ -93,7 +96,7 @@ class TestInterfaces(unittest.TestCase):
|
|||
self.add_child_interfaces(obj)
|
||||
|
||||
# IPv4 proto
|
||||
iface_proto1 = InterfaceProtocol(conn)
|
||||
iface_proto1 = InterfaceProtocol(self.conn)
|
||||
iface_proto1.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV4
|
||||
iface_proto1.add_ip("129.63.1.2")
|
||||
iface_proto1.add_ip("255.255.255.0")
|
||||
|
@ -102,7 +105,7 @@ class TestInterfaces(unittest.TestCase):
|
|||
iface_proto1.dhcp_peerdns = True
|
||||
|
||||
# IPv6 proto
|
||||
iface_proto2 = InterfaceProtocol(conn)
|
||||
iface_proto2 = InterfaceProtocol(self.conn)
|
||||
iface_proto2.family = InterfaceProtocol.INTERFACE_PROTOCOL_FAMILY_IPV6
|
||||
|
||||
iface_proto2.add_ip("fe99::215:58ff:fe6e:5", prefix="32")
|
||||
|
@ -204,7 +207,7 @@ class TestInterfaces(unittest.TestCase):
|
|||
protoxml = (" <protocol family='ipv6'>\n"
|
||||
" <dhcp/>\n"
|
||||
" </protocol>\n")
|
||||
proto = InterfaceProtocol(conn, parsexml=protoxml)
|
||||
proto = InterfaceProtocol(self.conn, parsexml=protoxml)
|
||||
obj.add_protocol(proto)
|
||||
|
||||
self.define_xml(obj)
|
||||
|
|
|
@ -25,8 +25,6 @@ from virtinst import VirtualHostDevice
|
|||
|
||||
from tests import utils
|
||||
|
||||
conn = utils.open_testdriver()
|
||||
|
||||
unknown_xml = """
|
||||
<device>
|
||||
<name>foodevice</name>
|
||||
|
@ -61,11 +59,14 @@ funky_chars_xml = """
|
|||
|
||||
|
||||
class TestNodeDev(unittest.TestCase):
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdriver_cached()
|
||||
|
||||
def _nodeDevFromName(self, devname):
|
||||
node = conn.nodeDeviceLookupByName(devname)
|
||||
node = self.conn.nodeDeviceLookupByName(devname)
|
||||
xml = node.XMLDesc(0)
|
||||
return NodeDevice.parse(conn, xml)
|
||||
return NodeDevice.parse(self.conn, xml)
|
||||
|
||||
def _testCompare(self, devname, vals, devxml=None):
|
||||
def _compare(dev, vals, root=""):
|
||||
|
@ -82,7 +83,7 @@ class TestNodeDev(unittest.TestCase):
|
|||
self.assertEqual(vals[attr], getattr(dev, attr))
|
||||
|
||||
if devxml:
|
||||
dev = NodeDevice.parse(conn, devxml)
|
||||
dev = NodeDevice.parse(self.conn, devxml)
|
||||
else:
|
||||
dev = self._nodeDevFromName(devname)
|
||||
|
||||
|
@ -94,7 +95,7 @@ class TestNodeDev(unittest.TestCase):
|
|||
if not nodedev:
|
||||
nodedev = self._nodeDevFromName(nodename)
|
||||
|
||||
dev = VirtualHostDevice(conn)
|
||||
dev = VirtualHostDevice(self.conn)
|
||||
dev.set_from_nodedev(nodedev)
|
||||
utils.diff_compare(dev.get_xml_config() + "\n", devfile)
|
||||
|
||||
|
@ -248,7 +249,7 @@ class TestNodeDev(unittest.TestCase):
|
|||
"device_type": NodeDevice.CAPABILITY_TYPE_DRM,
|
||||
"drm_type": "render"}
|
||||
dev = self._testCompare(devname, vals)
|
||||
self.assertEqual(dev.drm_pretty_name(conn),
|
||||
self.assertEqual(dev.drm_pretty_name(self.conn),
|
||||
"0000:00:02:0 Intel Corporation HD Graphics 530 (render)")
|
||||
|
||||
def testUnknownDevice(self):
|
||||
|
|
|
@ -47,7 +47,7 @@ class TestOSDB(unittest.TestCase):
|
|||
(osobj.name, osobj.get_typename()))
|
||||
|
||||
def test_recommended_resources(self):
|
||||
conn = utils.open_testdefault()
|
||||
conn = utils.URIs.open_testdefault_cached()
|
||||
guest = conn.caps.lookup_virtinst_guest()
|
||||
assert not OSDB.lookup_os("generic").get_recommended_resources(guest)
|
||||
|
||||
|
|
|
@ -105,9 +105,9 @@ def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
|
|||
|
||||
|
||||
class TestStorage(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.conn = utils.open_testdefault()
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdefault_cached()
|
||||
|
||||
def testDirPool(self):
|
||||
poolobj = createPool(self.conn,
|
||||
|
|
|
@ -16,7 +16,7 @@ from virtinst.initrdinject import perform_initrd_injections
|
|||
cleanup = []
|
||||
_alldistros = {}
|
||||
|
||||
testconn = utils.open_testdefault()
|
||||
testconn = utils.URIs.open_testdefault_cached()
|
||||
guest = Guest(testconn)
|
||||
guest.os.os_type = "hvm"
|
||||
guest.os.arch = "x86_64"
|
||||
|
|
|
@ -100,7 +100,7 @@ class _DistroURL(object):
|
|||
return "x86_64"
|
||||
return "x86_64"
|
||||
|
||||
testconn = utils.open_testdefault()
|
||||
testconn = utils.URIs.open_testdefault_cached()
|
||||
hvmguest = Guest(testconn)
|
||||
hvmguest.os.os_type = "hvm"
|
||||
xenguest = Guest(testconn)
|
||||
|
|
148
tests/utils.py
148
tests/utils.py
|
@ -17,6 +17,10 @@
|
|||
|
||||
import difflib
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import libvirt
|
||||
|
||||
import virtinst
|
||||
import virtinst.cli
|
||||
|
@ -75,75 +79,99 @@ def _make_uri(base, connver=None, libver=None):
|
|||
return base
|
||||
|
||||
|
||||
_conn_cache = {}
|
||||
class _URIs(object):
|
||||
def __init__(self):
|
||||
self._conn_cache = {}
|
||||
self._testdriver_cache = None
|
||||
self._testdriver_error = None
|
||||
self._testdriver_default = None
|
||||
|
||||
def openconn(self, uri):
|
||||
"""
|
||||
Extra super caching to speed up the test suite. We basically
|
||||
cache the first guest/pool/vol poll attempt for each URI, and save it
|
||||
across multiple reopenings of that connection. We aren't caching
|
||||
libvirt objects, just parsed XML objects. This works fine since
|
||||
generally every test uses a fresh virConnect, or undoes the
|
||||
persistent changes it makes.
|
||||
"""
|
||||
virtinst.util.register_libvirt_error_handler()
|
||||
is_testdriver_xml = "/testdriver.xml" in uri
|
||||
|
||||
def openconn(uri):
|
||||
"""
|
||||
Extra super caching to speed up the test suite. We basically
|
||||
cache the first guest/pool/vol poll attempt for each URI, and save it
|
||||
across multiple reopenings of that connection. We aren't caching
|
||||
libvirt objects, just parsed XML objects. This works fine since
|
||||
generally every test uses a fresh virConnect, or undoes the
|
||||
persistent changes it makes.
|
||||
"""
|
||||
virtinst.util.register_libvirt_error_handler()
|
||||
conn = virtinst.cli.getConnection(uri)
|
||||
uri = conn._open_uri
|
||||
if not (is_testdriver_xml and self._testdriver_error):
|
||||
try:
|
||||
conn = virtinst.cli.getConnection(uri)
|
||||
except libvirt.libvirtError as e:
|
||||
if not is_testdriver_xml:
|
||||
raise
|
||||
self._testdriver_error = (
|
||||
"error opening testdriver.xml: %s\n"
|
||||
"libvirt is probably too old" % str(e))
|
||||
print(self._testdriver_error, file=sys.stderr)
|
||||
|
||||
if is_testdriver_xml and self._testdriver_error:
|
||||
raise unittest.SkipTest(self._testdriver_error)
|
||||
|
||||
uri = conn._open_uri
|
||||
|
||||
# For the basic test:///default URI, skip this caching, so we have
|
||||
# an option to test the stock code
|
||||
if uri == uri_test_default:
|
||||
return conn
|
||||
|
||||
if uri not in self._conn_cache:
|
||||
conn.fetch_all_guests()
|
||||
conn.fetch_all_pools()
|
||||
conn.fetch_all_vols()
|
||||
conn.fetch_all_nodedevs()
|
||||
|
||||
self._conn_cache[uri] = {}
|
||||
for key, value in conn._fetch_cache.items():
|
||||
self._conn_cache[uri][key] = value[:]
|
||||
|
||||
# Prime the internal connection cache
|
||||
for key, value in self._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
|
||||
|
||||
# For the basic test:///default URI, skip this caching, so we have
|
||||
# an option to test the stock code
|
||||
if uri == uri_test_default:
|
||||
return conn
|
||||
|
||||
if uri not in _conn_cache:
|
||||
conn.fetch_all_guests()
|
||||
conn.fetch_all_pools()
|
||||
conn.fetch_all_vols()
|
||||
conn.fetch_all_nodedevs()
|
||||
def open_testdriver_cached(self):
|
||||
"""
|
||||
Open plain testdriver.xml and cache the instance. Tests that
|
||||
use this are expected to clean up after themselves so driver
|
||||
state doesn't become polluted.
|
||||
"""
|
||||
if not self._testdriver_cache:
|
||||
self._testdriver_cache = self.openconn(uri_test)
|
||||
return self._testdriver_cache
|
||||
|
||||
_conn_cache[uri] = {}
|
||||
for key, value in conn._fetch_cache.items():
|
||||
_conn_cache[uri][key] = value[:]
|
||||
def open_testdefault_cached(self):
|
||||
if not self._testdriver_default:
|
||||
self._testdriver_default = self.openconn(uri_test_default)
|
||||
return self._testdriver_default
|
||||
|
||||
# Prime the internal connection cache
|
||||
for key, value in _conn_cache[uri].items():
|
||||
conn._fetch_cache[key] = value[:]
|
||||
def open_kvm(self, connver=None, libver=None):
|
||||
return self.openconn(_make_uri(uri_kvm, connver, libver))
|
||||
def open_kvm_rhel(self, connver=None):
|
||||
return self.openconn(_make_uri(uri_kvm_rhel, connver))
|
||||
def open_test_remote(self):
|
||||
return self.openconn(uri_test_remote)
|
||||
|
||||
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)
|
||||
URIs = _URIs()
|
||||
|
||||
conn.cb_cache_new_pool = cb_cache_new_pool
|
||||
|
||||
return conn
|
||||
|
||||
|
||||
def open_testdefault():
|
||||
return openconn(uri_test_default)
|
||||
|
||||
|
||||
def open_testdriver():
|
||||
return openconn(uri_test)
|
||||
|
||||
|
||||
def open_kvm(connver=None, libver=None):
|
||||
return openconn(_make_uri(uri_kvm, connver, libver))
|
||||
|
||||
|
||||
def open_kvm_rhel(connver=None):
|
||||
return openconn(_make_uri(uri_kvm_rhel, connver))
|
||||
|
||||
|
||||
def open_test_remote():
|
||||
return openconn(uri_test_remote)
|
||||
|
||||
|
||||
def test_create(testconn, xml, define_func="defineXML"):
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestVirtConv(unittest.TestCase):
|
|||
def print_cb(msg):
|
||||
print(msg, file=outbuf)
|
||||
|
||||
conn = utils.open_kvm()
|
||||
conn = utils.URIs.open_kvm()
|
||||
converter = VirtConverter(conn, in_path, print_cb=print_cb)
|
||||
|
||||
if converter.parser.name != in_type:
|
||||
|
|
|
@ -25,16 +25,12 @@ from virtcli import CLIConfig
|
|||
from tests import utils
|
||||
|
||||
|
||||
_default_conn = utils.open_testdefault()
|
||||
_feature_conn = utils.open_testdriver()
|
||||
|
||||
|
||||
def _make_guest(installer=None, conn=None, os_variant=None):
|
||||
if not conn:
|
||||
if installer:
|
||||
conn = installer.conn
|
||||
else:
|
||||
conn = _feature_conn
|
||||
conn = utils.URIs.open_testdriver_cached()
|
||||
if not installer:
|
||||
installer = _make_installer(conn=conn)
|
||||
|
||||
|
@ -102,7 +98,7 @@ def _make_guest(installer=None, conn=None, os_variant=None):
|
|||
|
||||
|
||||
def _make_installer(location=None, conn=None):
|
||||
conn = conn or _feature_conn
|
||||
conn = conn or utils.URIs.open_testdriver_cached()
|
||||
inst = virtinst.DistroInstaller(conn)
|
||||
if location:
|
||||
inst.location = location
|
||||
|
@ -118,6 +114,10 @@ class TestXMLMisc(unittest.TestCase):
|
|||
testing any particularly tricky bits, general XML generation should
|
||||
be through virt-install examples in clitest
|
||||
"""
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdefault_cached()
|
||||
|
||||
def _compare(self, guest, filebase, do_install):
|
||||
filename = os.path.join("tests/xmlconfig-xml", filebase + ".xml")
|
||||
|
||||
|
@ -139,16 +139,16 @@ class TestXMLMisc(unittest.TestCase):
|
|||
return "bzz0"
|
||||
setattr(deviceinterface, "_default_bridge", newbridge)
|
||||
|
||||
dev1 = virtinst.VirtualNetworkInterface(_default_conn)
|
||||
dev1 = virtinst.VirtualNetworkInterface(self.conn)
|
||||
dev1.macaddr = "22:22:33:44:55:66"
|
||||
|
||||
dev2 = virtinst.VirtualNetworkInterface(_default_conn,
|
||||
dev2 = virtinst.VirtualNetworkInterface(self.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
dev2.source = None
|
||||
dev2.source = "foobr0"
|
||||
dev2.macaddr = "22:22:33:44:55:67"
|
||||
|
||||
dev3 = virtinst.VirtualNetworkInterface(_default_conn,
|
||||
dev3 = virtinst.VirtualNetworkInterface(self.conn,
|
||||
parsexml=dev1.get_xml_config())
|
||||
dev3.source = None
|
||||
dev3.macaddr = "22:22:33:44:55:68"
|
||||
|
@ -172,7 +172,7 @@ class TestXMLMisc(unittest.TestCase):
|
|||
|
||||
def testCpustrToTuple(self):
|
||||
# Various testing our cpustr handling
|
||||
conn = _default_conn
|
||||
conn = self.conn
|
||||
base = [False] * 16
|
||||
|
||||
expect = base[:]
|
||||
|
@ -213,7 +213,7 @@ class TestXMLMisc(unittest.TestCase):
|
|||
self.assertEqual(VirtualDisk.target_to_num("xvdaaa"),
|
||||
26 * 26 * 1 + 26 * 1 + 0)
|
||||
|
||||
disk = virtinst.VirtualDisk(_default_conn)
|
||||
disk = virtinst.VirtualDisk(self.conn)
|
||||
disk.bus = "ide"
|
||||
|
||||
self.assertEqual("hda", disk.generate_target([]))
|
||||
|
@ -243,27 +243,27 @@ class TestXMLMisc(unittest.TestCase):
|
|||
|
||||
def testCPUTopology(self):
|
||||
# Test CPU topology determining
|
||||
cpu = virtinst.CPU(_default_conn)
|
||||
cpu = virtinst.CPU(self.conn)
|
||||
cpu.sockets = "2"
|
||||
cpu.set_topology_defaults(6)
|
||||
self.assertEqual([cpu.sockets, cpu.cores, cpu.threads], [2, 3, 1])
|
||||
|
||||
cpu = virtinst.CPU(_default_conn)
|
||||
cpu = virtinst.CPU(self.conn)
|
||||
cpu.cores = "4"
|
||||
cpu.set_topology_defaults(9)
|
||||
self.assertEqual([cpu.sockets, cpu.cores, cpu.threads], [2, 4, 1])
|
||||
|
||||
cpu = virtinst.CPU(_default_conn)
|
||||
cpu = virtinst.CPU(self.conn)
|
||||
cpu.threads = "3"
|
||||
cpu.set_topology_defaults(14)
|
||||
self.assertEqual([cpu.sockets, cpu.cores, cpu.threads], [4, 1, 3])
|
||||
|
||||
cpu = virtinst.CPU(_default_conn)
|
||||
cpu = virtinst.CPU(self.conn)
|
||||
cpu.sockets = 5
|
||||
cpu.cores = 2
|
||||
self.assertEqual(cpu.vcpus_from_topology(), 10)
|
||||
|
||||
cpu = virtinst.CPU(_default_conn)
|
||||
cpu = virtinst.CPU(self.conn)
|
||||
self.assertEqual(cpu.vcpus_from_topology(), 1)
|
||||
|
||||
def testAC97(self):
|
||||
|
@ -275,9 +275,10 @@ class TestXMLMisc(unittest.TestCase):
|
|||
xml, ignore = g.start_install(return_xml=True, dry=True)
|
||||
return "ac97" in xml
|
||||
|
||||
self.assertTrue(has_ac97(utils.open_kvm(connver=11000)))
|
||||
self.assertFalse(has_ac97(utils.open_kvm(libver=5000)))
|
||||
self.assertFalse(has_ac97(utils.open_kvm(libver=7000, connver=7000)))
|
||||
self.assertTrue(has_ac97(utils.URIs.open_kvm(connver=11000)))
|
||||
self.assertFalse(has_ac97(utils.URIs.open_kvm(libver=5000)))
|
||||
self.assertFalse(has_ac97(
|
||||
utils.URIs.open_kvm(libver=7000, connver=7000)))
|
||||
|
||||
def testOSDeviceDefaultChange(self):
|
||||
"""
|
||||
|
@ -285,7 +286,7 @@ class TestXMLMisc(unittest.TestCase):
|
|||
distro/variant mid process
|
||||
"""
|
||||
# Use connver=12005 so that non-rhel displays ac97
|
||||
conn = utils.open_kvm_rhel(connver=12005)
|
||||
conn = utils.URIs.open_kvm_rhel(connver=12005)
|
||||
|
||||
g = _make_guest(conn=conn, os_variant="fedora11")
|
||||
self._compare(g, "install-f11-norheldefaults", False)
|
||||
|
@ -307,7 +308,7 @@ class TestXMLMisc(unittest.TestCase):
|
|||
|
||||
def test_hyperv_clock(self):
|
||||
def _make(connver):
|
||||
conn = utils.open_kvm(libver=1002002, connver=connver)
|
||||
conn = utils.URIs.open_kvm(libver=1002002, connver=connver)
|
||||
g = _make_guest(conn=conn, os_variant="win7")
|
||||
g.emulator = "/usr/libexec/qemu-kvm"
|
||||
return g
|
||||
|
|
|
@ -23,9 +23,6 @@ import virtinst
|
|||
|
||||
from tests import utils
|
||||
|
||||
conn = utils.open_testdefault()
|
||||
kvmconn = utils.open_kvm()
|
||||
|
||||
|
||||
def sanitize_file_xml(xml):
|
||||
# s/"/'/g from generated XML, matches what libxml dumps out
|
||||
|
@ -34,17 +31,29 @@ def sanitize_file_xml(xml):
|
|||
|
||||
|
||||
class XMLParseTest(unittest.TestCase):
|
||||
_kvmconn = None
|
||||
|
||||
@property
|
||||
def conn(self):
|
||||
return utils.URIs.open_testdefault_cached()
|
||||
|
||||
@property
|
||||
def kvmconn(self):
|
||||
if not self._kvmconn:
|
||||
self._kvmconn = utils.URIs.open_kvm()
|
||||
return self._kvmconn
|
||||
|
||||
def _roundtrip_compare(self, filename):
|
||||
expectXML = sanitize_file_xml(open(filename).read())
|
||||
guest = virtinst.Guest(conn, parsexml=expectXML)
|
||||
guest = virtinst.Guest(self.conn, parsexml=expectXML)
|
||||
actualXML = guest.get_xml_config()
|
||||
utils.diff_compare(actualXML, expect_out=expectXML)
|
||||
|
||||
def _alter_compare(self, actualXML, outfile, support_check=None):
|
||||
utils.diff_compare(actualXML, outfile)
|
||||
if (support_check and not conn.check_support(support_check)):
|
||||
if (support_check and not self.conn.check_support(support_check)):
|
||||
return
|
||||
utils.test_create(conn, actualXML)
|
||||
utils.test_create(self.conn, actualXML)
|
||||
|
||||
def testRoundTrip(self):
|
||||
"""
|
||||
|
@ -87,7 +96,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
def _get_test_content(self, basename, kvm=False):
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
guest = virtinst.Guest(kvm and kvmconn or conn,
|
||||
guest = virtinst.Guest(kvm and self.kvmconn or self.conn,
|
||||
parsexml=open(infile).read())
|
||||
return guest, outfile
|
||||
|
||||
|
@ -223,7 +232,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("locked", False, True)
|
||||
|
||||
self._alter_compare(guest.get_xml_config(), outfile,
|
||||
support_check=conn.SUPPORT_CONN_VMPORT)
|
||||
support_check=self.conn.SUPPORT_CONN_VMPORT)
|
||||
|
||||
def testSeclabel(self):
|
||||
guest, outfile = self._get_test_content("change-seclabel")
|
||||
|
@ -421,7 +430,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
def testSingleDisk(self):
|
||||
xml = ("""<disk type="file" device="disk"><source file="/a.img"/>\n"""
|
||||
"""<target dev="hda" bus="ide"/></disk>\n""")
|
||||
d = virtinst.VirtualDisk(conn, parsexml=xml)
|
||||
d = virtinst.VirtualDisk(self.conn, parsexml=xml)
|
||||
self._set_and_check(d, "target", "hda", "hdb")
|
||||
self.assertEqual(xml.replace("hda", "hdb"), d.get_xml_config())
|
||||
|
||||
|
@ -683,7 +692,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
def testAlterHostdevs(self):
|
||||
infile = "tests/xmlparse-xml/change-hostdevs-in.xml"
|
||||
outfile = "tests/xmlparse-xml/change-hostdevs-out.xml"
|
||||
guest = virtinst.Guest(conn,
|
||||
guest = virtinst.Guest(self.conn,
|
||||
parsexml=open(infile).read())
|
||||
|
||||
dev1 = guest.get_devices("hostdev")[0]
|
||||
|
@ -798,7 +807,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
def testAlterSounds(self):
|
||||
infile = "tests/xmlparse-xml/change-sounds-in.xml"
|
||||
outfile = "tests/xmlparse-xml/change-sounds-out.xml"
|
||||
guest = virtinst.Guest(conn,
|
||||
guest = virtinst.Guest(self.conn,
|
||||
parsexml=open(infile).read())
|
||||
|
||||
dev1 = guest.get_devices("sound")[0]
|
||||
|
@ -964,7 +973,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "change-xmlns-qemu"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
guest = virtinst.Guest(kvmconn, parsexml=open(infile).read())
|
||||
guest = virtinst.Guest(self.kvmconn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(guest.xmlns_qemu.args[0])
|
||||
check("value", "-somearg", "-somenewarg")
|
||||
|
@ -990,10 +999,10 @@ class XMLParseTest(unittest.TestCase):
|
|||
guest.remove_device(rmdev)
|
||||
|
||||
# Basic device add
|
||||
guest.add_device(virtinst.VirtualWatchdog(conn))
|
||||
guest.add_device(virtinst.VirtualWatchdog(self.conn))
|
||||
|
||||
# Test adding device with child properties (address value)
|
||||
adddev = virtinst.VirtualNetworkInterface(conn=conn)
|
||||
adddev = virtinst.VirtualNetworkInterface(self.conn)
|
||||
adddev.type = "network"
|
||||
adddev.source = "default"
|
||||
adddev.macaddr = "1A:2A:3A:4A:5A:6A"
|
||||
|
@ -1005,7 +1014,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
guest.add_device(adddev)
|
||||
|
||||
# Test adding device built from parsed XML
|
||||
guest.add_device(virtinst.VirtualAudio(conn,
|
||||
guest.add_device(virtinst.VirtualAudio(self.conn,
|
||||
parsexml="""<sound model='pcspk'/>"""))
|
||||
|
||||
self._alter_compare(guest.get_xml_config(), outfile)
|
||||
|
@ -1045,7 +1054,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "change-snapshot"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
snap = virtinst.DomainSnapshot(conn, parsexml=open(infile).read())
|
||||
snap = virtinst.DomainSnapshot(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(snap)
|
||||
check("name", "offline-root-child1", "name-foo")
|
||||
|
@ -1070,7 +1079,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "test-bridge-ip"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(conn, parsexml=open(infile).read())
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
self.assertEqual(len(iface.protocols), 2)
|
||||
self.assertEqual(len(iface.interfaces), 3)
|
||||
|
@ -1104,13 +1113,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
self.assertEqual(len(child_iface.interfaces), 2)
|
||||
|
||||
utils.diff_compare(iface.get_xml_config(), outfile)
|
||||
utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
utils.test_create(self.conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceBondArp(self):
|
||||
basename = "test-bond-arp"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(conn, parsexml=open(infile).read())
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("start_mode", "onboot", "hotplug")
|
||||
|
@ -1123,13 +1132,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("arp_validate_mode", "backup", "active")
|
||||
|
||||
utils.diff_compare(iface.get_xml_config(), outfile)
|
||||
utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
utils.test_create(self.conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceBondMii(self):
|
||||
basename = "test-bond-mii"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(conn, parsexml=open(infile).read())
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("mii_frequency", 123, 111)
|
||||
|
@ -1138,20 +1147,20 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("mii_carrier_mode", "netif", "ioctl")
|
||||
|
||||
utils.diff_compare(iface.get_xml_config(), outfile)
|
||||
utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
utils.test_create(self.conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
|
||||
def testInterfaceVLAN(self):
|
||||
basename = "test-vlan"
|
||||
infile = "tests/interface-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/interface-%s-out.xml" % basename
|
||||
iface = virtinst.Interface(conn, parsexml=open(infile).read())
|
||||
iface = virtinst.Interface(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(iface)
|
||||
check("tag", 123, 456)
|
||||
check("parent_interface", "eth2", "foonew")
|
||||
|
||||
utils.diff_compare(iface.get_xml_config(), outfile)
|
||||
utils.test_create(conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
utils.test_create(self.conn, iface.get_xml_config(), "interfaceDefineXML")
|
||||
|
||||
|
||||
#################
|
||||
|
@ -1162,7 +1171,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "pool-fs"
|
||||
infile = "tests/xmlparse-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
pool = virtinst.StoragePool(conn, parsexml=open(infile).read())
|
||||
pool = virtinst.StoragePool(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(pool)
|
||||
check("type", "fs", "dir")
|
||||
|
@ -1179,13 +1188,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("source_name", None, "fooname")
|
||||
|
||||
utils.diff_compare(pool.get_xml_config(), outfile)
|
||||
utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
utils.test_create(self.conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
|
||||
def testISCSIPool(self):
|
||||
basename = "pool-iscsi"
|
||||
infile = "tests/storage-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
pool = virtinst.StoragePool(conn, parsexml=open(infile).read())
|
||||
pool = virtinst.StoragePool(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(pool)
|
||||
check("iqn", "foo.bar.baz.iqn", "my.iqn")
|
||||
|
@ -1193,17 +1202,17 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("name", "some.random.hostname", "my.host")
|
||||
|
||||
utils.diff_compare(pool.get_xml_config(), outfile)
|
||||
utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
utils.test_create(self.conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
|
||||
def testGlusterPool(self):
|
||||
if not conn.check_support(conn.SUPPORT_CONN_POOL_GLUSTERFS):
|
||||
if not self.conn.check_support(self.conn.SUPPORT_CONN_POOL_GLUSTERFS):
|
||||
raise unittest.SkipTest("Gluster pools not supported with this "
|
||||
"libvirt version.")
|
||||
|
||||
basename = "pool-gluster"
|
||||
infile = "tests/storage-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
pool = virtinst.StoragePool(conn, parsexml=open(infile).read())
|
||||
pool = virtinst.StoragePool(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(pool)
|
||||
check("source_path", "/some/source/path", "/foo")
|
||||
|
@ -1211,13 +1220,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("name", "some.random.hostname", "my.host")
|
||||
|
||||
utils.diff_compare(pool.get_xml_config(), outfile)
|
||||
utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
utils.test_create(self.conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
|
||||
def testRBDPool(self):
|
||||
basename = "pool-rbd"
|
||||
infile = "tests/xmlparse-xml/%s.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
pool = virtinst.StoragePool(conn, parsexml=open(infile).read())
|
||||
pool = virtinst.StoragePool(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(pool.hosts[0])
|
||||
check("name", "ceph-mon-1.example.com")
|
||||
|
@ -1233,13 +1242,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
hostobj.port = "5555"
|
||||
|
||||
utils.diff_compare(pool.get_xml_config(), outfile)
|
||||
utils.test_create(conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
utils.test_create(self.conn, pool.get_xml_config(), "storagePoolDefineXML")
|
||||
|
||||
def testVol(self):
|
||||
basename = "pool-dir-vol"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
vol = virtinst.StorageVolume(conn, parsexml=open(infile).read())
|
||||
vol = virtinst.StorageVolume(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(vol)
|
||||
check("type", None, "file")
|
||||
|
@ -1268,7 +1277,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "network-multi"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
net = virtinst.Network(conn, parsexml=open(infile).read())
|
||||
net = virtinst.Network(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(net)
|
||||
check("name", "ipv6_multirange", "new-foo")
|
||||
|
@ -1330,13 +1339,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("netmask", None, "foo", None)
|
||||
|
||||
utils.diff_compare(net.get_xml_config(), outfile)
|
||||
utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
|
||||
utils.test_create(self.conn, net.get_xml_config(), "networkDefineXML")
|
||||
|
||||
def testNetOpen(self):
|
||||
basename = "network-open"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
net = virtinst.Network(conn, parsexml=open(infile).read())
|
||||
net = virtinst.Network(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(net)
|
||||
check("name", "open", "new-foo")
|
||||
|
@ -1356,13 +1365,13 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("end", "192.168.100.254", "192.168.101.254")
|
||||
|
||||
utils.diff_compare(net.get_xml_config(), outfile)
|
||||
utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
|
||||
utils.test_create(self.conn, net.get_xml_config(), "networkDefineXML")
|
||||
|
||||
def testNetVfPool(self):
|
||||
basename = "network-vf-pool"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
net = virtinst.Network(conn, parsexml=open(infile).read())
|
||||
net = virtinst.Network(self.conn, parsexml=open(infile).read())
|
||||
|
||||
check = self._make_checker(net)
|
||||
check("name", "passthrough", "new-foo")
|
||||
|
@ -1382,7 +1391,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
check("function", 0x0)
|
||||
|
||||
utils.diff_compare(net.get_xml_config(), outfile)
|
||||
utils.test_create(conn, net.get_xml_config(), "networkDefineXML")
|
||||
utils.test_create(self.conn, net.get_xml_config(), "networkDefineXML")
|
||||
|
||||
|
||||
##############
|
||||
|
@ -1394,7 +1403,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
basename = "clear-cpu-unknown-vals"
|
||||
infile = "tests/xmlparse-xml/%s-in.xml" % basename
|
||||
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
|
||||
guest = virtinst.Guest(kvmconn, parsexml=open(infile).read())
|
||||
guest = virtinst.Guest(self.kvmconn, parsexml=open(infile).read())
|
||||
|
||||
guest.cpu.copy_host_cpu()
|
||||
guest.cpu.clear()
|
||||
|
@ -1404,7 +1413,7 @@ class XMLParseTest(unittest.TestCase):
|
|||
# Make sure our XML engine doesn't mangle non-libvirt XML bits
|
||||
infile = "tests/xmlparse-xml/domain-roundtrip.xml"
|
||||
outfile = "tests/xmlparse-xml/domain-roundtrip.xml"
|
||||
guest = virtinst.Guest(conn, parsexml=open(infile).read())
|
||||
guest = virtinst.Guest(self.conn, parsexml=open(infile).read())
|
||||
|
||||
utils.diff_compare(guest.get_xml_config(), outfile)
|
||||
|
||||
|
|
Loading…
Reference in New Issue