From b8b5de985359fe07f235e8c10f375246b1608fbb Mon Sep 17 00:00:00 2001 From: Yong Huang Date: Thu, 7 Jun 2018 14:39:13 +0800 Subject: [PATCH] Empty option value maybe cause Unity driver failed to initialize If the value of list type option is empty, Unity driver may failed to initialize. Example: unity_io_ports= unity_storage_pool_names= Change-Id: Ib5850d984bfd3651d308f448993251e9ec5a9460 Closes-bug: #1775518 (cherry picked from commit 2ecfd6144ba79334740407241c8fa5d7ad928840) (cherry picked from commit c7f9d29e17523653b7d2f0eb2b109798235b6ebb) --- .../drivers/dell_emc/unity/test_driver.py | 3 ++- .../drivers/dell_emc/unity/test_utils.py | 21 +++++++++++++++++++ .../volume/drivers/dell_emc/unity/driver.py | 9 +++++--- cinder/volume/drivers/dell_emc/unity/utils.py | 5 +++-- ...ity-empty-list-issue-2d6b7c33aae1ffcc.yaml | 6 ++++++ 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/bug-1775518-fix-unity-empty-list-issue-2d6b7c33aae1ffcc.yaml diff --git a/cinder/tests/unit/volume/drivers/dell_emc/unity/test_driver.py b/cinder/tests/unit/volume/drivers/dell_emc/unity/test_driver.py index 3cb44c593c2..49f35890724 100644 --- a/cinder/tests/unit/volume/drivers/dell_emc/unity/test_driver.py +++ b/cinder/tests/unit/volume/drivers/dell_emc/unity/test_driver.py @@ -129,7 +129,8 @@ class UnityDriverTest(unittest.TestCase): def test_default_initialize(self): config = conf.Configuration(None) iscsi_driver = driver.UnityDriver(configuration=config) - self.assertIsNone(config.unity_storage_pool_names) + self.assertListEqual([], config.unity_storage_pool_names) + self.assertListEqual([], config.unity_io_ports) self.assertTrue(config.san_thin_provision) self.assertEqual('', config.san_ip) self.assertEqual('admin', config.san_login) diff --git a/cinder/tests/unit/volume/drivers/dell_emc/unity/test_utils.py b/cinder/tests/unit/volume/drivers/dell_emc/unity/test_utils.py index 7eb0c2fcc39..9558576e785 100644 --- a/cinder/tests/unit/volume/drivers/dell_emc/unity/test_utils.py +++ b/cinder/tests/unit/volume/drivers/dell_emc/unity/test_utils.py @@ -254,3 +254,24 @@ class UnityUtilsTest(unittest.TestCase): ret = utils.get_backend_qos_specs(volume) expected = {'maxBWS': 2, 'id': 'max_2_mbps', 'maxIOPS': None} self.assertEqual(expected, ret) + + def test_remove_empty(self): + option = mock.Mock() + value_list = [' pool1', 'pool2 ', ' pool3 '] + ret = utils.remove_empty(option, value_list) + expected = ['pool1', 'pool2', 'pool3'] + self.assertListEqual(expected, ret) + + def test_remove_empty_none(self): + option = mock.Mock() + value_list = None + ret = utils.remove_empty(option, value_list) + expected = None + self.assertEqual(expected, ret) + + def test_remove_empty_empty_list(self): + option = mock.Mock() + value_list = [] + ret = utils.remove_empty(option, value_list) + expected = None + self.assertEqual(expected, ret) diff --git a/cinder/volume/drivers/dell_emc/unity/driver.py b/cinder/volume/drivers/dell_emc/unity/driver.py index f52d3746c1f..ddd19945f2a 100644 --- a/cinder/volume/drivers/dell_emc/unity/driver.py +++ b/cinder/volume/drivers/dell_emc/unity/driver.py @@ -31,11 +31,11 @@ CONF = cfg.CONF UNITY_OPTS = [ cfg.ListOpt('unity_storage_pool_names', - default=None, + default=[], help='A comma-separated list of storage pool names to be ' 'used.'), cfg.ListOpt('unity_io_ports', - default=None, + default=[], help='A comma-separated list of iSCSI or FC ports to be used. ' 'Each port can be Unix-style glob expressions.'), cfg.BoolOpt('remove_empty_host', @@ -63,9 +63,12 @@ class UnityDriver(driver.ManageableVD, 2.0.2 - Support remove empty host 2.0.3 - Cherry-pick the fix for 1773305 to return the targets which connect to the logged-out initiators + 2.0.4 - Fixes bug 1775518 to make sure driver succeed to initialize + even though the value of unity_io_ports and + unity_storage_pool_names are empty """ - VERSION = '02.00.03' + VERSION = '02.00.04' VENDOR = 'Dell EMC' # ThirdPartySystems wiki page CI_WIKI_NAME = "EMC_UNITY_CI" diff --git a/cinder/volume/drivers/dell_emc/unity/utils.py b/cinder/volume/drivers/dell_emc/unity/utils.py index 0aecdcc834d..05e508950af 100644 --- a/cinder/volume/drivers/dell_emc/unity/utils.py +++ b/cinder/volume/drivers/dell_emc/unity/utils.py @@ -270,12 +270,13 @@ def get_backend_qos_specs(volume): def remove_empty(option, value_list): - if value_list is not None: + if value_list: value_list = list(filter(None, map(str.strip, value_list))) if not value_list: raise exception.InvalidConfigurationValue(option=option, value=value_list) - return value_list + return value_list + return None def match_any(full, patterns): diff --git a/releasenotes/notes/bug-1775518-fix-unity-empty-list-issue-2d6b7c33aae1ffcc.yaml b/releasenotes/notes/bug-1775518-fix-unity-empty-list-issue-2d6b7c33aae1ffcc.yaml new file mode 100644 index 00000000000..93b1db73226 --- /dev/null +++ b/releasenotes/notes/bug-1775518-fix-unity-empty-list-issue-2d6b7c33aae1ffcc.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Dell EMC Unity: Fixes bug 1775518 to make sure driver succeed + to initialize even though the value of unity_io_ports and + unity_storage_pool_names are empty