2014-03-12 19:36:17 +08:00
|
|
|
# Copyright (C) 2013, 2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-08-09 08:47:17 +08:00
|
|
|
import os
|
2013-03-18 05:06:52 +08:00
|
|
|
import unittest
|
2013-08-09 08:47:17 +08:00
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
from tests import utils
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
from virtinst import Capabilities
|
|
|
|
from virtinst import DomainCapabilities
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2020-01-27 07:11:43 +08:00
|
|
|
DATADIR = "tests/data/capabilities"
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
class TestCapabilities(unittest.TestCase):
|
2015-04-04 00:40:16 +08:00
|
|
|
def _buildCaps(self, filename):
|
2020-01-27 07:11:43 +08:00
|
|
|
path = os.path.join(DATADIR, filename)
|
2018-02-23 03:57:10 +08:00
|
|
|
conn = utils.URIs.open_testdefault_cached()
|
2017-05-06 02:19:54 +08:00
|
|
|
return Capabilities(conn, open(path).read())
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testCapsCPUFeaturesNewSyntax(self):
|
2015-04-23 05:06:35 +08:00
|
|
|
filename = "test-qemu-with-kvm.xml"
|
2013-03-18 05:06:52 +08:00
|
|
|
host_feature_list = ['lahf_lm', 'xtpr', 'cx16', 'tm2', 'est', 'vmx',
|
2015-04-04 00:40:16 +08:00
|
|
|
'ds_cpl', 'pbe', 'tm', 'ht', 'ss', 'acpi', 'ds']
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
caps = self._buildCaps(filename)
|
2015-04-04 00:40:16 +08:00
|
|
|
for f in host_feature_list:
|
2018-06-12 23:17:33 +08:00
|
|
|
self.assertEqual(
|
|
|
|
f in [feat.name for feat in caps.host.cpu.features], True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2017-05-05 23:39:59 +08:00
|
|
|
self.assertEqual(caps.host.cpu.model, "core2duo")
|
|
|
|
self.assertEqual(caps.host.cpu.vendor, "Intel")
|
|
|
|
self.assertEqual(caps.host.cpu.threads, 3)
|
|
|
|
self.assertEqual(caps.host.cpu.cores, 5)
|
|
|
|
self.assertEqual(caps.host.cpu.sockets, 7)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testCapsUtilFuncs(self):
|
2015-04-23 05:06:35 +08:00
|
|
|
caps_with_kvm = self._buildCaps("test-qemu-with-kvm.xml")
|
|
|
|
caps_no_kvm = self._buildCaps("test-qemu-no-kvm.xml")
|
2018-06-12 23:17:33 +08:00
|
|
|
caps_empty = self._buildCaps("test-empty.xml")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 04:42:07 +08:00
|
|
|
def test_utils(caps, has_guests, is_kvm):
|
2015-07-10 18:06:48 +08:00
|
|
|
if caps.guests:
|
2017-05-05 23:39:59 +08:00
|
|
|
self.assertEqual(caps.guests[0].has_install_options(), has_guests)
|
|
|
|
self.assertEqual(caps.guests[0].is_kvm_available(), is_kvm)
|
2015-04-04 04:39:47 +08:00
|
|
|
|
2015-04-23 05:06:35 +08:00
|
|
|
test_utils(caps_empty, False, False)
|
|
|
|
test_utils(caps_with_kvm, True, True)
|
|
|
|
test_utils(caps_no_kvm, True, False)
|
|
|
|
|
2019-06-11 02:15:50 +08:00
|
|
|
# Small test for extra unittest coverage
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
caps_empty.guest_lookup(os_type="linux")
|
|
|
|
|
2015-11-19 03:53:12 +08:00
|
|
|
def testCapsNuma(self):
|
|
|
|
cells = self._buildCaps("lxc.xml").host.topology.cells
|
2017-05-05 23:39:59 +08:00
|
|
|
self.assertEqual(len(cells), 1)
|
|
|
|
self.assertEqual(len(cells[0].cpus), 8)
|
|
|
|
self.assertEqual(cells[0].cpus[3].id, '3')
|
2015-11-19 03:53:12 +08:00
|
|
|
|
2015-04-23 05:06:35 +08:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# domcapabilities.py testing #
|
|
|
|
##############################
|
|
|
|
|
2014-09-18 02:56:52 +08:00
|
|
|
def testDomainCapabilities(self):
|
2020-01-27 07:11:43 +08:00
|
|
|
xml = open(DATADIR + "/test-domcaps.xml").read()
|
2018-02-23 03:57:10 +08:00
|
|
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
2014-09-18 02:56:52 +08:00
|
|
|
|
|
|
|
self.assertEqual(caps.os.loader.supported, True)
|
2017-05-05 23:39:59 +08:00
|
|
|
self.assertEqual(caps.os.loader.get_values(),
|
2014-09-18 02:56:52 +08:00
|
|
|
["/foo/bar", "/tmp/my_path"])
|
2017-05-05 23:39:59 +08:00
|
|
|
self.assertEqual(caps.os.loader.enum_names(), ["type", "readonly"])
|
|
|
|
self.assertEqual(caps.os.loader.get_enum("type").get_values(),
|
2014-09-18 02:56:52 +08:00
|
|
|
["rom", "pflash"])
|
|
|
|
|
2018-03-29 03:45:29 +08:00
|
|
|
def testDomainCapabilitiesx86(self):
|
2020-01-27 07:11:43 +08:00
|
|
|
xml = open(DATADIR + "/kvm-x86_64-domcaps.xml").read()
|
2018-03-29 03:45:29 +08:00
|
|
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
|
|
|
|
2018-10-05 00:22:22 +08:00
|
|
|
self.assertEqual(caps.machine, "pc-i440fx-2.1")
|
|
|
|
self.assertEqual(caps.arch, "x86_64")
|
|
|
|
self.assertEqual(caps.domain, "kvm")
|
|
|
|
self.assertEqual(caps.path, "/bin/qemu-system-x86_64")
|
|
|
|
|
2018-03-29 03:45:29 +08:00
|
|
|
custom_mode = caps.cpu.get_mode("custom")
|
|
|
|
self.assertTrue(bool(custom_mode))
|
|
|
|
cpu_model = custom_mode.get_model("Opteron_G4")
|
|
|
|
self.assertTrue(bool(cpu_model))
|
|
|
|
self.assertTrue(cpu_model.usable)
|
2020-01-27 23:06:18 +08:00
|
|
|
|
|
|
|
models = caps.get_cpu_models()
|
|
|
|
assert len(models) > 10
|
|
|
|
assert "SandyBridge" in models
|
|
|
|
|
|
|
|
assert caps.label_for_firmware_path(None) == "BIOS"
|
|
|
|
assert "Custom:" in caps.label_for_firmware_path("/foobar")
|
|
|
|
assert "UEFI" in caps.label_for_firmware_path("OVMF")
|
|
|
|
|
|
|
|
def testDomainCapabilitiesAArch64(self):
|
|
|
|
xml = open(DATADIR + "/kvm-aarch64-domcaps.xml").read()
|
|
|
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
|
|
|
|
|
|
|
assert "None" in caps.label_for_firmware_path(None)
|