Skip to content

Commit 3b41633

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Support old & new versions of svm and vmx traits"
2 parents 19cb983 + b420c34 commit 3b41633

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

nova/tests/functional/libvirt/test_report_cpu_traits.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def test_report_cpu_traits(self):
8181
# trait values are coming from fakelibvirt's baselineCPU result.
8282
# COMPUTE_NODE is always set on the compute node provider.
8383
traits = self._get_provider_traits(self.host_uuid)
84-
for trait in ('HW_CPU_X86_VMX', 'HW_CPU_X86_AESNI', 'COMPUTE_NODE'):
84+
for trait in (
85+
'HW_CPU_X86_VMX', 'HW_CPU_X86_INTEL_VMX', 'HW_CPU_X86_AESNI',
86+
'COMPUTE_NODE',
87+
):
8588
self.assertIn(trait, traits)
8689

8790
self._create_trait('CUSTOM_TRAITS')
@@ -96,10 +99,14 @@ def test_report_cpu_traits(self):
9699
# and it's not in the baseline for the host.
97100
traits = set(self._get_provider_traits(self.host_uuid))
98101
expected_traits = self.expected_libvirt_driver_capability_traits.union(
99-
[u'HW_CPU_X86_VMX', u'HW_CPU_X86_AESNI', u'CUSTOM_TRAITS',
100-
# The periodic restored the COMPUTE_NODE trait.
101-
u'COMPUTE_NODE']
102-
)
102+
[
103+
'HW_CPU_X86_VMX',
104+
'HW_CPU_X86_INTEL_VMX',
105+
'HW_CPU_X86_AESNI',
106+
'CUSTOM_TRAITS',
107+
# The periodic restored the COMPUTE_NODE trait.
108+
'COMPUTE_NODE',
109+
])
103110
for trait in expected_traits:
104111
self.assertIn(trait, traits)
105112

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21101,7 +21101,7 @@ class TestUpdateProviderTree(test.NoDBTestCase):
2110121101
pcpus = 12
2110221102
memory_mb = 1024
2110321103
disk_gb = 200
21104-
cpu_traits = {t: False for t in libvirt_utils.CPU_TRAITS_MAPPING.values()}
21104+
cpu_traits = libvirt_utils.cpu_features_to_traits({})
2110521105

2110621106
def setUp(self):
2110721107
super(TestUpdateProviderTree, self).setUp()
@@ -21816,7 +21816,7 @@ class TraitsComparisonMixin(object):
2181621816

2181721817
def assertTraitsEqual(self, expected, actual):
2181821818
exp = {t: t in expected
21819-
for t in libvirt_utils.CPU_TRAITS_MAPPING.values()}
21819+
for t in libvirt_utils.cpu_features_to_traits({})}
2182021820
self.assertEqual(exp, actual)
2182121821

2182221822

@@ -25538,8 +25538,9 @@ def test_cpu_traits_with_passthrough_mode(self):
2553825538
are calculated from fakelibvirt's baseline CPU features.
2553925539
"""
2554025540
self.flags(cpu_mode='host-passthrough', group='libvirt')
25541-
self.assertTraitsEqual(['HW_CPU_X86_AESNI', 'HW_CPU_X86_VMX'],
25542-
self.drvr._get_cpu_feature_traits())
25541+
self.assertTraitsEqual(
25542+
['HW_CPU_X86_AESNI', 'HW_CPU_X86_VMX', 'HW_CPU_X86_INTEL_VMX'],
25543+
self.drvr._get_cpu_feature_traits())
2554325544

2554425545
@mock.patch('nova.virt.libvirt.host.libvirt.Connection.baselineCPU')
2554525546
def test_cpu_traits_with_mode_none(self, mock_baseline):
@@ -25548,9 +25549,10 @@ def test_cpu_traits_with_mode_none(self, mock_baseline):
2554825549
"""
2554925550
self.flags(cpu_mode='none', group='libvirt')
2555025551
mock_baseline.return_value = _fake_qemu64_cpu_feature
25551-
self.assertTraitsEqual(['HW_CPU_X86_SSE', 'HW_CPU_X86_SVM',
25552-
'HW_CPU_X86_MMX', 'HW_CPU_X86_SSE2'],
25553-
self.drvr._get_cpu_feature_traits())
25552+
self.assertTraitsEqual(
25553+
['HW_CPU_X86_SSE', 'HW_CPU_X86_SVM', 'HW_CPU_X86_AMD_SVM',
25554+
'HW_CPU_X86_MMX', 'HW_CPU_X86_SSE2'],
25555+
self.drvr._get_cpu_feature_traits())
2555425556

