From e1f8b8ae7938758d5e04664d656950bdc3e13f5d Mon Sep 17 00:00:00 2001 From: huyang Date: Wed, 1 Mar 2017 09:28:34 +0800 Subject: [PATCH] Huawei driver supports front-end qos There's a parameter in QoS specs named "consumer" and it's default value is 'back-end'. When "consumer" is set to 'front-end'/'back-end', it should create a front-end/back-end QoS. Now Huawei Driver doesn't consider the "consumer" parameter, fix it. Change-Id: If76b7525b011c2576cfb669a4dc29ee1d6b870de Closes-bug:#1667875 (cherry picked from commit b268b842bd88b37ae1c0d8f6b29ae0e804776413) --- .../volume/drivers/huawei/test_huawei_drivers.py | 14 +++++++------- cinder/volume/drivers/huawei/constants.py | 1 + cinder/volume/drivers/huawei/smartx.py | 9 ++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/huawei/test_huawei_drivers.py b/cinder/tests/unit/volume/drivers/huawei/test_huawei_drivers.py index 4dce56b00..f346da6b9 100644 --- a/cinder/tests/unit/volume/drivers/huawei/test_huawei_drivers.py +++ b/cinder/tests/unit/volume/drivers/huawei/test_huawei_drivers.py @@ -2981,7 +2981,6 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase): self.assertEqual(test_info, pool_info) def test_get_smartx_specs_opts(self): - smartx_opts = smartx.SmartX().get_smartx_specs_opts(smarttier_opts) self.assertEqual('3', smartx_opts['policy']) @@ -2997,6 +2996,7 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase): self.assertDictEqual(expect_value, json.loads(lun_info['provider_location'])) + @ddt.data('front-end', 'back-end') @mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_volume_params', return_value={'smarttier': 'true', 'smartcache': 'true', @@ -3008,14 +3008,14 @@ class HuaweiISCSIDriverTestCase(HuaweiTestBase): 'partitionname': 'partition-test'}) @mock.patch.object(huawei_driver.HuaweiBaseDriver, '_get_volume_type', return_value={'qos_specs_id': u'025ce295-15e9-41a7'}) - @mock.patch.object(qos_specs, 'get_qos_specs', - return_value={'specs': {'maxBandWidth': '100', - 'IOType': '0'}, - 'consumer': 'back-end'}) def test_create_smartqos_success(self, + mock_consumer, mock_qos_specs, - mock_value_type, - mock_volume_params): + mock_value_type): + self.mock_object(qos_specs, 'get_qos_specs', + return_value={'specs': {'maxBandWidth': '100', + 'IOType': '0'}, + 'consumer': mock_consumer}) self.driver.support_func = FAKE_POOLS_SUPPORT_REPORT lun_info = self.driver.create_volume(self.volume) expect_value = {"huawei_lun_id": "1", diff --git a/cinder/volume/drivers/huawei/constants.py b/cinder/volume/drivers/huawei/constants.py index 6420b4987..097a407cc 100644 --- a/cinder/volume/drivers/huawei/constants.py +++ b/cinder/volume/drivers/huawei/constants.py @@ -19,6 +19,7 @@ STATUS_RUNNING = '10' STATUS_VOLUME_READY = '27' STATUS_LUNCOPY_READY = '40' STATUS_QOS_ACTIVE = '2' +STATUS_QOS_INACTIVE = '45' LUN_TYPE = '11' SNAPSHOT_TYPE = '27' diff --git a/cinder/volume/drivers/huawei/smartx.py b/cinder/volume/drivers/huawei/smartx.py index 2569e5707..490ec8b30 100644 --- a/cinder/volume/drivers/huawei/smartx.py +++ b/cinder/volume/drivers/huawei/smartx.py @@ -19,6 +19,7 @@ from oslo_utils import excutils from cinder import context from cinder import exception from cinder.i18n import _, _LI +from cinder import utils from cinder.volume.drivers.huawei import constants from cinder.volume import qos_specs @@ -44,6 +45,10 @@ class SmartQos(object): qos = {} io_type_flag = None ctxt = context.get_admin_context() + consumer = qos_specs.get_qos_specs(ctxt, qos_specs_id)['consumer'] + if consumer == 'front-end': + return {} + kvs = qos_specs.get_qos_specs(ctxt, qos_specs_id)['specs'] LOG.info(_LI('The QoS sepcs is: %s.'), kvs) for k, v in kvs.items(): @@ -96,6 +101,7 @@ class SmartQos(object): return False + @utils.synchronized('huawei_qos', external=True) def add(self, qos, lun_id): policy_id = None try: @@ -119,13 +125,14 @@ class SmartQos(object): if policy_id is not None: self.client.delete_qos_policy(policy_id) + @utils.synchronized('huawei_qos', external=True) def remove(self, qos_id, lun_id): qos_info = self.client.get_qos_info(qos_id) lun_list = self.client.get_lun_list_in_qos(qos_id, qos_info) if len(lun_list) <= 1: qos_status = qos_info['RUNNINGSTATUS'] # 2: Active status. - if qos_status == constants.STATUS_QOS_ACTIVE: + if qos_status != constants.STATUS_QOS_INACTIVE: self.client.activate_deactivate_qos(qos_id, False) self.client.delete_qos_policy(qos_id) else: