tests: Add unit test coverage for #539

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2023-08-29 12:27:40 -04:00
parent 6e5c1db6b4
commit 19b0f3f446
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<domain type='kvm'>
<name>manual-emulator-test</name>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/unknown"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>8</vcpu>
<os>
<type arch='mips' machine='some-unknown-machine'>hvm</type>
<boot dev='hd'/>
</os>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/my/manual/emulator</emulator>
</devices>
</domain>

View File

@ -1170,3 +1170,34 @@ def testDiskSourceAbspath():
# ...unless it's a URL
disk.set_source_path("http://example.com/foobar3")
assert disk.get_source_path() == "http://example.com/foobar3"
def testUnknownEmulatorDomcapsLookup(monkeypatch):
"""
Libvirt can handle defining a VM with a custom emulator, one not detected
by `virsh capabilities`. An appropriate `virsh domcapabilities` call will
inspect the emulator and return relevant info.
This test ensures that for parsing XML the `virsh capabilities` failure
isn't fatal, and we attempt to return valid `virsh domcapabilities` data
"""
seen = False
def fake_build_from_params(conn, emulator, arch, machine, hvtype):
nonlocal seen
seen = True
assert arch == "mips"
assert machine == "some-unknown-machine"
assert emulator == "/my/manual/emulator"
return virtinst.DomainCapabilities(conn)
monkeypatch.setattr(
"virtinst.DomainCapabilities.build_from_params",
fake_build_from_params)
conn = utils.URIs.open_kvm()
xml = open(DATADIR + "emulator-custom.xml").read()
guest = virtinst.Guest(conn, xml)
assert guest.lookup_domcaps()
assert guest.lookup_domcaps()
assert seen