tests: Rename test_xmlconfig.py to test_misc.py

That's what it is now, just a collection of misc virtinst tests

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-18 16:06:39 -04:00
parent 4c4753d910
commit b79ee9565f
5 changed files with 134 additions and 162 deletions

View File

@ -365,6 +365,11 @@
<address type="ccw" cssid="0xfe" ssid="0" devno="01"/> <address type="ccw" cssid="0xfe" ssid="0" devno="01"/>
<boot order="15" loadparm="SYSTEM1"/> <boot order="15" loadparm="SYSTEM1"/>
</interface> </interface>
<interface type="bridge">
<source bridge="testsuitebr0"/>
<mac address="00:11:22:33:44:55"/>
<model type="vmxnet3"/>
</interface>
<smartcard mode="passthrough" type="spicevmc"/> <smartcard mode="passthrough" type="spicevmc"/>
<smartcard mode="host" type="tcp"/> <smartcard mode="host" type="tcp"/>
<smartcard mode="passthrough" type="spicevmc"/> <smartcard mode="passthrough" type="spicevmc"/>

View File

@ -629,6 +629,7 @@ source.reservations.managed=no,source.reservations.source.type=unix,source.reser
--network user,model=virtio,address.type=spapr-vio,address.reg=0x500,link.state=no --network user,model=virtio,address.type=spapr-vio,address.reg=0x500,link.state=no
--network vhostuser,source_type=unix,source_path=/tmp/vhost1.sock,source_mode=server,model=virtio,source.type=unix,source.path=/tmp/vhost1.sock,address.type=pci,address.bus=0x00,address.slot=0x10,address.function=0x0,address.domain=0x0000 --network vhostuser,source_type=unix,source_path=/tmp/vhost1.sock,source_mode=server,model=virtio,source.type=unix,source.path=/tmp/vhost1.sock,address.type=pci,address.bus=0x00,address.slot=0x10,address.function=0x0,address.domain=0x0000
--network user,address.type=ccw,address.cssid=0xfe,address.ssid=0,address.devno=01,boot.order=15,boot.loadparm=SYSTEM1 --network user,address.type=ccw,address.cssid=0xfe,address.ssid=0,address.devno=01,boot.order=15,boot.loadparm=SYSTEM1
--network model=vmxnet3
--graphics sdl --graphics sdl
--graphics spice,keymap=none --graphics spice,keymap=none

126
tests/test_misc.py Normal file
View File

