Skip to content

Commit 7583267

Browse files
committed
Fix traits to cpu flags mapping
Following keys like HW_CPU_X86_SVM and HW_CPU_X86_VMX are placed in TRAITS_CPU_MAPPING as part of a tuple instead of being direct keys. This patch will flaten these tuples. Closes-Bug: #2043030 Change-Id: Ia600ceb22c5939117095593b97ed94735c8f953c (cherry picked from commit 99fe8c9) (cherry picked from commit 55ed576)
1 parent 4940f81 commit 7583267

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

nova/tests/unit/virt/libvirt/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ def test_get_machine_type_from_image(self):
710710
os_mach_type = libvirt_utils.get_machine_type(image_meta)
711711
self.assertEqual('q35', os_mach_type)
712712

713+
def test_make_reverse_cpu_traits_mapping(self):
714+
for k in libvirt_utils.make_reverse_cpu_traits_mapping():
715+
self.assertIsInstance(k, str)
716+
713717
def test_get_flags_by_flavor_specs(self):
714718
flavor = objects.Flavor(
715719
id=1, flavorid='fakeid-1', name='fake1.small', memory_mb=128,
@@ -718,11 +722,15 @@ def test_get_flags_by_flavor_specs(self):
718722
'trait:%s' % os_traits.HW_CPU_X86_3DNOW: 'required',
719723
'trait:%s' % os_traits.HW_CPU_X86_SSE2: 'required',
720724
'trait:%s' % os_traits.HW_CPU_HYPERTHREADING: 'required',
725+
'trait:%s' % os_traits.HW_CPU_X86_INTEL_VMX: 'required',
726+
'trait:%s' % os_traits.HW_CPU_X86_VMX: 'required',
727+
'trait:%s' % os_traits.HW_CPU_X86_SVM: 'required',
728+
'trait:%s' % os_traits.HW_CPU_X86_AMD_SVM: 'required',
721729
})
722730
traits = libvirt_utils.get_flags_by_flavor_specs(flavor)
723731
# we shouldn't see the hyperthreading trait since that's a valid trait
724732
# but not a CPU flag
725-
self.assertEqual(set(['3dnow', 'sse2']), traits)
733+
self.assertEqual(set(['3dnow', 'sse2', 'vmx', 'svm']), traits)
726734

727735
@mock.patch('nova.virt.libvirt.utils.copy_image')
728736
@mock.patch('nova.privsep.path.chown')

nova/virt/libvirt/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,20 @@
103103
'xop': os_traits.HW_CPU_X86_XOP
104104
}
105105

106+
107+
def make_reverse_cpu_traits_mapping() -> ty.Dict[str, str]:
108+
traits_cpu_mapping = dict()
109+
for k, v in CPU_TRAITS_MAPPING.items():
110+
if isinstance(v, tuple):
111+
for trait in v:
112+
traits_cpu_mapping[trait] = k
113+
else:
114+
traits_cpu_mapping[v] = k
115+
return traits_cpu_mapping
116+
117+
106118
# Reverse CPU_TRAITS_MAPPING
107-
TRAITS_CPU_MAPPING = {v: k for k, v in CPU_TRAITS_MAPPING.items()}
119+
TRAITS_CPU_MAPPING = make_reverse_cpu_traits_mapping()
108120

109121
# global directory for emulated TPM
110122
VTPM_DIR = '/var/lib/libvirt/swtpm/'

0 commit comments

Comments
 (0)