capabilities: Fix model list caching for different archs (bz 1451113)

We could return cached x86_64 results for aarch64 VMs

https://bugzilla.redhat.com/show_bug.cgi?id=1451113
This commit is contained in:
Cole Robinson 2017-07-17 11:29:54 -04:00
parent 2eaf084b04
commit ca56f74ed7
3 changed files with 18 additions and 40 deletions

View File

@ -92,7 +92,7 @@ class TestCapabilities(unittest.TestCase):
caps = self._buildCaps("test-qemu-with-kvm.xml")
cpu_64 = caps.get_cpu_values("x86_64")
cpu_32 = caps.get_cpu_values("i486")
cpu_32 = caps.get_cpu_values("i686")
cpu_random = caps.get_cpu_values("mips")
def test_cpu_map(cpumap, cpus):

View File

@ -972,12 +972,6 @@ class vmmDetails(vmmGObjectUI):
txtCol.add_attribute(text, 'text', BOOT_LABEL)
txtCol.add_attribute(text, 'sensitive', BOOT_ACTIVE)
try:
cpu_names = caps.get_cpu_values(self.vm.get_arch())
except:
cpu_names = []
logging.exception("Error populating CPU model list")
# CPU model combo
cpu_model = self.widget("cpu-model")
@ -996,7 +990,7 @@ class vmmDetails(vmmGObjectUI):
model.append([_("Clear CPU configuration"), "3",
virtinst.CPU.SPECIAL_MODE_CLEAR, False])
model.append([None, None, None, True])
for name in cpu_names:
for name in caps.get_cpu_values(self.vm.get_arch()):
model.append([name, name, name, False])
# Remove button tooltip

View File

@ -25,33 +25,6 @@ from .cpu import CPU as DomainCPU
from .xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
##########################
# CPU model list objects #
##########################
class _CPUAPIValues(object):
"""
Lists valid values for cpu models obtained from libvirt's getCPUModelNames
"""
def __init__(self, conn):
self.conn = conn
self._cpus = None
def get_cpus(self, arch):
if self._cpus is not None:
return self._cpus
if self.conn.check_support(self.conn.SUPPORT_CONN_CPU_MODEL_NAMES):
names = self.conn.getCPUModelNames(arch, 0)
# Bindings were broke for a long time, so catch -1
if names != -1:
self._cpus = names
return self._cpus
return []
###################################
# capabilities host <cpu> parsing #
###################################
@ -313,7 +286,7 @@ class _CapsInfo(object):
class Capabilities(XMLBuilder):
def __init__(self, *args, **kwargs):
XMLBuilder.__init__(self, *args, **kwargs)
self._cpu_values = None
self._cpu_models_cache = {}
_XML_ROOT_NAME = "capabilities"
@ -344,11 +317,22 @@ class Capabilities(XMLBuilder):
def get_cpu_values(self, arch):
if not arch:
return []
if self._cpu_values:
return self._cpu_values.get_cpus(arch)
if not self.conn.check_support(self.conn.SUPPORT_CONN_CPU_MODEL_NAMES):
return []
if arch in self._cpu_models_cache:
return self._cpu_models_cache[arch]
self._cpu_values = _CPUAPIValues(self.conn)
return self._cpu_values.get_cpus(arch)
try:
names = self.conn.getCPUModelNames(arch, 0)
if names == -1:
names = []
except Exception as e:
logging.debug("Error fetching CPU model names for arch=%s: %s",
arch, e)
names = []
self._cpu_models_cache[arch] = names
return names
############################