summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBalazs Gibizer <gibi@redhat.com>2022-05-25 12:02:09 +0200
committerBalazs Gibizer <gibizer@gmail.com>2022-05-30 17:06:07 +0000
commit8a1b4975f71f9ce1446db689afb092d6e0a670a7 (patch)
treefdfecc57c9b9e276aa0a2c15263e374115368b86
parent52f4e37f6a5ff15576c4ff2a9ca203651798db10 (diff)
downloadnova-8a1b4975f71f9ce1446db689afb092d6e0a670a7.tar.gz
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 (cherry picked from commit ab51a5dd25b8d4c66562148b43b1022eb5ceed7e)
-rw-r--r--nova/tests/unit/virt/libvirt/test_host.py33
-rw-r--r--nova/virt/libvirt/host.py7
2 files changed, 25 insertions, 15 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_host.py b/nova/tests/unit/virt/libvirt/test_host.py
index d71d13ab37..1eb26572aa 100644
--- a/nova/tests/unit/virt/libvirt/test_host.py
+++ b/nova/tests/unit/virt/libvirt/test_host.py
@@ -16,6 +16,7 @@
import os
+import ddt
import eventlet
from eventlet import greenthread
from eventlet import tpool
@@ -1928,6 +1929,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):
@@ -1935,19 +1937,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"))
diff --git a/nova/virt/libvirt/host.py b/nova/virt/libvirt/host.py
index cdf47008de..63f1a9c6e4 100644
--- a/nova/virt/libvirt/host.py
+++ b/nova/virt/libvirt/host.py
@@ -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
@@ -1656,9 +1657,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: