summaryrefslogtreecommitdiff
path: root/nova/virt
diff options
context:
space:
mode:
authoryenai <yenai@cmss.chinamobile.com>2019-01-23 11:02:33 +0800
committerMatt Riedemann <mriedem.os@gmail.com>2019-04-16 15:52:59 +0000
commitee52fb12bb42b80ace19ab898bac008076cb67e6 (patch)
tree1eee2479ad4634c7c45f132c8740476845035eae /nova/virt
parent28d94c50722d24e50ceb57cffb98b98adc4c4a33 (diff)
downloadnova-ee52fb12bb42b80ace19ab898bac008076cb67e6.tar.gz
libvirt: disconnect volume when encryption fails
The compute node has left the attachment information after the encryption fails. This patch fixes this by ensuring the volume is disconnected when an exception occurs. Change-Id: I9d652f182d83a2557ff6ed0b21c69a735c3f9840 Closes-Bug: #1812945 (cherry picked from commit 79bcb4e21b7909f3e989d4fbcf68ac268680b865) (cherry picked from commit d773e3b1469a76f129d2f7a4edab68d007f3f928) (cherry picked from commit 2cde44659c42ebab25259e2b05cd5c2ffe38c131)
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/libvirt/driver.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 7762c787bd..c39720b004 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -1251,8 +1251,15 @@ class LibvirtDriver(driver.ComputeDriver):
encryption=None, allow_native_luks=True):
vol_driver = self._get_volume_driver(connection_info)
vol_driver.connect_volume(connection_info, instance)
- self._attach_encryptor(context, connection_info, encryption,
- allow_native_luks)
+ try:
+ self._attach_encryptor(
+ context, connection_info, encryption, allow_native_luks)
+ except Exception:
+ # Encryption failed so rollback the volume connection.
+ with excutils.save_and_reraise_exception(logger=LOG):
+ LOG.exception("Failure attaching encryptor; rolling back "
+ "volume connection", instance=instance)
+ vol_driver.disconnect_volume(connection_info, instance)
def _should_disconnect_target(self, context, connection_info, instance):
connection_count = 0