Merge "libvirt: Ensure both swtpm and swtpm_setup exist for vTPM support"

This commit is contained in:
Zuul
2024-05-28 09:07:13 +00:00
committed by Gerrit Code Review
2 changed files with 8 additions and 7 deletions

View File

@@ -1470,13 +1470,13 @@ class LibvirtConnTestCase(test.NoDBTestCase,
exc = self.assertRaises(exception.InvalidConfiguration,
drvr.init_host, "dummyhost")
self.assertIn(
"vTPM support is configured but the 'swtpm' and 'swtpm_setup' "
"binaries could not be found on PATH.",
"vTPM support is configured but one (or all) of the 'swtpm' "
"and 'swtpm_setup' binaries could not be found on PATH.",
str(exc),
)
mock_which.assert_has_calls(
[mock.call('swtpm_setup'), mock.call('swtpm')],
[mock.call('swtpm_setup')],
)
@mock.patch.object(host.Host, 'has_min_version', return_value=True)
@@ -1547,12 +1547,13 @@ class LibvirtConnTestCase(test.NoDBTestCase,
correctly.
"""
self.flags(swtpm_enabled=True, virt_type='kvm', group='libvirt')
mock_which.return_value = True
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
drvr.init_host('dummyhost')
mock_which.assert_has_calls(
[mock.call('swtpm_setup'), mock.call().__bool__()],
[mock.call('swtpm_setup'), mock.call('swtpm')],
)
@mock.patch.object(libvirt_driver.LOG, 'warning')

View File

@@ -1090,10 +1090,10 @@ class LibvirtDriver(driver.ComputeDriver):
# NOTE(stephenfin): This checks using the PATH of the user running
# nova-compute rather than the libvirtd service, meaning it's an
# imperfect check but the best we can do
if not any(shutil.which(cmd) for cmd in ('swtpm_setup', 'swtpm')):
if not all(shutil.which(cmd) for cmd in ('swtpm_setup', 'swtpm')):
msg = _(
"vTPM support is configured but the 'swtpm' and "
"'swtpm_setup' binaries could not be found on PATH.")
"vTPM support is configured but one (or all) of the 'swtpm' "
"and 'swtpm_setup' binaries could not be found on PATH.")
raise exception.InvalidConfiguration(msg)
# The user and group must be valid on this host for cold migration and