From 74d67bc4f829100a2a3f1d6a5eda5c1ab5795d94 Mon Sep 17 00:00:00 2001 From: Matan Sabag Date: Sun, 13 Mar 2016 04:19:49 -0700 Subject: [PATCH] Fix ScaleIO driver does not honor clone size Fixed a bug that when creating a volume from source the driver didn't honor the new volume size. Added unit test. Change-Id: I3a39953002432ac70a4ee2eccedd6737d9c3b019 Closes-Bug: #1554777 --- .../emc/scaleio/test_create_cloned_volume.py | 5 ++++ .../drivers/emc/scaleio/test_extend_volume.py | 2 +- cinder/volume/drivers/emc/scaleio.py | 30 +++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/emc/scaleio/test_create_cloned_volume.py b/cinder/tests/unit/volume/drivers/emc/scaleio/test_create_cloned_volume.py index a2ff534d6..e9ad27ec4 100644 --- a/cinder/tests/unit/volume/drivers/emc/scaleio/test_create_cloned_volume.py +++ b/cinder/tests/unit/volume/drivers/emc/scaleio/test_create_cloned_volume.py @@ -98,3 +98,8 @@ class TestCreateClonedVolume(scaleio.TestScaleIODriver): def test_create_cloned_volume(self): self.set_https_response_mode(self.RESPONSE_MODE.Valid) self.driver.create_cloned_volume(self.new_volume, self.src_volume) + + def test_create_cloned_volume_larger_size(self): + self.set_https_response_mode(self.RESPONSE_MODE.Valid) + self.new_volume.size = 2 + self.driver.create_cloned_volume(self.new_volume, self.src_volume) diff --git a/cinder/tests/unit/volume/drivers/emc/scaleio/test_extend_volume.py b/cinder/tests/unit/volume/drivers/emc/scaleio/test_extend_volume.py index 2b1ab30d3..2b704f958 100644 --- a/cinder/tests/unit/volume/drivers/emc/scaleio/test_extend_volume.py +++ b/cinder/tests/unit/volume/drivers/emc/scaleio/test_extend_volume.py @@ -52,7 +52,7 @@ class TestExtendVolume(scaleio.TestScaleIODriver): self.volume_name_2x_enc: '"{}"'.format(self.volume.id), 'instances/Volume::{}/action/setVolumeSize'.format( self.volume.provider_id - ): 'OK', + ): mocks.MockHTTPSResponse({}, 200), }, self.RESPONSE_MODE.BadStatus: { 'types/Volume/instances/getByName::' + diff --git a/cinder/volume/drivers/emc/scaleio.py b/cinder/volume/drivers/emc/scaleio.py index 3ee76b8c4..e0b754f97 100644 --- a/cinder/volume/drivers/emc/scaleio.py +++ b/cinder/volume/drivers/emc/scaleio.py @@ -537,12 +537,15 @@ class ScaleIODriver(driver.VolumeDriver): This action will round up the volume to the nearest size that is a granularity of 8 GBs. """ - vol_id = volume['provider_id'] + return self._extend_volume(volume['provider_id'], volume.size, + new_size) + + def _extend_volume(self, volume_id, old_size, new_size): + vol_id = volume_id LOG.info(_LI( - "ScaleIO extend volume:" - " volume %(volname)s to size %(new_size)s."), - {'volname': vol_id, - 'new_size': new_size}) + "ScaleIO extend volume: volume %(volname)s to size %(new_size)s."), + {'volname': vol_id, + 'new_size': new_size}) req_vars = {'server_ip': self.server_ip, 'server_port': self.server_port, @@ -555,7 +558,7 @@ class ScaleIODriver(driver.VolumeDriver): # Round up the volume size so that it is a granularity of 8 GBs # because ScaleIO only supports volumes with a granularity of 8 GBs. volume_new_size = self._round_to_8_gran(new_size) - volume_real_old_size = self._round_to_8_gran(volume.size) + volume_real_old_size = self._round_to_8_gran(old_size) if volume_real_old_size == volume_new_size: return @@ -566,14 +569,7 @@ class ScaleIODriver(driver.VolumeDriver): volume_new_size) params = {'sizeInGB': six.text_type(volume_new_size)} - r = requests.post( - request, - data=json.dumps(params), - headers=self._get_headers(), - auth=(self.server_username, - self.server_token), - verify=self._get_verify_cert()) - r = self._check_response(r, request, False, params) + r, response = self._execute_scaleio_post_request(params, request) if r.status_code != OK_STATUS_CODE: response = r.json() @@ -598,7 +594,11 @@ class ScaleIODriver(driver.VolumeDriver): {'src': volume_id, 'tgt': snapname}) - return self._snapshot_volume(volume_id, snapname) + ret = self._snapshot_volume(volume_id, snapname) + if volume.size > src_vref.size: + self._extend_volume(ret['provider_id'], src_vref.size, volume.size) + + return ret def delete_volume(self, volume): """Deletes a self.logical volume""" -- 2.45.2