Skip to content

Commit ab51a5d

Browse files
committed
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
1 parent e44b1a9 commit ab51a5d

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818

19+
import ddt
1920
import eventlet
2021
from eventlet import greenthread
2122
from eventlet import tpool
@@ -1947,26 +1948,34 @@ def setUp(self):
19471948
self.host = host.Host("qemu:///system")
19481949

19491950

1951+
@ddt.ddt
19501952
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
19511953
@mock.patch.object(os.path, 'exists', return_value=False)
19521954
def test_kernel_parameter_missing(self, fake_exists):
19531955
self.assertFalse(self.host._kernel_supports_amd_sev())
19541956
fake_exists.assert_called_once_with(
19551957
'/sys/module/kvm_amd/parameters/sev')
19561958

1959+
@ddt.data(
1960+
('0\n', False),
1961+
('N\n', False),
1962+
('1\n', True),
1963+
('Y\n', True),
1964+
)
1965+
@ddt.unpack
19571966
@mock.patch.object(os.path, 'exists', return_value=True)
1958-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1959-
def test_kernel_parameter_zero(self, fake_exists):
1960-
self.assertFalse(self.host._kernel_supports_amd_sev())
1961-
fake_exists.assert_called_once_with(
1962-
'/sys/module/kvm_amd/parameters/sev')
1963-
1964-
@mock.patch.object(os.path, 'exists', return_value=True)
1965-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1966-
def test_kernel_parameter_one(self, fake_exists):
1967-
self.assertTrue(self.host._kernel_supports_amd_sev())
1968-
fake_exists.assert_called_once_with(
1969-
'/sys/module/kvm_amd/parameters/sev')
1967+
def test_kernel_parameter(
1968+
self, sev_param_value, expected_support, mock_exists
1969+
):
1970+
with mock.patch(
1971+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1972+
):
1973+
self.assertIs(
1974+
expected_support,
1975+
self.host._kernel_supports_amd_sev()
1976+
)
1977+
mock_exists.assert_called_once_with(
1978+
'/sys/module/kvm_amd/parameters/sev')
19701979

19711980
@mock.patch.object(os.path, 'exists', return_value=True)
19721981
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))

nova/virt/libvirt/host.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from oslo_serialization import jsonutils
4747
from oslo_utils import excutils
4848
from oslo_utils import importutils
49+
from oslo_utils import strutils
4950
from oslo_utils import units
5051
from oslo_utils import versionutils
5152

@@ -1699,9 +1700,9 @@ def _kernel_supports_amd_sev(self) -> bool:
16991700
return False
17001701

17011702
with open(SEV_KERNEL_PARAM_FILE) as f:
1702-
contents = f.read()
1703-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1704-
return contents == "1\n"
1703+
content = f.read()
1704+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1705+
return strutils.bool_from_string(content)
17051706

17061707
@property
17071708
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)