Merge "XtremIO: allow a cloned volume with larger size"

This commit is contained in:
Jenkins 2017-03-14 02:00:41 +00:00 committed by Gerrit Code Review
commit 1133f8e656
2 changed files with 57 additions and 0 deletions

View File

@ -525,6 +525,52 @@ class XtremIODriverISCSITestCase(BaseXtremIODriverTestCase):
'provider_location': fake_provider}, 'provider_location': fake_provider},
update) update)
def test_clone_volume_and_resize(self, req):
req.side_effect = xms_request
self.driver.db = mock.Mock()
(self.driver.db.
image_volume_cache_get_by_volume_id.return_value) = mock.MagicMock()
self.driver.create_volume(self.data.test_volume)
vol = xms_data['volumes'][1]
vol['num-of-dest-snaps'] = 0
clone = self.data.test_clone.copy()
clone['size'] = 2
with mock.patch.object(self.driver,
'extend_volume') as extend:
self.driver.create_cloned_volume(clone, self.data.test_volume)
extend.assert_called_once_with(clone, clone['size'])
def test_clone_volume_and_resize_fail(self, req):
req.side_effect = xms_request
self.driver.create_volume(self.data.test_volume)
vol = xms_data['volumes'][1]
def failed_extend(obj_type='volumes', method='GET', data=None,
*args, **kwargs):
if method == 'GET':
return {'content': vol}
elif method == 'POST':
return {'links': [{'href': 'volume/2'}]}
elif method == 'PUT':
if 'name' in data:
return
raise exception.VolumeBackendAPIException('Failed Clone')
req.side_effect = failed_extend
self.driver.db = mock.Mock()
(self.driver.db.
image_volume_cache_get_by_volume_id.return_value) = mock.MagicMock()
vol['num-of-dest-snaps'] = 0
clone = self.data.test_clone.copy()
clone['size'] = 2
with mock.patch.object(self.driver,
'delete_volume') as delete:
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.create_cloned_volume,
clone,
self.data.test_volume)
self.assertTrue(delete.called)
# ##### Connection ##### # ##### Connection #####
def test_no_portals_configured(self, req): def test_no_portals_configured(self, req):
req.side_effect = xms_request req.side_effect = xms_request

View File

@ -460,6 +460,17 @@ class XtremIOVolumeDriver(san.SanDriver):
except exception.XtremIOSnapshotsLimitExceeded as e: except exception.XtremIOSnapshotsLimitExceeded as e:
raise exception.CinderException(e.message) raise exception.CinderException(e.message)
# extend the snapped volume if requested size is larger then original
if volume['size'] > src_vref['size']:
try:
self.extend_volume(volume, volume['size'])
except Exception:
LOG.error(_LE('failes to extend volume %s, '
'reverting clone operation'), volume['id'])
# remove the volume in case resize failed
self.delete_volume(volume)
raise
if volume.get('consistencygroup_id') and self.client is XtremIOClient4: if volume.get('consistencygroup_id') and self.client is XtremIOClient4:
self.client.add_vol_to_cg(volume['id'], self.client.add_vol_to_cg(volume['id'],
volume['consistencygroup_id']) volume['consistencygroup_id'])