Skip to content

Commit 7e90471

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "libvirt: Skip encryption metadata lookups if secret already exists on host" into stable/victoria
2 parents 5f82c5e + eda11a4 commit 7e90471

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
@@ -9136,6 +9136,9 @@ def test_connect_volume_luks(self, mock_is_volume_luks, mock_host,
91369136
'encryption_key_id': uuids.encryption_key_id}
91379137
instance = mock.sentinel.instance
91389138

9139+
# Mock out find_secret so we don't skip ahead
9140+
drvr._host.find_secret.return_value = None
9141+
91399142
# Mock out the encryptors
91409143
mock_encryptor = mock.Mock()
91419144
mock_get_volume_encryptor.return_value = mock_encryptor
@@ -10199,6 +10202,21 @@ def test_attach_encryptor_encrypted_native_luks_serial(self,
1019910202
crt_scrt.assert_called_once_with(
1020010203
'volume', uuids.serial, password=key)
1020110204

10205+
@mock.patch.object(key_manager, 'API')
10206+
def test_attach_encryptor_secret_exists(self, mock_key_manager_api):
10207+
connection_info = {'data': {'volume_id': uuids.volume_id}}
10208+
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
10209+
with test.nested(
10210+
mock.patch.object(drvr, '_get_volume_encryption'),
10211+
mock.patch.object(drvr._host, 'find_secret')
10212+
) as (mock_get_volume_encryption, mock_find_secret):
10213+
drvr._attach_encryptor(self.context, connection_info, None)
10214+
10215+
# Assert we called find_secret and nothing else
10216+
mock_find_secret.assert_called_once_with('volume', uuids.volume_id)
10217+
mock_get_volume_encryption.assert_not_called()
10218+
mock_key_manager_api.assert_not_called()
10219+
1020210220
@mock.patch('os_brick.encryptors.get_encryption_metadata')
1020310221
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
1020410222
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
@@ -1791,6 +1791,17 @@ def _attach_encryptor(self, context, connection_info, encryption):
17911791
to determine if an attempt to attach the encryptor should be made.
17921792

17931793
"""
1794+
# NOTE(lyarwood): Skip any attempt to fetch encryption metadata or the
1795+
# actual passphrase from the key manager if a libvirt secert already
1796+
# exists locally for the volume. This suggests that the instance was
1797+
# only powered off or the underlying host rebooted.
1798+
volume_id = driver_block_device.get_volume_id(connection_info)
1799+
if self._host.find_secret('volume', volume_id):
1800+
LOG.debug("A libvirt secret for volume %s has been found on the "
1801+
"host, skipping any attempt to create another or attach "
1802+
"an os-brick encryptor.", volume_id)
1803+
return
1804+
17941805
if encryption is None:
17951806
encryption = self._get_volume_encryption(context, connection_info)
17961807

@@ -1822,7 +1833,6 @@ def _attach_encryptor(self, context, connection_info, encryption):
18221833
# NOTE(lyarwood): Store the passphrase as a libvirt secret locally
18231834
# on the compute node. This secret is used later when generating
18241835
# the volume config.
1825-
volume_id = driver_block_device.get_volume_id(connection_info)
18261836
self._host.create_secret('volume', volume_id, password=passphrase)
18271837
elif encryption:
18281838
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)