Accept both 1 and Y as AMD SEV KVM kernel param value
The libvirt virt dirver checks the AMD KVM kernel module parameter SEV to see if that feature is enabled. However it seems that the /sys/module/kvm_amd/parameters/sev file can either contain "1\n" or "Y\n" to indicate that the feature is enabled. Nova only checked for "1\n" so far making the feature disabled on compute nodes with "Y\n" value. Now the logic is extended to accept both. Closes-Bug: #1975686 Change-Id: I737e1d73242430b6756178eb0bf9bd6ec5c94160
This commit is contained in:
parent
e44b1a940f
commit
ab51a5dd25
|
@ -16,6 +16,7 @@
|
|||
|
||||
import os
|
||||
|
||||
import ddt
|
||||
import eventlet
|
||||
from eventlet import greenthread
|
||||
from eventlet import tpool
|
||||
|
@ -1947,6 +1948,7 @@ class TestLibvirtSEV(test.NoDBTestCase):
|
|||
self.host = host.Host("qemu:///system")
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
||||
@mock.patch.object(os.path, 'exists', return_value=False)
|
||||
def test_kernel_parameter_missing(self, fake_exists):
|
||||
|
@ -1954,19 +1956,26 @@ class TestLibvirtSEVUnsupported(TestLibvirtSEV):
|
|||
fake_exists.assert_called_once_with(
|
||||
'/sys/module/kvm_amd/parameters/sev')
|
||||
|
||||
@ddt.data(
|
||||
('0\n', False),
|
||||
('N\n', False),
|
||||
('1\n', True),
|
||||
('Y\n', True),
|
||||
)
|
||||
@ddt.unpack
|
||||
@mock.patch.object(os.path, 'exists', return_value=True)
|
||||
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
|
||||
def test_kernel_parameter_zero(self, fake_exists):
|
||||
self.assertFalse(self.host._kernel_supports_amd_sev())
|
||||
fake_exists.assert_called_once_with(
|
||||
'/sys/module/kvm_amd/parameters/sev')
|
||||
|
||||
@mock.patch.object(os.path, 'exists', return_value=True)
|
||||
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
||||
def test_kernel_parameter_one(self, fake_exists):
|
||||
self.assertTrue(self.host._kernel_supports_amd_sev())
|
||||
fake_exists.assert_called_once_with(
|
||||
'/sys/module/kvm_amd/parameters/sev')
|
||||
def test_kernel_parameter(
|
||||
self, sev_param_value, expected_support, mock_exists
|
||||
):
|
||||
with mock.patch(
|
||||
'builtins.open', mock.mock_open(read_data=sev_param_value)
|
||||
):
|
||||
self.assertIs(
|
||||
expected_support,
|
||||
self.host._kernel_supports_amd_sev()
|
||||
)
|
||||
mock_exists.assert_called_once_with(
|
||||
'/sys/module/kvm_amd/parameters/sev')
|
||||
|
||||
@mock.patch.object(os.path, 'exists', return_value=True)
|
||||
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
|
||||
|
|
|
@ -46,6 +46,7 @@ from oslo_log import log as logging
|
|||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import units
|
||||
from oslo_utils import versionutils
|
||||
|
||||
|
@ -1699,9 +1700,9 @@ class Host(object):
|
|||
return False
|
||||
|
||||
with open(SEV_KERNEL_PARAM_FILE) as f:
|
||||
contents = f.read()
|
||||
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
|
||||
return contents == "1\n"
|
||||
content = f.read()
|
||||
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
|
||||
return strutils.bool_from_string(content)
|
||||
|
||||
@property
|
||||
def supports_amd_sev(self) -> bool:
|
||||
|
|
Loading…
Reference in New Issue