Skip to content

Commit 200cd65

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "libvirt: Skip encryption metadata lookups if secret already exists on host"
2 parents 7591f68 + a107a50 commit 200cd65

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9119,6 +9119,9 @@ def test_connect_volume_luks(self, mock_is_volume_luks, mock_host,
91199119
'encryption_key_id': uuids.encryption_key_id}
91209120
instance = mock.sentinel.instance
91219121

9122+
# Mock out find_secret so we don't skip ahead
9123+
drvr._host.find_secret.return_value = None
9124+
91229125
# Mock out the encryptors
91239126
mock_encryptor = mock.Mock()
91249127
mock_get_volume_encryptor.return_value = mock_encryptor
@@ -10179,6 +10182,21 @@ def test_attach_encryptor_encrypted_native_luks_serial(self,
1017910182
crt_scrt.assert_called_once_with(
1018010183
'volume', uuids.serial, password=key)
1018110184

10185+
@mock.patch.object(key_manager, 'API')
10186+
def test_attach_encryptor_secret_exists(self, mock_key_manager_api):
10187+
connection_info = {'data': {'volume_id': uuids.volume_id}}
10188+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
10189+
with test.nested(
10190+
mock.patch.object(drvr, '_get_volume_encryption'),
10191+
mock.patch.object(drvr._host, 'find_secret')
10192+
) as (mock_get_volume_encryption, mock_find_secret):
10193+
drvr._attach_encryptor(self.context, connection_info, None)
10194+
10195+
# Assert we called find_secret and nothing else
10196+
mock_find_secret.assert_called_once_with('volume', uuids.volume_id)
10197+
mock_get_volume_encryption.assert_not_called()
10198+
mock_key_manager_api.assert_not_called()
10199+
1018210200
@mock.patch('os_brick.encryptors.get_encryption_metadata')
1018310201
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
1018410202
def test_detach_encryptor_connection_info_incomplete(self,

nova/virt/libvirt/driver.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,17 @@ def _attach_encryptor(self, context, connection_info, encryption):
17151715
to determine if an attempt to attach the encryptor should be made.
17161716

17171717
"""
1718+
# NOTE(lyarwood): Skip any attempt to fetch encryption metadata or the
1719+
# actual passphrase from the key manager if a libvirt secert already
1720+
# exists locally for the volume. This suggests that the instance was
1721+
# only powered off or the underlying host rebooted.
1722+
volume_id = driver_block_device.get_volume_id(connection_info)
1723+
if self._host.find_secret('volume', volume_id):
1724+
LOG.debug("A libvirt secret for volume %s has been found on the "
1725+
"host, skipping any attempt to create another or attach "
1726+
"an os-brick encryptor.", volume_id)
1727+
return
1728+
17181729
if encryption is None:
17191730
encryption = self._get_volume_encryption(context, connection_info)
17201731

@@ -1746,7 +1757,6 @@ def _attach_encryptor(self, context, connection_info, encryption):
17461757
# NOTE(lyarwood): Store the passphrase as a libvirt secret locally
17471758
# on the compute node. This secret is used later when generating
17481759
# the volume config.
1749-
volume_id = driver_block_device.get_volume_id(connection_info)
17501760
self._host.create_secret('volume', volume_id, password=passphrase)
17511761
elif encryption:
17521762
encryptor = self._get_volume_encryptor(connection_info,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
fixes:
3+
- |
4+
The libvirt virt driver will no longer attempt to fetch volume
5+
encryption metadata or the associated secret key when attaching ``LUKSv1``
6+
encrypted volumes if a libvirt secret already exists on the host.
7+
8+
This resolves `bug 1905701`_ where instances with ``LUKSv1`` encrypted
9+
volumes could not be restarted automatically by the ``nova-compute``
10+
service after a host reboot when the
11+
``[DEFAULT]/resume_guests_state_on_host_boot`` configurable was enabled.
12+
13+
.. _bug 1905701: https://launchpad.net/bugs/1905701

0 commit comments

Comments
 (0)