@@ -7507,6 +7507,66 @@ def test_get_volume_config(self, _set_cache_mode, get_config):
7507
7507
_set_cache_mode.assert_called_once_with(config)
7508
7508
self.assertEqual(config_guest_disk.to_xml(), config.to_xml())
7509
7509
7510
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_driver')
7511
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_attach_encryptor')
7512
+ def test_connect_volume_encryption_success(
7513
+ self, mock_attach_encryptor, mock_get_volume_driver):
7514
+
7515
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7516
+ mock_volume_driver = mock.MagicMock(
7517
+ spec=volume_drivers.LibvirtBaseVolumeDriver)
7518
+ mock_get_volume_driver.return_value = mock_volume_driver
7519
+
7520
+ connection_info = {'driver_volume_type': 'fake',
7521
+ 'data': {'device_path': '/fake',
7522
+ 'access_mode': 'rw',
7523
+ 'volume_id': uuids.volume_id}}
7524
+ encryption = {'provider': encryptors.LUKS,
7525
+ 'encryption_key_id': uuids.encryption_key_id}
7526
+ instance = mock.sentinel.instance
7527
+
7528
+ drvr._connect_volume(self.context, connection_info, instance,
7529
+ encryption=encryption)
7530
+
7531
+ mock_get_volume_driver.assert_called_once_with(connection_info)
7532
+ mock_volume_driver.connect_volume.assert_called_once_with(
7533
+ connection_info, instance)
7534
+ mock_attach_encryptor.assert_called_once_with(
7535
+ self.context, connection_info, encryption, True)
7536
+ mock_volume_driver.disconnect_volume.assert_not_called()
7537
+
7538
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_driver')
7539
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_attach_encryptor')
7540
+ def test_connect_volume_encryption_fail(
7541
+ self, mock_attach_encryptor, mock_get_volume_driver):
7542
+
7543
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7544
+ mock_volume_driver = mock.MagicMock(
7545
+ spec=volume_drivers.LibvirtBaseVolumeDriver)
7546
+ mock_get_volume_driver.return_value = mock_volume_driver
7547
+
7548
+ connection_info = {'driver_volume_type': 'fake',
7549
+ 'data': {'device_path': '/fake',
7550
+ 'access_mode': 'rw',
7551
+ 'volume_id': uuids.volume_id}}
7552
+ encryption = {'provider': encryptors.LUKS,
7553
+ 'encryption_key_id': uuids.encryption_key_id}
7554
+ instance = mock.sentinel.instance
7555
+ mock_attach_encryptor.side_effect = processutils.ProcessExecutionError
7556
+
7557
+ self.assertRaises(processutils.ProcessExecutionError,
7558
+ drvr._connect_volume,
7559
+ self.context, connection_info, instance,
7560
+ encryption=encryption)
7561
+
7562
+ mock_get_volume_driver.assert_called_once_with(connection_info)
7563
+ mock_volume_driver.connect_volume.assert_called_once_with(
7564
+ connection_info, instance)
7565
+ mock_attach_encryptor.assert_called_once_with(
7566
+ self.context, connection_info, encryption, True)
7567
+ mock_volume_driver.disconnect_volume.assert_called_once_with(
7568
+ connection_info, instance)
7569
+
7510
7570
@mock.patch.object(key_manager, 'API')
7511
7571
@mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_encryption')
7512
7572
@mock.patch.object(libvirt_driver.LibvirtDriver, '_use_native_luks')
0 commit comments