From: Wilson Liu Date: Tue, 23 Feb 2016 08:35:31 +0000 (+0800) Subject: Huawei: Check the real size before extend volume X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9de166725d863a858b6e334c5ff3e7895e4ffced;p=openstack-build%2Fcinder-build.git Huawei: Check the real size before extend volume Currently we not check the real size before we do the extend on array. But in fact, users may change the LUN size directly on the backend, not throuth Cinder api, although the LUN is created from Cinder side. Closes-Bug: #1548676 Change-Id: I093d23a7a18ec3f5b780095d31c795139dabd7a8 --- diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index c5e212797..c84612f60 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -2006,8 +2006,25 @@ class HuaweiISCSIDriverTestCase(test.TestCase): data = self.driver.get_volume_stats() self.assertEqual('2.0.5', data['driver_version']) - def test_extend_volume(self): + @mock.patch.object(rest_client.RestClient, 'get_lun_info', + return_value={"CAPACITY": 6291456}) + @mock.patch.object(rest_client.RestClient, 'extend_lun') + def test_extend_volume_size_equal(self, mock_extend, mock_lun_info): + self.driver.extend_volume(test_volume, 3) + self.assertEqual(0, mock_extend.call_count) + + @mock.patch.object(rest_client.RestClient, 'get_lun_info', + return_value={"CAPACITY": 5291456}) + @mock.patch.object(rest_client.RestClient, 'extend_lun') + def test_extend_volume_success(self, mock_extend, mock_lun_info): self.driver.extend_volume(test_volume, 3) + self.assertEqual(1, mock_extend.call_count) + + @mock.patch.object(rest_client.RestClient, 'get_lun_info', + return_value={"CAPACITY": 7291456}) + def test_extend_volume_fail(self, mock_lun_info): + self.assertRaises(exception.VolumeBackendAPIException, + self.driver.extend_volume, test_volume, 3) def test_login_fail(self): self.driver.client.test_fail = True diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index 2691cc09b..7a3cd2dca 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -691,8 +691,26 @@ class HuaweiBaseDriver(driver.VolumeDriver): LOG.error(msg) raise exception.VolumeBackendAPIException(data=msg) - old_size = huawei_utils.get_volume_size(volume) + lun_info = self.client.get_lun_info(lun_id) + old_size = int(lun_info.get('CAPACITY')) + new_size = int(new_size) * units.Gi / 512 + + if new_size == old_size: + LOG.info(_LI("New size is equal to the real size from backend" + " storage, no need to extend." + " realsize: %(oldsize)s, newsize: %(newsize)s."), + {'oldsize': old_size, + 'newsize': new_size}) + return + if new_size < old_size: + msg = (_("New size should be bigger than the real size from " + "backend storage." + " realsize: %(oldsize)s, newsize: %(newsize)s."), + {'oldsize': old_size, + 'newsize': new_size}) + LOG.error(msg) + raise exception.VolumeBackendAPIException(data=msg) volume_name = huawei_utils.encode_name(volume['id']) LOG.info(_LI(