Skip to content

Commit a19a836

Browse files
authored
Merge pull request #53 from stackhpc/upstream/wallaby-2023-11-03
Synchronise wallaby with upstream
2 parents 8882902 + 2ace99d commit a19a836

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
@@ -1821,26 +1822,34 @@ def setUp(self):
18211822
self.host = host.Host("qemu:///system")
18221823

18231824

1825+
@ddt.ddt
18241826
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
18251827
@mock.patch.object(os.path, 'exists', return_value=False)
18261828
def test_kernel_parameter_missing(self, fake_exists):
18271829
self.assertFalse(self.host._kernel_supports_amd_sev())
18281830
fake_exists.assert_called_once_with(
18291831
'/sys/module/kvm_amd/parameters/sev')
18301832

1833+
@ddt.data(
1834+
('0\n', False),
1835+
('N\n', False),
1836+
('1\n', True),
1837+
('Y\n', True),
1838+
)
1839+
@ddt.unpack
18311840
@mock.patch.object(os.path, 'exists', return_value=True)
1832-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1833-
def test_kernel_parameter_zero(self, fake_exists):
1834-
self.assertFalse(self.host._kernel_supports_amd_sev())
1835-
fake_exists.assert_called_once_with(
1836-
'/sys/module/kvm_amd/parameters/sev')
1837-
1838-
@mock.patch.object(os.path, 'exists', return_value=True)
1839-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1840-
def test_kernel_parameter_one(self, fake_exists):
1841-
self.assertTrue(self.host._kernel_supports_amd_sev())
1842-
fake_exists.assert_called_once_with(
1843-
'/sys/module/kvm_amd/parameters/sev')
1841+
def test_kernel_parameter(
1842+
self, sev_param_value, expected_support, mock_exists
1843+
):
1844+
with mock.patch(
1845+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1846+
):
1847+
self.assertIs(
1848+
expected_support,
1849+
self.host._kernel_supports_amd_sev()
1850+
)
1851+
mock_exists.assert_called_once_with(
1852+
'/sys/module/kvm_amd/parameters/sev')
18441853

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

@@ -1553,9 +1554,9 @@ def _kernel_supports_amd_sev(self) -> bool:
15531554
return False
15541555

15551556
with open(SEV_KERNEL_PARAM_FILE) as f:
1556-
contents = f.read()
1557-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1558-
return contents == "1\n"
1557+
content = f.read()
1558+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1559+
return strutils.bool_from_string(content)
15591560

15601561
@property
15611562
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)