Merge "Accept both 1 and Y as AMD SEV KVM kernel param value" into stable/yoga
This commit is contained in:
commit
eada760a21
|
@ -16,6 +16,7 @@
|
|||
|
||||
import os
|
||||
|
||||
import ddt
|
||||
import eventlet
|
||||
from eventlet import greenthread
|
||||
from eventlet import tpool
|
||||
|
@ -1935,6 +1936,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):
|
||||
|
@ -1942,19 +1944,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
|
||||
|
||||
|
@ -1671,9 +1672,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