def test_libvirt_exception_cpu_features(self): machinetype.cpu_features.invalidate() with MonkeyPatchScope([ (machinetype.libvirtconnection, 'get', lambda: FailingConnection()), ]): result = machinetype.cpu_features() self.assertEqual(result, [])
def test_cpu_features(self, arch, expected_features): machinetype.cpu_features.invalidate() conn = FakeConnection(arch) with MonkeyPatchScope([ (machinetype.cpuarch, 'real', lambda: arch), (machinetype.libvirtconnection, 'get', lambda: conn), ]): result = machinetype.cpu_features() self.assertEqual(result, expected_features)
def test_cpu_features_no_ibrs(self): machinetype.cpu_features.invalidate() conn = FakeConnection(cpuarch.X86_64, file_name='domcaps_libvirt_x86_64_noibrs.out') with MonkeyPatchScope([ (machinetype.cpuarch, 'real', lambda: cpuarch.X86_64), (machinetype.libvirtconnection, 'get', lambda: conn), ]): result = machinetype.cpu_features() self.assertEqual(result, _EXPECTED_CPU_FEATURES_X86_64)
def _getFlagsAndFeatures(): """ Read CPU flags from cpuinfo and CPU features from domcapabilities, and combine them into a single list. """ # We need to use both flags (cpuinfo.flags()) and domcapabilites # (machinetype.cpu_features) because they return different sets # of flags (domcapabilities also return the content of # arch_capabilities). The sets overlap, so we convert # list -> set -> list to remove duplicates. flags_and_features = list(set(cpuinfo.flags() + machinetype.cpu_features())) return flags_and_features + machinetype.compatible_cpu_models()
def _getFlagsAndFeatures(): """ Read CPU flags from cpuinfo and CPU features from domcapabilities, and combine them into a single list. """ # We need to use both flags (cpuinfo.flags()) and domcapabilites # (machinetype.cpu_features) because they return different sets # of flags (domcapabilities also return the content of # arch_capabilities). The sets overlap, so we convert # list -> set -> list to remove duplicates. flags_and_features = list(set(cpuinfo.flags() + machinetype.cpu_features())) cpu_models = machinetype.compatible_cpu_models() # Easier to add here than in Engine: # If -IBRS suffix is present in any of the compatible CPU models, # we can assume spec_ctrl feature. for model in cpu_models: if model.endswith('-IBRS'): spec_ctrl = 'spec_ctrl' if spec_ctrl not in flags_and_features: flags_and_features.append(spec_ctrl) break return flags_and_features + cpu_models