From: Wilson Liu Date: Sat, 23 Jan 2016 02:58:46 +0000 (+0800) Subject: Add description when rename LUN in Huawei driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5e0bc7cb2eddcf7bdb6e6e7a6cf08d37aeff0042;p=openstack-build%2Fcinder-build.git Add description when rename LUN in Huawei driver Sometimes when we rename a LUN on the array, we should add some description to record some information like volume id on cinder side. This patch will enable this. Closes-Bug: #1537304 Change-Id: Ib156e61b5b1e305c41426cf5c6001dd44770140c --- diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index 6ea717e6b..0927c614a 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -3489,6 +3489,17 @@ class HuaweiFCDriverTestCase(test.TestCase): wwns = self.driver.client.get_online_free_wwns() self.assertEqual(['1'], wwns) + @mock.patch.object(rest_client.RestClient, 'call', + return_value={"data": {"ID": 1}, "error": {"code": 0}}) + def test_rename_lun(self, mock_call): + des = 'This LUN is renamed.' + new_name = 'test_name' + self.driver.client.rename_lun('1', new_name, des) + self.assertEqual(1, mock_call.call_count) + url = "/lun/1" + data = {"NAME": new_name, "DESCRIPTION": des} + mock_call.assert_called_once_with(url, data, "PUT") + class HuaweiConfTestCase(test.TestCase): def setUp(self): diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index 80e02b600..c67b65c90 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -1219,8 +1219,7 @@ class HuaweiBaseDriver(driver.VolumeDriver): LOG.debug("Rename LUN %(old_name)s to %(new_name)s.", {'old_name': lun_info.get('NAME'), 'new_name': new_name}) - self.client.rename_lun(lun_id, new_name, # pylint: disable=E1121 - description) + self.client.rename_lun(lun_id, new_name, description) model_update = {} model_update.update({'provider_location': lun_id}) diff --git a/cinder/volume/drivers/huawei/rest_client.py b/cinder/volume/drivers/huawei/rest_client.py index 90e85eae9..4ca4cfda8 100644 --- a/cinder/volume/drivers/huawei/rest_client.py +++ b/cinder/volume/drivers/huawei/rest_client.py @@ -1635,9 +1635,11 @@ class RestClient(object): return initiators - def rename_lun(self, lun_id, new_name): + def rename_lun(self, lun_id, new_name, description=None): url = "/lun/" + lun_id data = {"NAME": new_name} + if description: + data.update({"DESCRIPTION": description}) result = self.call(url, data, "PUT") msg = _('Rename lun on array error.') self._assert_rest_result(result, msg)