From 04beea30c862d1f4e0d9b7edce9548c434bd7c3b Mon Sep 17 00:00:00 2001 From: Vadim Kryvian Date: Mon, 26 Jun 2017 10:20:47 +0300 Subject: [PATCH] IBM Storage: Fix for misidentification of QoS type There were case where QoS type identification was incorrect, causing QoS creation with incorrect type. Change-Id: I1a6e62c0b002dc021b8ccf5621444c0164a4f7f1 Closes-Bug: 1700358 --- .../unit/volume/drivers/ibm/test_xiv_proxy.py | 55 +++++++++++++++++++ .../drivers/ibm/ibm_storage/xiv_proxy.py | 10 +++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py index 6e478009544..c6d1dc424c3 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py @@ -699,6 +699,61 @@ class XIVProxyTest(test.TestCase): ex = getattr(p, "_get_exception")() self.assertRaises(ex, p._check_perf_class_on_backend, {'bw': '100'}) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_proxy.XIVProxy._qos_create_kwargs_for_xcli", + mock.MagicMock(return_value={})) + def test_regex_from_perf_class_name(self): + """Test type extraction from perf_class with Regex""" + driver = mock.MagicMock() + driver.VERSION = "VERSION" + + p = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver) + + perf_class_names_list = [ + {'class_name': 'cinder-qos_iops_1000_type_independent_bw_1000', + 'type': 'independent'}, + {'class_name': 'cinder-qos_iops_1000_bw_1000_type_shared', + 'type': 'shared'}, + {'class_name': 'cinder-qos_type_badtype_bw_1000', + 'type': None}] + + for element in perf_class_names_list: + _type = p._get_type_from_perf_class_name( + perf_class_name=element['class_name']) + self.assertEqual(element['type'], _type) + + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_proxy.XIVProxy._qos_create_kwargs_for_xcli", + mock.MagicMock(return_value={})) + def test_create_qos_class_with_type(self): + """Test performance class creation with type""" + driver = mock.MagicMock() + driver.VERSION = "VERSION" + + p = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver) + + p.ibm_storage_cli = mock.MagicMock() + p.ibm_storage_cli.cmd.perf_class_set_rate.return_value = None + p.ibm_storage_cli.cmd.perf_class_create.return_value = None + + perf_class_name = 'cinder-qos_iops_1000_type_independent_bw_1000' + p_class_name = p._create_qos_class(perf_class_name=perf_class_name, + specs=None) + + p.ibm_storage_cli.cmd.perf_class_create.assert_called_once_with( + perf_class=perf_class_name, + type='independent') + self.assertEqual('cinder-qos_iops_1000_type_independent_bw_1000', + p_class_name) + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." "xiv_proxy.XIVProxy._check_storage_version_for_qos_support", mock.MagicMock(return_value=True)) diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index 2b7f6854c75..6ee3c44b63f 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -14,9 +14,11 @@ # under the License. # import datetime +import re import six import socket + from oslo_log import log as logging from oslo_utils import importutils @@ -384,13 +386,17 @@ class XIVProxy(proxy.IBMStorageProxy): self._create_qos_class(perf_class_name, specs) return perf_class_name + def _get_type_from_perf_class_name(self, perf_class_name): + _type = re.findall('type_(independent|shared)', perf_class_name) + return _type[0] if _type else None + def _create_qos_class(self, perf_class_name, specs): """Create the qos class on the backend.""" try: # check if we have a shared (default) perf class # or an independent perf class - if 'type_' in perf_class_name: - _type = perf_class_name.split('type_')[1] + _type = self._get_type_from_perf_class_name(perf_class_name) + if _type: self._call_xiv_xcli("perf_class_create", perf_class=perf_class_name, type=_type)