@@ -7450,6 +7450,66 @@ def test_get_volume_config(self, _set_cache_mode, get_config):
7450
7450
_set_cache_mode.assert_called_once_with(config)
7451
7451
self.assertEqual(config_guest_disk.to_xml(), config.to_xml())
7452
7452
7453
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_driver')
7454
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_attach_encryptor')
7455
+ def test_connect_volume_encryption_success(
7456
+ self, mock_attach_encryptor, mock_get_volume_driver):
7457
+
7458
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7459
+ mock_volume_driver = mock.MagicMock(
7460
+ spec=volume_drivers.LibvirtBaseVolumeDriver)
7461
+ mock_get_volume_driver.return_value = mock_volume_driver
7462
+
7463
+ connection_info = {'driver_volume_type': 'fake',
7464
+ 'data': {'device_path': '/fake',
7465
+ 'access_mode': 'rw',
7466
+ 'volume_id': uuids.volume_id}}
7467
+ encryption = {'provider': encryptors.LUKS,
7468
+ 'encryption_key_id': uuids.encryption_key_id}
7469
+ instance = mock.sentinel.instance
7470
+
7471
+ drvr._connect_volume(self.context, connection_info, instance,
7472
+ encryption=encryption)
7473
+
7474
+ mock_get_volume_driver.assert_called_once_with(connection_info)
7475
+ mock_volume_driver.connect_volume.assert_called_once_with(
7476
+ connection_info, instance)
7477
+ mock_attach_encryptor.assert_called_once_with(
7478
+ self.context, connection_info, encryption, True)
7479
+ mock_volume_driver.disconnect_volume.assert_not_called()
7480
+
7481
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_driver')
7482
+ @mock.patch.object(libvirt_driver.LibvirtDriver, '_attach_encryptor')
7483
+ def test_connect_volume_encryption_fail(
7484
+ self, mock_attach_encryptor, mock_get_volume_driver):
7485
+
7486
+ drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
7487
+ mock_volume_driver = mock.MagicMock(
7488
+ spec=volume_drivers.LibvirtBaseVolumeDriver)
7489
+ mock_get_volume_driver.return_value = mock_volume_driver
7490
+
7491
+ connection_info = {'driver_volume_type': 'fake',
7492
+ 'data': {'device_path': '/fake',
7493
+ 'access_mode': 'rw',
7494
+ 'volume_id': uuids.volume_id}}
7495
+ encryption = {'provider': encryptors.LUKS,
7496
+ 'encryption_key_id': uuids.encryption_key_id}
7497
+ instance = mock.sentinel.instance
7498
+ mock_attach_encryptor.side_effect = processutils.ProcessExecutionError
7499
+
7500
+ self.assertRaises(processutils.ProcessExecutionError,
7501
+ drvr._connect_volume,
7502
+ self.context, connection_info, instance,
7503
+ encryption=encryption)
7504
+
7505
+ mock_get_volume_driver.assert_called_once_with(connection_info)
7506
+ mock_volume_driver.connect_volume.assert_called_once_with(
7507
+ connection_info, instance)
7508
+ mock_attach_encryptor.assert_called_once_with(
7509
+ self.context, connection_info, encryption, True)
7510
+ mock_volume_driver.disconnect_volume.assert_called_once_with(
7511
+ connection_info, instance)
7512
+
7453
7513
@mock.patch.object(key_manager, 'API')
7454
7514
@mock.patch.object(libvirt_driver.LibvirtDriver, '_get_volume_encryption')
7455
7515
@mock.patch.object(libvirt_driver.LibvirtDriver, '_use_native_luks')
0 commit comments