Merge "Add provider_location to cloned volume"
This commit is contained in:
commit
4c9a37b4f1
@ -6401,6 +6401,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,
|
||||
|
@ -1351,15 +1351,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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user