]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Huawei: Check the real size before extend volume
authorWilson Liu <liuxinguo@huawei.com>
Tue, 23 Feb 2016 08:35:31 +0000 (16:35 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Thu, 3 Mar 2016 06:36:38 +0000 (14:36 +0800)
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

cinder/tests/unit/test_huawei_drivers.py
cinder/volume/drivers/huawei/huawei_driver.py

index c5e212797aa35030d880c084563c854320fde407..c84612f60232ce65efe39cf469542406810c99d8 100644 (file)
@@ -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
index 2691cc09bf5ee4de878241361e2a05dddb34248d..7a3cd2dca975c984efcbae609ff6019d5bcb78fa 100644 (file)
@@ -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(