2555525557
mock_baseline.assert_called_with([u'''<cpu>
2555625558
<arch>x86_64</arch>
@@ -25638,6 +25640,7 @@ def test_cpu_traits_with_mode_custom_multi_models(self, mocked_baseline,
2563825640
'HW_CPU_X86_SSE2',
2563925641
'HW_CPU_X86_SSE',
2564025642
'HW_CPU_X86_MMX',
25643+
'HW_CPU_X86_AMD_SVM',
2564125644
'HW_CPU_X86_SVM'
2564225645
], self.drvr._get_cpu_feature_traits()
2564325646
)
@@ -25705,6 +25708,7 @@ def test_cpu_traits_with_mode_custom_multi_models_and_extra_flags(self,
2570525708
'HW_CPU_X86_SSE2',
2570625709
'HW_CPU_X86_SSE',
2570725710
'HW_CPU_X86_MMX',
25711+
'HW_CPU_X86_AMD_SVM',
2570825712
'HW_CPU_X86_SVM'
2570925713
], self.drvr._get_cpu_feature_traits()
2571025714
)

nova/virt/libvirt/utils.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,13 @@
9393
'sse4.2': os_traits.HW_CPU_X86_SSE42,
9494
'sse4a': os_traits.HW_CPU_X86_SSE4A,
9595
'ssse3': os_traits.HW_CPU_X86_SSSE3,
96-
'svm': os_traits.HW_CPU_X86_SVM,
96+
# We have to continue to support the old (generic) trait for the
97+
# AMD-specific svm feature.
98+
'svm': (os_traits.HW_CPU_X86_SVM, os_traits.HW_CPU_X86_AMD_SVM),
9799
'tbm': os_traits.HW_CPU_X86_TBM,
98-
'vmx': os_traits.HW_CPU_X86_VMX,
100+
# We have to continue to support the old (generic) trait for the
101+
# Intel-specific vmx feature.
102+
'vmx': (os_traits.HW_CPU_X86_VMX, os_traits.HW_CPU_X86_INTEL_VMX),
99103
'xop': os_traits.HW_CPU_X86_XOP
100104
}
101105

@@ -577,11 +581,15 @@ def cpu_features_to_traits(features: ty.Set[str]) -> ty.Dict[str, bool]:
577581
"""Returns this driver's CPU traits dict where keys are trait names from
578582
CPU_TRAITS_MAPPING, values are boolean indicates whether the trait should
579583
be set in the provider tree.
584+
585+
:param features: A set of feature names (short, lowercase,
586+
CPU_TRAITS_MAPPING's keys).
580587
"""
581-
traits = {trait_name: False for trait_name in CPU_TRAITS_MAPPING.values()}
582-
for f in features:
583-
if f in CPU_TRAITS_MAPPING:
584-
traits[CPU_TRAITS_MAPPING[f]] = True
588+
traits = {}
589+
for feature_name, val in CPU_TRAITS_MAPPING.items():
590+
trait_tuple = val if isinstance(val, tuple) else (val,)
591+
for trait_name in trait_tuple:
592+
traits[trait_name] = feature_name in features
585593

586594
return traits
587595

0 commit comments

Comments
 (0)