@ -0,0 +1,126 @@
# Copyright (C) 2013, 2014 Red Hat, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import virtinst
from tests import utils
# Misc tests for various virtinst special behavior. These should only aim for
# testing any particularly tricky bits, general XML generation should
# be through virt-install examples in test_cli
def test_misc_cpu_topology():
"""
Various topology calculation corner cases
"""
conn = utils.URIs.open_testdefault_cached()
cpu = virtinst.DomainCpu(conn)
cpu.set_topology_defaults(6)
assert cpu.topology.sockets is None
cpu.topology.sockets = "2"
cpu.set_topology_defaults(6)
def get_top(_c):
return [_c.topology.sockets, _c.topology.cores, _c.topology.threads]
assert get_top(cpu) == [2, 3, 1]
cpu = virtinst.DomainCpu(conn)
cpu.topology.cores = "4"
cpu.set_topology_defaults(9)
assert get_top(cpu) == [2, 4, 1]
cpu = virtinst.DomainCpu(conn)
cpu.topology.threads = "3"
cpu.set_topology_defaults(14)
assert get_top(cpu) == [4, 1, 3]
cpu = virtinst.DomainCpu(conn)
cpu.topology.sockets = 5
cpu.topology.cores = 2
assert cpu.vcpus_from_topology() == 10
cpu = virtinst.DomainCpu(conn)
assert cpu.vcpus_from_topology() == 1
def test_misc_guest_osinfo_metadata():
"""
Test that reading an unknown OS ID from guest XML will not blow up
"""
# pylint: disable=protected-access
g = virtinst.Guest(utils.URIs.open_testdefault_cached())
g._metadata.libosinfo.os_id = "http://fedoraproject.org/fedora/20"
assert g.osinfo.name == "fedora20"
g = virtinst.Guest(utils.URIs.open_testdefault_cached())
g._metadata.libosinfo.os_id = "http://example.com/idontexit"
assert g.osinfo.name == "generic"
def test_misc_nonpredicatble_generate():
"""
Bypass our testsuite 'predicatable' handling to test actual random output
"""
from virtinst import cli
predconn = utils.URIs.open_testdefault_cached()
kvm_uri = utils.URIs.kvm.replace(",predictable", "")
kvmconn = cli.getConnection(kvm_uri)
testconn = cli.getConnection("test:///default")
testuuid = virtinst.Guest.generate_uuid(predconn)
randomuuid = virtinst.Guest.generate_uuid(testconn)
assert randomuuid != testuuid
assert len(randomuuid) == len(testuuid)
testmac = virtinst.DeviceInterface.generate_mac(predconn)
randommac = virtinst.DeviceInterface.generate_mac(testconn)
qemumac = virtinst.DeviceInterface.generate_mac(kvmconn)
assert randommac != testmac
assert qemumac != testmac
assert len(randommac) == len(testmac)
# Ensure check_mac_in_use doesn't error on None
virtinst.DeviceInterface.check_mac_in_use(predconn, None)
def test_misc_support_cornercases():
"""
Test support.py corner cases
"""
conn = utils.URIs.open_testdefault_cached()
try:
conn.lookupByName("foobar-idontexist")
except Exception as e:
if not conn.support.is_libvirt_error_no_domain(e):
raise
def test_misc_osxml_cornercases():
"""
Test OSXML corner cases
"""
conn = utils.URIs.open_testdefault_cached()
guest = virtinst.Guest(conn)
guest.os.set_initargs_string("foo bar")
guest.os.set_initargs_string("baz wibble")
assert [i.val for i in guest.os.initargs] == ["baz", "wibble"]
def test_misc_cpu_cornercases():
"""
Hit the validation paths for default HOST_MODEL_ONLY
"""
kvmconn = utils.URIs.open_kvm()
guest = virtinst.Guest(kvmconn)
guest.x86_cpu_default = guest.cpu.SPECIAL_MODE_HOST_MODEL_ONLY
guest.set_defaults(guest)
assert guest.cpu.model == "Opteron_G4"
# pylint: disable=protected-access
guest.cpu.model = "idontexist"
guest.cpu._validate_default_host_model_only(guest)
assert guest.cpu.model is None

View File

