Browse Source

Cinder - Creating clone of encrypted volume fails

After a clone of an encrypted volume is created, an attach is attempted.
PowerMax driver requires the provider_location be populated in order
to find the volume to attach. For this, the volume object needs to be
updated.

Closes-Bug: #1913054
Change-Id: Idf5b3783ddc333d6d60f28a3d08e5fd28e5c1fa8
changes/17/772517/5
Helen Walsh 8 months ago
parent
commit
e1f56a7c85
  1. 52
      cinder/tests/unit/volume/flows/test_create_volume_flow.py
  2. 1
      cinder/volume/flows/manager/create_volume.py
  3. 6
      releasenotes/notes/cinder-clone-encrypted-a28338e2b1838a63.yaml

52
cinder/tests/unit/volume/flows/test_create_volume_flow.py

@ -268,6 +268,33 @@ class CreateVolumeFlowTestCase(test.TestCase):
multiattach=None)
self.assertEqual(bootable, result['volume_properties']['bootable'])
@mock.patch('cinder.db.volume_create')
@mock.patch('cinder.objects.Volume.get_by_id')
@ddt.unpack
def test_create_from_source_volid_encrypted(self,
volume_get_by_id,
volume_create):
volume_db = {'encryption_key_id': fakes.ENCRYPTION_KEY_ID}
volume_obj = fake_volume.fake_volume_obj(self.ctxt, **volume_db)
volume_get_by_id.return_value = volume_obj
volume_create.return_value = {'id': fakes.VOLUME2_ID}
task = create_volume.EntryCreateTask()
result = task.execute(self.ctxt,
optional_args=None,
source_volid=volume_obj.id,
snapshot_id=None,
availability_zones=['nova'],
size=1,
encryption_key_id=volume_obj.encryption_key_id,
description='123',
name='123',
multiattach=None)
self.assertEqual(
fakes.ENCRYPTION_KEY_ID,
result['volume_properties']['encryption_key_id'])
@ddt.data(('enabled', {'replication_enabled': '<is> True'}),
('disabled', {'replication_enabled': '<is> False'}),
('disabled', {}))
@ -1016,6 +1043,31 @@ class CreateVolumeFlowManagerTestCase(test.TestCase):
super(CreateVolumeFlowManagerTestCase, self).setUp()
self.ctxt = context.get_admin_context()
@mock.patch('cinder.volume.flows.manager.create_volume.'
'CreateVolumeFromSpecTask.'
'_cleanup_cg_in_volume')
@mock.patch('cinder.volume.flows.manager.create_volume.'
'CreateVolumeFromSpecTask.'
'_rekey_volume')
@mock.patch('cinder.objects.Volume.update')
@mock.patch('cinder.objects.Volume.get_by_id')
def test_create_from_source_volume_encrypted_update_volume(
self, volume_get_by_id, vol_update, rekey_vol, cleanup_cg):
fake_db = mock.MagicMock()
fake_driver = mock.MagicMock()
fake_volume_manager = mock.MagicMock()
fake_manager = create_volume_manager.CreateVolumeFromSpecTask(
fake_volume_manager, fake_db, fake_driver)
volume_db = {'encryption_key_id': fakes.ENCRYPTION_KEY_ID}
volume_obj = fake_volume.fake_volume_obj(self.ctxt, **volume_db)
volume_get_by_id.return_value = volume_obj
source_volume_id = fakes.VOLUME2_ID
fake_manager._create_from_source_volume(
self.ctxt, volume_obj, source_volume_id)
# Check if volume object is updated.
self.assertTrue(vol_update.called)
@mock.patch('cinder.volume.flows.manager.create_volume.'
'CreateVolumeFromSpecTask.'
'_cleanup_cg_in_volume')

1
cinder/volume/flows/manager/create_volume.py

@ -632,6 +632,7 @@ class CreateVolumeFromSpecTask(flow_utils.CinderTask):
if model_update is None:
model_update = {}
if volume.encryption_key_id is not None:
volume.update(model_update)
rekey_model_update = self._rekey_volume(context, volume)
model_update.update(rekey_model_update)
finally:

6
releasenotes/notes/cinder-clone-encrypted-a28338e2b1838a63.yaml

@ -0,0 +1,6 @@
---
fixes:
- |
`Bug #1913054 <https://bugs.launchpad.net/cinder/+bug/1913054>`_: Fix
for creating a clone of an encrypted volume for drivers that require
additional information to attach.
Loading…
Cancel
Save