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
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(