@ -1,141 +0,0 @@
# Copyright (C) 2013, 2014 Red Hat, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import os
import unittest
import virtinst
from tests import utils
def _make_guest(conn=None, os_variant=None):
if not conn:
conn = utils.URIs.open_testdriver_cached()
g = virtinst.Guest(conn)
g.name = "TestGuest"
g.currentMemory = int(200 * 1024)
g.memory = int(400 * 1024)
if os_variant:
g.set_os_name(os_variant)
# File disk
d = virtinst.DeviceDisk(conn)
d.path = "/dev/default-pool/new-test-suite.img"
if d.wants_storage_creation():
parent_pool = d.get_parent_pool()
vol_install = virtinst.DeviceDisk.build_vol_install(conn,
os.path.basename(d.path), parent_pool, .0000001, True)
d.set_vol_install(vol_install)
d.validate()
g.add_device(d)
# Block disk
d = virtinst.DeviceDisk(conn)
d.path = "/dev/disk-pool/diskvol1"
d.validate()
g.add_device(d)
# Network device
dev = virtinst.DeviceInterface(conn)
g.add_device(dev)
return g
class TestXMLMisc(unittest.TestCase):
"""
Misc tests for various XML special behavior. These should only aim for
testing any particularly tricky bits, general XML generation should
be through virt-install examples in test_cli
"""
@property
def conn(self):
return utils.URIs.open_testdefault_cached()
def testCPUTopology(self):
# Test CPU topology determining
cpu = virtinst.DomainCpu(self.conn)
cpu.set_topology_defaults(6)
assert cpu.topology.sockets is None
cpu.topology.sockets = "2"
cpu.set_topology_defaults(6)
def get_top(_c):
return [_c.topology.sockets, _c.topology.cores, _c.topology.threads]
assert get_top(cpu) == [2, 3, 1]
cpu = virtinst.DomainCpu(self.conn)
cpu.topology.cores = "4"
cpu.set_topology_defaults(9)
assert get_top(cpu) == [2, 4, 1]
cpu = virtinst.DomainCpu(self.conn)
cpu.topology.threads = "3"
cpu.set_topology_defaults(14)
assert get_top(cpu) == [4, 1, 3]
cpu = virtinst.DomainCpu(self.conn)
cpu.topology.sockets = 5
cpu.topology.cores = 2
assert cpu.vcpus_from_topology() == 10
cpu = virtinst.DomainCpu(self.conn)
assert cpu.vcpus_from_topology() == 1
def test_set_defaults_double(self):
"""
Check that a common config has idempotent set_defaults
"""
g = _make_guest(conn=utils.URIs.open_kvm(), os_variant="fedora-unknown")
g.set_defaults(None)
xml1 = g.get_xml()
g.set_defaults(None)
xml2 = g.get_xml()
assert xml1 == xml2
def test_guest_osinfo_metadata(self):
"""
Test that reading an unknown OS ID from guest XML will not blow up
"""
# pylint: disable=protected-access
g = virtinst.Guest(utils.URIs.open_testdefault_cached())
g._metadata.libosinfo.os_id = "http://fedoraproject.org/fedora/20"
assert g.osinfo.name == "fedora20"
g = virtinst.Guest(utils.URIs.open_testdefault_cached())
g._metadata.libosinfo.os_id = "http://example.com/idontexit"
assert g.osinfo.name == "generic"
def test_nonpredicatble_generate(self):
from virtinst import cli
kvm_uri = utils.URIs.kvm.replace(",predictable", "")
kvmconn = cli.getConnection(kvm_uri)
testconn = cli.getConnection("test:///default")
testuuid = virtinst.Guest.generate_uuid(self.conn)
randomuuid = virtinst.Guest.generate_uuid(testconn)
assert randomuuid != testuuid
assert len(randomuuid) == len(testuuid)
testmac = virtinst.DeviceInterface.generate_mac(self.conn)
randommac = virtinst.DeviceInterface.generate_mac(testconn)
qemumac = virtinst.DeviceInterface.generate_mac(kvmconn)
assert randommac != testmac
assert qemumac != testmac
assert len(randommac) == len(testmac)
# Ensure check_mac_in_use doesn't error on None
virtinst.DeviceInterface.check_mac_in_use(self.conn, None)
def test_support_misc(self):
try:
self.conn.lookupByName("foobar-idontexist")
except Exception as e:
if not self.conn.support.is_libvirt_error_no_domain(e):
raise

View File

@ -287,7 +287,8 @@ class XMLParseTest(unittest.TestCase):
self._alter_compare(guest.get_xml(), outfile) self._alter_compare(guest.get_xml(), outfile)
# Hits a codepath when domcaps don't provide the needed info # Hits a codepath when domcaps don't provide the needed info
guest = virtinst.Guest(self.conn, xml) emptyconn = utils.URIs.open_testdefault_cached()
guest = virtinst.Guest(emptyconn, xml)
guest.cpu.check_security_features(guest) guest.cpu.check_security_features(guest)
assert guest.cpu.secure is False assert guest.cpu.secure is False
@ -1138,23 +1139,3 @@ class XMLParseTest(unittest.TestCase):
# Little test for DeviceAddress.pretty_desc # Little test for DeviceAddress.pretty_desc
assert devs[-1].address.pretty_desc() == "0:0:0:3" assert devs[-1].address.pretty_desc() == "0:0:0:3"
def testCPUHostModelOnly(self):
"""
Hit the validation paths for default HOST_MODEL_ONLY
"""
guest = virtinst.Guest(self.kvmconn)
guest.x86_cpu_default = guest.cpu.SPECIAL_MODE_HOST_MODEL_ONLY
guest.set_defaults(guest)
assert guest.cpu.model == "Opteron_G4"
# pylint: disable=protected-access
guest.cpu.model = "idontexist"
guest.cpu._validate_default_host_model_only(guest)
assert guest.cpu.model is None
def testOSXMLInitargsRemove(self):
guest = virtinst.Guest(self.conn)
guest.os.set_initargs_string("foo bar")
guest.os.set_initargs_string("baz wibble")
assert [i.val for i in guest.os.initargs] == ["baz", "wibble"]