From 220390ebd48b33d1d1fae747dc41f1aedd7646e0 Mon Sep 17 00:00:00 2001 Message-Id: <220390ebd48b33d1d1fae747dc41f1aedd7646e0@dist-git> From: Pavel Hrdina Date: Wed, 15 May 2019 10:37:47 +0200 Subject: [PATCH] domain: cpu: introduce set_model function We will need to pass another variable into the setter so we cannot use the property setter. Signed-off-by: Pavel Hrdina Reviewed-by: Cole Robinson (cherry picked from commit 6423f653fd2d895d5addf37a6d504dbc9a4a0d6f) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1716402 Signed-off-by: Pavel Hrdina --- 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 709bc48f..61552720 100644 --- a/tests/xmlparse.py +++ b/tests/xmlparse.py @@ -176,7 +176,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) @@ -267,7 +268,9 @@ class XMLParseTest(unittest.TestCase): guest.seclabels[0].get_xml().startswith(" 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 @@ -103,13 +103,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 @@ -139,7 +147,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 @@ -201,17 +209,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") @@ -273,7 +271,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.21.0