From 6fee4e260c2c4e9418bab8c9bf8c19d47840a0e3 Mon Sep 17 00:00:00 2001 From: Kumar Prashant Date: Tue, 18 Sep 2018 11:59:22 +0530 Subject: [PATCH] VMAX Driver - Fix for invalid device id length The external reference supplied while managing an existing device should be of exactly 5 digits as device ids on the VMAX array are of exactly 5 digits. The VMAX driver should perform a check and throw appropriate error. Change-Id: I06cc3e107a5b07f8f00e9a9a025a0152199092df Closes-bug: 1792889 --- .../volume/drivers/dell_emc/vmax/test_vmax.py | 21 +++++++++++++++++++ cinder/volume/drivers/dell_emc/vmax/utils.py | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/cinder/tests/unit/volume/drivers/dell_emc/vmax/test_vmax.py b/cinder/tests/unit/volume/drivers/dell_emc/vmax/test_vmax.py index 6f9779c95b0..b609931ff2c 100644 --- a/cinder/tests/unit/volume/drivers/dell_emc/vmax/test_vmax.py +++ b/cinder/tests/unit/volume/drivers/dell_emc/vmax/test_vmax.py @@ -19,6 +19,8 @@ import datetime import platform import time +from ddt import data +from ddt import ddt import mock import requests import six @@ -49,6 +51,7 @@ from cinder.volume import utils as volume_utils from cinder.volume import volume_types from cinder.zonemanager import utils as fczm_utils + CINDER_EMC_CONFIG_DIR = '/etc/cinder/' @@ -1259,6 +1262,7 @@ class FakeConfiguration(object): pass +@ddt class VMAXUtilsTest(test.TestCase): def setUp(self): self.data = VMAXCommonData() @@ -1412,6 +1416,23 @@ class VMAXUtilsTest(test.TestCase): self.utils.get_array_and_device_id, volume, external_ref) + @data({u'source-name': u'000001'}, {u'source-name': u'00028A'}) + def test_get_array_and_device_id_invalid_long_id(self, external_ref): + volume = deepcopy(self.data.test_volume) + # Test for device id more than 5 digits + self.assertRaises(exception.VolumeBackendAPIException, + self.utils.get_array_and_device_id, + volume, external_ref) + + @data({u'source-name': u'01'}, {u'source-name': u'028A'}, + {u'source-name': u'0001'}) + def test_get_array_and_device_id_invalid_short_id(self, external_ref): + volume = deepcopy(self.data.test_volume) + # Test for device id less than 5 digits + self.assertRaises(exception.VolumeBackendAPIException, + self.utils.get_array_and_device_id, + volume, external_ref) + def test_get_pg_short_name(self): pg_under_12_chars = 'pg_11_chars' pg1 = self.utils.get_pg_short_name(pg_under_12_chars) diff --git a/cinder/volume/drivers/dell_emc/vmax/utils.py b/cinder/volume/drivers/dell_emc/vmax/utils.py index 7543d358335..1a14aa1c473 100644 --- a/cinder/volume/drivers/dell_emc/vmax/utils.py +++ b/cinder/volume/drivers/dell_emc/vmax/utils.py @@ -338,6 +338,13 @@ class VMAXUtils(object): array = host_list[(len(host_list) - 1)] if device_id: + if len(device_id) != 5: + error_message = (_("Device ID: %(device_id)s is invalid. " + "Device ID should be exactly 5 digits.") % + {'device_id': device_id}) + LOG.error(error_message) + raise exception.VolumeBackendAPIException( + message=error_message) LOG.debug("Get device ID of existing volume - device ID: " "%(device_id)s, Array: %(array)s.", {'device_id': device_id,