Subject: tests: Add unit test coverage for #539 From: Cole Robinson crobinso@redhat.com Tue Aug 29 12:27:40 2023 -0400 Date: Tue Aug 29 12:27:40 2023 -0400: Git: 19b0f3f446ff8fc3b98c676726ee3a42b0b00b74 Signed-off-by: Cole Robinson diff --git a/tests/data/xmlparse/emulator-custom.xml b/tests/data/xmlparse/emulator-custom.xml new file mode 100644 index 00000000..d39ce024 --- /dev/null +++ b/tests/data/xmlparse/emulator-custom.xml @@ -0,0 +1,22 @@ + + manual-emulator-test + + + + + + 8388608 + 8388608 + 8 + + hvm + + + destroy + restart + destroy + + /my/manual/emulator + + + diff --git a/tests/test_xmlparse.py b/tests/test_xmlparse.py index 1bf0ebe5..781680cf 100644 --- a/tests/test_xmlparse.py +++ b/tests/test_xmlparse.py @@ -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