diff --git a/cinder/tests/unit/test_hpe3par.py b/cinder/tests/unit/test_hpe3par.py index f337f5124cc..d47f1808e0d 100644 --- a/cinder/tests/unit/test_hpe3par.py +++ b/cinder/tests/unit/test_hpe3par.py @@ -2848,6 +2848,63 @@ class HPE3PARBaseDriver(object): None) self.assertEqual(expected_info, vlun_info) + def test_create_vlun_vlunid_zero(self): + # This will test "auto" for deactive when Lun ID is 0 + host = 'fake-host' + lun_id = 0 + nsp = '0:1:1' + port = {'node': 0, 'slot': 1, 'cardPort': 1} + + mock_client = self.setup_driver() + with mock.patch.object(hpecommon.HPE3PARCommon, + '_create_client') as mock_create_client: + mock_create_client.return_value = mock_client + + # _create_3par_vlun with nsp + location = ("%(name)s,%(lunid)s,%(host)s,%(nsp)s" % + {'name': self.VOLUME_NAME, + 'lunid': lun_id, + 'host': host, + 'nsp': nsp}) + mock_client.createVLUN.return_value = location + expected_info = {'volume_name': self.VOLUME_NAME, + 'lun_id': lun_id, + 'host_name': host, + 'nsp': nsp} + common = self.driver._login() + vlun_info = common._create_3par_vlun( + self.VOLUME_NAME, + host, + nsp, + lun_id=lun_id) + self.assertEqual(expected_info, vlun_info) + mock_client.createVLUN.assert_called_once_with(self.VOLUME_NAME, + hostname=host, + auto=False, + portPos=port, + lun=lun_id) + + # _create_3par_vlun without nsp + mock_client.reset_mock() + location = ("%(name)s,%(lunid)s,%(host)s" % + {'name': self.VOLUME_NAME, + 'lunid': lun_id, + 'host': host}) + mock_client.createVLUN.return_value = location + expected_info = {'volume_name': self.VOLUME_NAME, + 'lun_id': lun_id, + 'host_name': host} + vlun_info = common._create_3par_vlun( + self.VOLUME_NAME, + host, + None, + lun_id=lun_id) + self.assertEqual(expected_info, vlun_info) + mock_client.createVLUN.assert_called_once_with(self.VOLUME_NAME, + hostname=host, + auto=False, + lun=lun_id) + def test__get_existing_volume_ref_name(self): mock_client = self.setup_driver() with mock.patch.object(hpecommon.HPE3PARCommon, diff --git a/cinder/volume/drivers/hpe/hpe_3par_common.py b/cinder/volume/drivers/hpe/hpe_3par_common.py index 5960fe2956c..d7a869553bb 100644 --- a/cinder/volume/drivers/hpe/hpe_3par_common.py +++ b/cinder/volume/drivers/hpe/hpe_3par_common.py @@ -235,10 +235,11 @@ class HPE3PARCommon(object): 3.0.17 - Don't fail on clearing 3PAR object volume key. bug #1546392 3.0.18 - create_cloned_volume account for larger size. bug #1554740 3.0.19 - Remove metadata that tracks the instance ID. bug #1572665 + 3.0.20 - Fix lun_id of 0 issue. bug #1573298 """ - VERSION = "3.0.19" + VERSION = "3.0.20" stats = {} @@ -1116,7 +1117,7 @@ class HPE3PARCommon(object): location = None auto = True - if lun_id: + if lun_id is not None: auto = False if nsp is None: