From c3d4917d9cfbe03fe40e0c99bd148fa3c526d4bb Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Fri, 20 Feb 2015 01:57:05 -0500 Subject: [PATCH] i18n Compatibility in VMAX driver The patch fixed some message formatting issues according to the i18n guidelines in the VMAX driver. Change-Id: I5c1d2ec640d26c026bda89061e416fe7b136eaac --- cinder/volume/drivers/emc/emc_vmax_common.py | 63 ++++++++++++------- cinder/volume/drivers/emc/emc_vmax_fast.py | 30 +++++---- cinder/volume/drivers/emc/emc_vmax_https.py | 3 +- .../drivers/emc/emc_vmax_provision_v3.py | 4 +- cinder/volume/drivers/emc/emc_vmax_utils.py | 23 +++++-- 5 files changed, 83 insertions(+), 40 deletions(-) diff --git a/cinder/volume/drivers/emc/emc_vmax_common.py b/cinder/volume/drivers/emc/emc_vmax_common.py index 73d3bcd89..f0438a62a 100644 --- a/cinder/volume/drivers/emc/emc_vmax_common.py +++ b/cinder/volume/drivers/emc/emc_vmax_common.py @@ -1091,7 +1091,9 @@ class EMCVMAXCommon(object): foundStorageGroupInstanceName) emcFastSetting = self.utils._get_fast_settings_from_storage_group( storageGroupInstance) - targetCombination = targetSlo + '+' + targetWorkload + targetCombination = ("%(targetSlo)s+%(targetWorkload)s" + % {'targetSlo': targetSlo, + 'targetWorkload': targetWorkload}) if targetCombination in emcFastSetting: LOG.error(_LE( "No action required. Volume: %(volumeName)s is " @@ -1544,15 +1546,19 @@ class EMCVMAXCommon(object): configurationFile = self.configuration.cinder_emc_config_file else: configurationFile = ( - CINDER_EMC_CONFIG_FILE_PREFIX + configGroupName + - CINDER_EMC_CONFIG_FILE_POSTFIX) + ("%(prefix)s%(configGroupName)s%(postfix)s" + % {'prefix': CINDER_EMC_CONFIG_FILE_PREFIX, + 'configGroupName': configGroupName, + 'postfix': CINDER_EMC_CONFIG_FILE_POSTFIX})) # The file saved in self.configuration may not be the correct one, # double check. if configGroupName not in configurationFile: configurationFile = ( - CINDER_EMC_CONFIG_FILE_PREFIX + configGroupName + - CINDER_EMC_CONFIG_FILE_POSTFIX) + ("%(prefix)s%(configGroupName)s%(postfix)s" + % {'prefix': CINDER_EMC_CONFIG_FILE_PREFIX, + 'configGroupName': configGroupName, + 'postfix': CINDER_EMC_CONFIG_FILE_POSTFIX})) self._set_ecom_credentials(configurationFile) return configurationFile @@ -1577,10 +1583,15 @@ class EMCVMAXCommon(object): self.user, self.passwd = self.utils.get_ecom_cred(configurationFile) self.ecomUseSSL, self.ecomCACert, self.ecomNoVerification = ( self.utils.get_ecom_cred_SSL(configurationFile)) + ip_port = ("%(ip)s:%(port)s" + % {'ip': ip, + 'port': port}) if self.ecomUseSSL: - self.url = 'https://' + ip + ':' + port + self.url = ("https://%(ip_port)s" + % {'ip_port': ip_port}) else: - self.url = 'http://' + ip + ':' + port + self.url = ("http://%(ip_port)s" + % {'ip_port': ip_port}) self.conn = self._get_ecom_connection() def _initial_setup(self, volume, volumeTypeId=None): @@ -1681,23 +1692,27 @@ class EMCVMAXCommon(object): maskingViewDict['slo'] = slo maskingViewDict['workload'] = workload maskingViewDict['pool'] = poolName - maskingViewDict['sgGroupName'] = ( - 'OS-' + shortHostName + '-' + poolName + '-' + slo + '-' + - workload + '-SG') - maskingViewDict['maskingViewName'] = ( - 'OS-' + shortHostName + '-' + poolName + '-' + slo + '-' + - workload + '-MV') + prefix = ( + ("OS-%(shortHostName)s-%(poolName)s-%(slo)s-%(workload)s" + % {'shortHostName': shortHostName, + 'poolName': poolName, + 'slo': slo, + 'workload': workload})) else: - maskingViewDict['sgGroupName'] = ( - 'OS-' + shortHostName + '-' + poolName + '-' + - protocol + '-SG') - maskingViewDict['maskingViewName'] = ( - 'OS-' + shortHostName + '-' + poolName + '-' + - protocol + '-MV') + prefix = ( + ("OS-%(shortHostName)s-%(poolName)s-%(protocol)s" + % {'shortHostName': shortHostName, + 'poolName': poolName, + 'protocol': protocol})) maskingViewDict['fastPolicy'] = ( self.utils.parse_fast_policy_name_from_file( self.configuration.cinder_emc_config_file)) + maskingViewDict['sgGroupName'] = ("%(prefix)s-SG" + % {'prefix': prefix}) + + maskingViewDict['maskingViewName'] = ("%(prefix)s-MV" + % {'prefix': prefix}) volumeName = volume['name'] volumeInstance = self._find_lun(volume) storageSystemName = volumeInstance['SystemName'] @@ -1711,7 +1726,9 @@ class EMCVMAXCommon(object): self.configuration.cinder_emc_config_file)) maskingViewDict['igGroupName'] = ( - 'OS-' + shortHostName + '-' + protocol + '-IG') + ("OS-%(shortHostName)s-%(protocol)s-IG" + % {'shortHostName': shortHostName, + 'protocol': protocol})) maskingViewDict['connector'] = connector maskingViewDict['volumeInstance'] = volumeInstance maskingViewDict['volumeName'] = volumeName @@ -2241,8 +2258,8 @@ class EMCVMAXCommon(object): "Replication Service: %(service)s Operation: 8 " "Synchronization: %(syncName)s.", {'snapshot': snapshotname, - 'service': str(repservice), - 'syncName': str(syncName)}) + 'service': repservice, + 'syncName': syncName}) self.provision.delete_clone_relationship( self.conn, repservice, syncName, self.extraSpecs, True) @@ -3524,7 +3541,7 @@ class EMCVMAXCommon(object): LOG.info(_LI("Target wwns in masking view %(maskingView)s: " "%(targetWwns)s."), {'maskingView': mvInstanceName, - 'targetWwns': str(targetWwns)}) + 'targetWwns': six.text_type(targetWwns)}) return targetWwns def get_port_group_from_masking_view(self, maskingViewInstanceName): diff --git a/cinder/volume/drivers/emc/emc_vmax_fast.py b/cinder/volume/drivers/emc/emc_vmax_fast.py index 155f3bc3d..4515b6444 100644 --- a/cinder/volume/drivers/emc/emc_vmax_fast.py +++ b/cinder/volume/drivers/emc/emc_vmax_fast.py @@ -117,12 +117,11 @@ class EMCVMAXFast(object): assocStorageGroupInstanceName = ( self.utils.get_storage_group_from_volume(conn, volumeInstanceName)) - defaultSgGroupName = (DEFAULT_SG_PREFIX + fastPolicyName + - DEFAULT_SG_POSTFIX) + defaultSgName = self._format_default_sg_string(fastPolicyName) defaultStorageGroupInstanceName = ( self.utils.find_storage_masking_group(conn, controllerConfigService, - defaultSgGroupName)) + defaultSgName)) if defaultStorageGroupInstanceName is None: LOG.error(_LE( "Unable to find default storage group " @@ -138,9 +137,20 @@ class EMCVMAXFast(object): "Volume: %(volumeName)s Does not belong " "to storage storage group %(defaultSgGroupName)s."), {'volumeName': volumeName, - 'defaultSgGroupName': defaultSgGroupName}) + 'defaultSgGroupName': defaultSgName}) return foundDefaultStorageGroupInstanceName + def _format_default_sg_string(self, fastPolicyName): + """Format the default storage group name + + :param fastPolicyName: the fast policy name + :returns: defaultSgName + """ + return ("%(prefix)s%(fastPolicyName)s%(postfix)s" + % {'prefix': DEFAULT_SG_PREFIX, + 'fastPolicyName': fastPolicyName, + 'postfix': DEFAULT_SG_POSTFIX}) + def add_volume_to_default_storage_group_for_fast_policy( self, conn, controllerConfigService, volumeInstance, volumeName, fastPolicyName, extraSpecs): @@ -159,10 +169,9 @@ class EMCVMAXFast(object): associated with the volume """ failedRet = None - defaultSgGroupName = (DEFAULT_SG_PREFIX + fastPolicyName + - DEFAULT_SG_POSTFIX) + defaultSgName = self._format_default_sg_string(fastPolicyName) storageGroupInstanceName = self.utils.find_storage_masking_group( - conn, controllerConfigService, defaultSgGroupName) + conn, controllerConfigService, defaultSgName) if storageGroupInstanceName is None: LOG.error(_LE( "Unable to create default storage group for " @@ -740,19 +749,18 @@ class EMCVMAXFast(object): :returns: defaultStorageGroupInstanceName - the default storage group instance name """ - defaultSgGroupName = (DEFAULT_SG_PREFIX + fastPolicyName + - DEFAULT_SG_POSTFIX) + defaultSgName = self._format_default_sg_string(fastPolicyName) defaultStorageGroupInstanceName = ( self.utils.find_storage_masking_group(conn, controllerConfigService, - defaultSgGroupName)) + defaultSgName)) if defaultStorageGroupInstanceName is None: # Create it and associate it with the FAST policy in question. defaultStorageGroupInstanceName = ( self._create_default_storage_group(conn, controllerConfigService, fastPolicyName, - defaultSgGroupName, + defaultSgName, volumeInstance, extraSpecs)) diff --git a/cinder/volume/drivers/emc/emc_vmax_https.py b/cinder/volume/drivers/emc/emc_vmax_https.py index c44f5912b..9a145723b 100644 --- a/cinder/volume/drivers/emc/emc_vmax_https.py +++ b/cinder/volume/drivers/emc/emc_vmax_https.py @@ -108,7 +108,8 @@ class HTTPSConnection(httplib.HTTPSConnection): self.key_file = None if key_file is None else key_file self.cert_file = None if cert_file is None else cert_file self.insecure = no_verification - self.ca_certs = None if ca_certs is None else str(ca_certs) + self.ca_certs = ( + None if ca_certs is None else six.text_type(ca_certs)) self.set_context() # ssl exceptions are reported in various form in Python 3 # so to be compatible, we report the same kind as under diff --git a/cinder/volume/drivers/emc/emc_vmax_provision_v3.py b/cinder/volume/drivers/emc/emc_vmax_provision_v3.py index 80ca10e6a..cac18c217 100644 --- a/cinder/volume/drivers/emc/emc_vmax_provision_v3.py +++ b/cinder/volume/drivers/emc/emc_vmax_provision_v3.py @@ -349,7 +349,9 @@ class EMCVMAXProvisionV3(object): for storagePoolSetting in storagePoolSettings: settingInstanceID = storagePoolSetting['InstanceID'] - matchString = slo + ':' + workload + matchString = ("%(slo)s:%(workload)s" + % {'slo': slo, + 'workload': workload}) if matchString in settingInstanceID: foundStoragePoolSetting = storagePoolSetting break diff --git a/cinder/volume/drivers/emc/emc_vmax_utils.py b/cinder/volume/drivers/emc/emc_vmax_utils.py index 613853cfd..c9301636a 100644 --- a/cinder/volume/drivers/emc/emc_vmax_utils.py +++ b/cinder/volume/drivers/emc/emc_vmax_utils.py @@ -868,12 +868,23 @@ class EMCVMAXUtils(object): idarray = poolInstanceId.split('+') if len(idarray) > 2: - systemName = idarray[0] + '+' + idarray[1] + systemName = self._format_system_name(idarray[0], idarray[1]) LOG.debug("Pool name: %(poolName)s System name: %(systemName)s.", {'poolName': poolName, 'systemName': systemName}) return poolName, systemName + def _format_system_name(self, part1, part2): + """Join to make up system name + + :param part1: the prefix + :param part2: the postfix + :returns: systemName + """ + return ("%(part1)s+%(part2)s" + % {'part1': part1, + 'part2': part2}) + def parse_pool_instance_id_v3(self, poolInstanceId): """Given the instance Id parse the pool name and system name from it. @@ -891,7 +902,7 @@ class EMCVMAXUtils(object): idarray = poolInstanceId.split('-+-') if len(idarray) > 2: - systemName = idarray[0] + '-+-' + idarray[1] + systemName = self._format_system_name(idarray[0], idarray[1]) LOG.debug("Pool name: %(poolName)s System name: %(systemName)s.", {'poolName': poolName, 'systemName': systemName}) @@ -1366,7 +1377,7 @@ class EMCVMAXUtils(object): :returns: string -- delta in string H:MM:SS """ delta = endTime - startTime - return str(datetime.timedelta(seconds=int(delta))) + return six.text_type(datetime.timedelta(seconds=int(delta))) def find_sync_sv_by_target( self, conn, storageSystem, target, waitforsync=True): @@ -1706,7 +1717,11 @@ class EMCVMAXUtils(object): :param workload: the workload string e.g DSS :returns: storageGroupName """ - return 'OS-' + poolName + '-' + slo + '-' + workload + '-SG' + storageGroupName = ("OS-%(poolName)s-%(slo)s-%(workload)s-SG" + % {'poolName': poolName, + 'slo': slo, + 'workload': workload}) + return storageGroupName def strip_short_host_name(self, storageGroupName): tempList = storageGroupName.split("-") -- 2.45.2