From bcc04993fe8fbeb374cacf990105270579a530c2 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 13 Jun 2012 16:34:06 +0100 Subject: Refactor libvirt config classes for representing CPU models/features The previously added (but not used) LibvirtConfigCPUTest class was too inflexible. It did not distinguish between parts of the XML schema which applied to both capabilities & domain XML, vs those which only applied to the domain XML. By representing features as a plain string it did not allow for setting attributes on feature flags like policy. This change replaces the single LibvirtConfigCPUTest class with 4 new classes: - LibvirtConfigCPUFeature - base class for defining CPU features - LibvirtConfigCPU - base class for defining CPU models - LibvirtConfigGuestCPUFeature - extension for setting the guest specific feature policy - LibvirtConfigGuestCPU - extension for setting the guest specific match policy, and allowing use of host CPU model passthrough Fixes: bug #1003373 Implements: blueprint libvirt-xml-cpu-model Change-Id: I0aa0ddfb86cf8b89b2e4dcc95e21bdca304bd6b3 Signed-off-by: Daniel P. Berrange --- nova/tests/test_libvirt_config.py | 154 +++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 37 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index 4f9970e79..59ed88e1c 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -151,6 +151,123 @@ class LibvirtConfigGuestClockTest(LibvirtConfigBaseTest): """) +class LibvirtConfigCPUFeatureTest(LibvirtConfigBaseTest): + + def test_config_simple(self): + obj = config.LibvirtConfigCPUFeature("mtrr") + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + """) + + +class LibvirtConfigGuestCPUFeatureTest(LibvirtConfigBaseTest): + + def test_config_simple(self): + obj = config.LibvirtConfigGuestCPUFeature("mtrr") + obj.policy = "force" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + """) + + +class LibvirtConfigCPUTest(LibvirtConfigBaseTest): + + def test_config_simple(self): + obj = config.LibvirtConfigCPU() + obj.model = "Penryn" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + Penryn + + """) + + def test_config_complex(self): + obj = config.LibvirtConfigCPU() + obj.model = "Penryn" + obj.vendor = "Intel" + obj.arch = "x86_64" + + obj.add_feature(config.LibvirtConfigCPUFeature("mtrr")) + obj.add_feature(config.LibvirtConfigCPUFeature("apic")) + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + x86_64 + Penryn + Intel + + + + """) + + def test_config_topology(self): + obj = config.LibvirtConfigCPU() + obj.model = "Penryn" + obj.sockets = 4 + obj.cores = 4 + obj.threads = 2 + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + Penryn + + + """) + + +class LibvirtConfigGuestCPUTest(LibvirtConfigBaseTest): + + def test_config_simple(self): + obj = config.LibvirtConfigGuestCPU() + obj.model = "Penryn" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + Penryn + + """) + + def test_config_complex(self): + obj = config.LibvirtConfigGuestCPU() + obj.model = "Penryn" + obj.vendor = "Intel" + obj.arch = "x86_64" + obj.mode = "custom" + + obj.add_feature(config.LibvirtConfigGuestCPUFeature("mtrr")) + obj.add_feature(config.LibvirtConfigGuestCPUFeature("apic")) + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + x86_64 + Penryn + Intel + + + + """) + + def test_config_host(self): + obj = config.LibvirtConfigGuestCPU() + obj.mode = "host-model" + obj.match = "exact" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + """) + + class LibvirtConfigGuestDiskTest(LibvirtConfigBaseTest): def test_config_file(self): @@ -485,43 +602,6 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest): """) -class LibvirtConfigCPUTest(LibvirtConfigBaseTest): - - def test_config_cpu(self): - obj = config.LibvirtConfigCPU() - obj.vendor = "AMD" - obj.model = "Quad-Core AMD Opteron(tm) Processor 2350" - obj.arch = "x86_64" - obj.add_feature("svm") - obj.add_feature("extapic") - obj.add_feature("constant_tsc") - - xml = obj.to_xml() - self.assertXmlEqual(xml, """ - - x86_64 - Quad-Core AMD Opteron(tm) Processor 2350 - AMD - - - - """) - - def test_config_topology(self): - obj = config.LibvirtConfigCPU() - obj.vendor = "AMD" - obj.sockets = 2 - obj.cores = 4 - obj.threads = 2 - - xml = obj.to_xml() - self.assertXmlEqual(xml, """ - - AMD - - """) - - class LibvirtConfigGuestSnapshotTest(LibvirtConfigBaseTest): def test_config_snapshot(self): -- cgit