Add provider_location to cloned volume

Forced backup was failing when the driver returned a 'provider_location'
for a cloned volume, because the return value for create_cloned_volume()
was ignored in _create_temp_cloned_volume().

Change-Id: I709996316e4c212243629e461d36da4152e995e4
Closes-Bug: 1573126
(cherry picked from commit 616a2bd34d)
This commit is contained in:
Ollie Leahy 2016-04-21 17:19:16 +01:00
parent 4dbaf981cf
commit d6a502b74d
2 changed files with 28 additions and 4 deletions

View File

@ -6360,6 +6360,26 @@ class GenericVolumeDriverTestCase(DriverTestCase):
mock_volume_get.assert_called_with(self.context, vol['id'])
def test_create_temp_cloned_volume(self):
with mock.patch.object(
self.volume.driver,
'create_cloned_volume') as mock_create_cloned_volume:
model_update = {'provider_location': 'dummy'}
mock_create_cloned_volume.return_value = model_update
vol = tests_utils.create_volume(self.context,
status='backing-up')
cloned_vol = self.volume.driver._create_temp_cloned_volume(
self.context, vol)
self.assertEqual('dummy', cloned_vol['provider_location'])
self.assertEqual('available', cloned_vol['status'])
mock_create_cloned_volume.return_value = None
vol = tests_utils.create_volume(self.context,
status='backing-up')
cloned_vol = self.volume.driver._create_temp_cloned_volume(
self.context, vol)
self.assertEqual('available', cloned_vol['status'])
@mock.patch.object(utils, 'temporary_chown')
@mock.patch('six.moves.builtins.open')
@mock.patch.object(os_brick.initiator.connector,

View File

@ -1348,15 +1348,19 @@ class BaseVD(object):
}
temp_vol_ref = self.db.volume_create(context, temp_volume)
try:
self.create_cloned_volume(temp_vol_ref, volume)
# Some drivers return None, because they do not need to update the
# model for the volume. For those cases we set the model_update to
# an empty dictionary.
model_update = self.create_cloned_volume(temp_vol_ref,
volume) or {}
except Exception:
with excutils.save_and_reraise_exception():
self.db.volume_destroy(context.elevated(),
temp_vol_ref['id'])
self.db.volume_update(context, temp_vol_ref['id'],
{'status': 'available'})
return temp_vol_ref
model_update['status'] = 'available'
self.db.volume_update(context, temp_vol_ref['id'], model_update)
return self.db.volume_get(context, temp_vol_ref['id'])
def _create_temp_volume_from_snapshot(self, context, volume, snapshot):
temp_volume = {