Skip to content

Commit 4511d5d

Browse files
authored
Merge pull request #39 from stackhpc/upstream/xena-2023-03-31
Synchronise xena with upstream
2 parents 13ba896 + 5f1b7d3 commit 4511d5d

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
@@ -1844,26 +1845,34 @@ def setUp(self):
18441845
self.host = host.Host("qemu:///system")
18451846

18461847

1848+
@ddt.ddt
18471849
class TestLibvirtSEVUnsupported(TestLibvirtSEV):
18481850
@mock.patch.object(os.path, 'exists', return_value=False)
18491851
def test_kernel_parameter_missing(self, fake_exists):
18501852
self.assertFalse(self.host._kernel_supports_amd_sev())
18511853
fake_exists.assert_called_once_with(
18521854
'/sys/module/kvm_amd/parameters/sev')
18531855

1856+
@ddt.data(
1857+
('0\n', False),
1858+
('N\n', False),
1859+
('1\n', True),
1860+
('Y\n', True),
1861+
)
1862+
@ddt.unpack
18541863
@mock.patch.object(os.path, 'exists', return_value=True)
1855-
@mock.patch('builtins.open', mock.mock_open(read_data="0\n"))
1856-
def test_kernel_parameter_zero(self, fake_exists):
1857-
self.assertFalse(self.host._kernel_supports_amd_sev())
1858-
fake_exists.assert_called_once_with(
1859-
'/sys/module/kvm_amd/parameters/sev')
1860-
1861-
@mock.patch.object(os.path, 'exists', return_value=True)
1862-
@mock.patch('builtins.open', mock.mock_open(read_data="1\n"))
1863-
def test_kernel_parameter_one(self, fake_exists):
1864-
self.assertTrue(self.host._kernel_supports_amd_sev())
1865-
fake_exists.assert_called_once_with(
1866-
'/sys/module/kvm_amd/parameters/sev')
1864+
def test_kernel_parameter(
1865+
self, sev_param_value, expected_support, mock_exists
1866+
):
1867+
with mock.patch(
1868+
'builtins.open', mock.mock_open(read_data=sev_param_value)
1869+
):
1870+
self.assertIs(
1871+
expected_support,
1872+
self.host._kernel_supports_amd_sev()
1873+
)
1874+
mock_exists.assert_called_once_with(
1875+
'/sys/module/kvm_amd/parameters/sev')
18671876

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

@@ -1585,9 +1586,9 @@ def _kernel_supports_amd_sev(self) -> bool:
15851586
return False
15861587

15871588
with open(SEV_KERNEL_PARAM_FILE) as f:
1588-
contents = f.read()
1589-
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, contents)
1590-
return contents == "1\n"
1589+
content = f.read()
1590+
LOG.debug("%s contains [%s]", SEV_KERNEL_PARAM_FILE, content)
1591+
return strutils.bool_from_string(content)
15911592

15921593
@property
15931594
def supports_amd_sev(self) -> bool:

0 commit comments

Comments
 (0)