[virt-tools-list] [virt-manager PATCH 7/8] domain: cpu: introduce set_model function

Pavel Hrdina phrdina at redhat.com
Fri Mar 15 16:41:41 UTC 2019


We will need to pass another variable into the setter so we cannot use
the property setter.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 tests/xmlparse.py      | 11 +++++++----
 virtManager/domain.py  |  2 +-
 virtinst/cli.py        |  2 +-
 virtinst/domain/cpu.py | 28 +++++++++++++---------------
 4 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 5a9de54e..dd2dbb8a 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -184,7 +184,8 @@ class XMLParseTest(unittest.TestCase):
 
         check = self._make_checker(guest.cpu)
         check("match", "exact", "strict")
-        check("model", "footest", "qemu64")
+        guest.cpu.set_model("qemu64")
+        check("model", "qemu64")
         check("vendor", "Intel", "qemuvendor")
         check("threads", 2, 1)
         check("cores", 5, 3)
@@ -275,7 +276,9 @@ class XMLParseTest(unittest.TestCase):
             guest.seclabels[0].get_xml().startswith("<seclabel"))
 
         check = self._make_checker(guest.cpu)
-        check("model", None, "foobar")
+        check("model", None)
+        guest.cpu.set_model("foobar")
+        check("model", "foobar")
         check("model_fallback", None, "allow")
         check("cores", None, 4)
         guest.cpu.add_feature("x2apic", "forbid")
@@ -341,8 +344,8 @@ class XMLParseTest(unittest.TestCase):
         check("mode", "host-passthrough")
         guest.cpu.set_special_mode(guest, "host-model")
         check("mode", "host-model")
-        # mode will be "custom"
-        check("model", None, "qemu64")
+        guest.cpu.set_model("qemu64")
+        check("model", "qemu64")
 
         self._alter_compare(guest.get_xml(), outfile)
 
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 98875fbf..7e4e6d6b 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -460,7 +460,7 @@ class vmmDomain(vmmLibvirtObject):
             if model in guest.cpu.SPECIAL_MODES:
                 guest.cpu.set_special_mode(guest, model)
             else:
-                guest.cpu.model = model
+                guest.cpu.set_model(model)
         self._redefine_xmlobj(guest)
 
     def define_memory(self, memory=_SENTINEL, maxmem=_SENTINEL):
diff --git a/virtinst/cli.py b/virtinst/cli.py
index dce0a72c..a25e5c84 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1734,7 +1734,7 @@ class ParserCPU(VirtCLIParser):
         if val in inst.SPECIAL_MODES:
             inst.set_special_mode(self.guest, val)
         else:
-            inst.model = val
+            inst.set_model(val)
 
     def set_feature_cb(self, inst, val, virtarg):
         policy = virtarg.cliname
diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py
index 8cf85a43..207fa35e 100644
--- a/virtinst/domain/cpu.py
+++ b/virtinst/domain/cpu.py
@@ -61,7 +61,7 @@ class DomainCpu(XMLBuilder):
     Class for generating <cpu> XML
     """
     XML_NAME = "cpu"
-    _XML_PROP_ORDER = ["mode", "match", "_model", "vendor",
+    _XML_PROP_ORDER = ["mode", "match", "model", "vendor",
                        "sockets", "cores", "threads", "features"]
 
     special_mode_was_set = False
@@ -102,13 +102,21 @@ class DomainCpu(XMLBuilder):
         elif val == self.SPECIAL_MODE_HOST_MODEL_ONLY:
             if self.conn.caps.host.cpu.model:
                 self.clear()
-                self.model = self.conn.caps.host.cpu.model
+                self.set_model(self.conn.caps.host.cpu.model)
         else:
             raise RuntimeError("programming error: unknown "
                 "special cpu mode '%s'" % val)
 
         self.special_mode_was_set = True
 
+    def set_model(self, val):
+        logging.debug("setting cpu model %s", val)
+        if val:
+            self.mode = "custom"
+            if not self.match:
+                self.match = "exact"
+        self.model = val
+
     def add_feature(self, name, policy="require"):
         feature = self.features.add_new()
         feature.name = name
@@ -138,7 +146,7 @@ class DomainCpu(XMLBuilder):
 
         self.mode = "custom"
         self.match = "exact"
-        self.model = model
+        self.set_model(model)
         if fallback:
             self.model_fallback = fallback
         self.vendor = cpu.vendor
@@ -200,17 +208,7 @@ class DomainCpu(XMLBuilder):
     # XML properties #
     ##################
 
-    def _set_model(self, val):
-        if val:
-            self.mode = "custom"
-            if not self.match:
-                self.match = "exact"
-        self._model = val
-    def _get_model(self):
-        return self._model
-    _model = XMLProperty("./model")
-    model = property(_get_model, _set_model)
-
+    model = XMLProperty("./model")
     model_fallback = XMLProperty("./model/@fallback")
 
     match = XMLProperty("./@match")
@@ -272,7 +270,7 @@ class DomainCpu(XMLBuilder):
 
         elif guest.os.is_arm64() and guest.os.is_arm_machvirt():
             # -M virt defaults to a 32bit CPU, even if using aarch64
-            self.model = "cortex-a57"
+            self.set_model("cortex-a57")
 
         elif guest.os.is_x86() and guest.type == "kvm":
             self._set_cpu_x86_kvm_default(guest)
-- 
2.20.1




More information about the virt-tools-list mailing list