Skip to content

Commit eada760

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Accept both 1 and Y as AMD SEV KVM kernel param value" into stable/yoga
2 parents 4ccd7c0 + 8a1b497 commit eada760

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
@@ -1935,26 +1936,34 @@ def setUp(self):
19351936
self.host = host.Host("qemu:///system")
19361937

19371938

1939+
@ddt.ddt
19381940
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
19391941
@mock.patch.object(os.path, 'exists', return_value=False)
19401942
def test_kernel_parameter_missing(self, fake_exists):
19411943
self.assertFalse(self.host._kernel_supports_amd_sev())
19421944
fake_exists.assert_called_once_with(
19431945
'/sys/module/kvm_amd/parameters/sev')
19441946

1947+
@ddt.data(
1948+
('0\n', False),
1949+
('N\n', False),
1950+
('1\n', True),
1951+
('Y\n', True),
1952+
)
1953+
@ddt.unpack
19451954
@mock.patch.object(os.path, 'exists', return_value=True)
1946-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1947-
def test_kernel_parameter_zero(self, fake_exists):
1948-
self.assertFalse(self.host._kernel_supports_amd_sev())
1949-
fake_exists.assert_called_once_with(
1950-
'/sys/module/kvm_amd/parameters/sev')
1951-
1952-
@mock.patch.object(os.path, 'exists', return_value=True)
1953-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1954-
def test_kernel_parameter_one(self, fake_exists):
1955-
self.assertTrue(self.host._kernel_supports_amd_sev())
1956-
fake_exists.assert_called_once_with(
1957-
'/sys/module/kvm_amd/parameters/sev')
1955+
def test_kernel_parameter(
1956+
self, sev_param_value, expected_support, mock_exists
1957+
):
1958+
with mock.patch(
1959+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1960+
):
1961+
self.assertIs(
1962+
expected_support,
1963+
self.host._kernel_supports_amd_sev()
1964+
)
1965+
mock_exists.assert_called_once_with(
1966+
'/sys/module/kvm_amd/parameters/sev')
19581967

19591968
@mock.patch.object(os.path, 'exists', return_value=True)
19601969
@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

@@ -1671,9 +1672,9 @@ def _kernel_supports_amd_sev(self) -> bool:
16711672
return False
16721673

16731674
with open(SEV_KERNEL_PARAM_FILE) as f:
1674-
contents = f.read()
1675-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1676-
return contents == "1\n"
1675+
content = f.read()
1676+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1677+
return strutils.bool_from_string(content)
16771678

16781679
@property
16791680
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)