diff --git a/cinder/tests/unit/volume/drivers/emc/test_emc_vmax.py b/cinder/tests/unit/volume/drivers/emc/test_emc_vmax.py index a035d96f2..c245e4b0d 100644 --- a/cinder/tests/unit/volume/drivers/emc/test_emc_vmax.py +++ b/cinder/tests/unit/volume/drivers/emc/test_emc_vmax.py @@ -5853,7 +5853,7 @@ class EMCV3DriverTestCase(test.TestCase): def set_configuration(self): configuration = mock.Mock() configuration.cinder_emc_config_file = self.config_file_path - configuration.safe_get.return_value = 3 + configuration.safe_get.return_value = 'EMCV3DriverTests' configuration.config_group = 'V3' self.mock_object(emc_vmax_common.EMCVMAXCommon, '_get_ecom_connection', @@ -6073,8 +6073,8 @@ class EMCV3DriverTestCase(test.TestCase): emc_vmax_utils.EMCVMAXUtils, 'find_storageSystem', return_value={'Name': EMCVMAXCommonData.storage_system_v3}) - def test_get_volume_stats_v3( - self, mock_storage_system): + def test_get_volume_stats_v3(self, mock_storage_system): + self.driver.common.pool_info['reserved_percentage'] = 5 self.driver.get_volume_stats(True) @mock.patch.object( @@ -8759,3 +8759,91 @@ class EMCVMAXISCSITest(test.TestCase): properties['target_iqns']) self.assertEqual(['10.10.0.50:3260', '10.10.0.51:3260'], properties['target_portals']) + + +class VMAXInitiatorCheckFalseTest(test.TestCase): + def setUp(self): + self.data = EMCVMAXCommonData() + + super(VMAXInitiatorCheckFalseTest, self).setUp() + + configuration = mock.Mock() + configuration.safe_get.return_value = 'initiatorCheckTest' + configuration.config_group = 'initiatorCheckTest' + + emc_vmax_common.EMCVMAXCommon._gather_info = mock.Mock() + instancename = FakeCIMInstanceName() + self.mock_object(emc_vmax_utils.EMCVMAXUtils, 'get_instance_name', + instancename.fake_getinstancename) + self.mock_object(emc_vmax_common.EMCVMAXCommon, '_get_ecom_connection', + FakeEcomConnection()) + self.mock_object(emc_vmax_utils.EMCVMAXUtils, + 'find_controller_configuration_service', + return_value=None) + driver = emc_vmax_iscsi.EMCVMAXISCSIDriver(configuration=configuration) + driver.db = FakeDB() + self.driver = driver + + @mock.patch.object( + emc_vmax_common.EMCVMAXCommon, + '_find_lun', + return_value=( + {'SystemName': EMCVMAXCommonData.storage_system})) + def test_populate_masking_dict(self, mock_find_lun): + extraSpecs = {'storagetype:pool': u'SRP_1', + 'volume_backend_name': 'INITIATOR_BE', + 'storagetype:array': u'1234567891011', + 'isV3': True, + 'portgroupname': u'OS-portgroup-PG', + 'storagetype:slo': u'Diamond', + 'storagetype:workload': u'DSS'} + connector = self.data.connector + maskingViewDict = self.driver.common._populate_masking_dict( + self.data.test_volume, connector, extraSpecs) + self.assertFalse(maskingViewDict['initiatorCheck']) + + +class VMAXInitiatorCheckTrueTest(test.TestCase): + def setUp(self): + self.data = EMCVMAXCommonData() + + super(VMAXInitiatorCheckTrueTest, self).setUp() + + self.configuration = mock.Mock( + initiator_check='True', + config_group='initiatorCheckTest') + + def safe_get(key): + return getattr(self.configuration, key) + self.configuration.safe_get = safe_get + emc_vmax_common.EMCVMAXCommon._gather_info = mock.Mock() + instancename = FakeCIMInstanceName() + self.mock_object(emc_vmax_utils.EMCVMAXUtils, 'get_instance_name', + instancename.fake_getinstancename) + self.mock_object(emc_vmax_common.EMCVMAXCommon, '_get_ecom_connection', + FakeEcomConnection()) + self.mock_object(emc_vmax_utils.EMCVMAXUtils, + 'find_controller_configuration_service', + return_value=None) + driver = emc_vmax_iscsi.EMCVMAXISCSIDriver( + configuration=self.configuration) + driver.db = FakeDB() + self.driver = driver + + @mock.patch.object( + emc_vmax_common.EMCVMAXCommon, + '_find_lun', + return_value=( + {'SystemName': EMCVMAXCommonData.storage_system})) + def test_populate_masking_dict(self, mock_find_lun): + extraSpecs = {'storagetype:pool': u'SRP_1', + 'volume_backend_name': 'INITIATOR_BE', + 'storagetype:array': u'1234567891011', + 'isV3': True, + 'portgroupname': u'OS-portgroup-PG', + 'storagetype:slo': u'Diamond', + 'storagetype:workload': u'DSS'} + connector = self.data.connector + maskingViewDict = self.driver.common._populate_masking_dict( + self.data.test_volume, connector, extraSpecs) + self.assertTrue(maskingViewDict['initiatorCheck']) diff --git a/cinder/volume/drivers/emc/emc_vmax_common.py b/cinder/volume/drivers/emc/emc_vmax_common.py index e8dd71b6a..289f3196b 100644 --- a/cinder/volume/drivers/emc/emc_vmax_common.py +++ b/cinder/volume/drivers/emc/emc_vmax_common.py @@ -77,8 +77,12 @@ SNAPVX_REPLICATION_TYPE = 6 emc_opts = [ cfg.StrOpt('cinder_emc_config_file', default=CINDER_EMC_CONFIG_FILE, - help='use this file for cinder emc plugin ' - 'config data'), ] + help='Use this file for cinder emc plugin ' + 'config data'), + cfg.StrOpt('initiator_check', + default=False, + help='Use this value to enable ' + 'the initiator_check')] CONF.register_opts(emc_opts) @@ -127,6 +131,7 @@ class EMCVMAXCommon(object): self.provision = emc_vmax_provision.EMCVMAXProvision(prtcl) self.provisionv3 = emc_vmax_provision_v3.EMCVMAXProvisionV3(prtcl) self.version = version + self.initiatorCheck = False self._gather_info() def _gather_info(self): @@ -1355,6 +1360,21 @@ class EMCVMAXCommon(object): configGroup) return extraSpecs, configurationFile, qosSpecs + def _get_initiator_check_flag(self): + """Reads the configuration for initator_check flag. + + :returns: flag + """ + + confString = ( + self.configuration.safe_get('initiator_check')) + retVal = False + stringTrue = "True" + if confString: + if confString.lower() == stringTrue.lower(): + retVal = True + return retVal + def _get_ecom_connection(self): """Get the ecom connection. @@ -1925,6 +1945,10 @@ class EMCVMAXCommon(object): maskingViewDict['volumeInstance'] = volumeInstance maskingViewDict['volumeName'] = volumeName maskingViewDict['storageSystemName'] = storageSystemName + if self._get_initiator_check_flag(): + maskingViewDict['initiatorCheck'] = True + else: + maskingViewDict['initiatorCheck'] = False return maskingViewDict diff --git a/cinder/volume/drivers/emc/emc_vmax_masking.py b/cinder/volume/drivers/emc/emc_vmax_masking.py index 7678836b0..7eadc77a3 100644 --- a/cinder/volume/drivers/emc/emc_vmax_masking.py +++ b/cinder/volume/drivers/emc/emc_vmax_masking.py @@ -335,14 +335,16 @@ class EMCVMAXMasking(object): connector = maskingViewDict['connector'] storageSystemName = maskingViewDict['storageSystemName'] maskingViewName = maskingViewDict['maskingViewName'] + checkInitiator = maskingViewDict['initiatorCheck'] # First verify that the initiator group matches the initiators. - errorMessage = self._check_existing_initiator_group( - conn, controllerConfigService, maskingViewName, - connector, storageSystemName, igGroupName, extraSpecs) + if checkInitiator: + errorMessage = self._check_existing_initiator_group( + conn, controllerConfigService, maskingViewName, + connector, storageSystemName, igGroupName, extraSpecs) - if errorMessage: - return storageGroupInstanceName, errorMessage + if errorMessage: + return storageGroupInstanceName, errorMessage storageGroupInstanceName, errorMessage = ( self._check_existing_storage_group(