From: Victor Stinner Date: Fri, 12 Jun 2015 13:05:00 +0000 (+0200) Subject: Rewrite code merging two dictionaries X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0256d88719ece09f9c376d859ba57f7ff459b5e1;p=openstack-build%2Fcinder-build.git Rewrite code merging two dictionaries Basically, replace dict(dict1.items() + dict2.items()) with dict1.update(dict2) (and copy dict1 when needed). This change adds Python 3 compatibility to the modified code. Blueprint cinder-python3 Change-Id: I4f73efa0434f5c7ffba2dd966035762d197b9c68 --- diff --git a/cinder/context.py b/cinder/context.py index f99f31480..774769cd7 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -107,19 +107,19 @@ class RequestContext(context.RequestContext): _del_read_deleted) def to_dict(self): - default = super(RequestContext, self).to_dict() - extra = {'user_id': self.user_id, - 'project_id': self.project_id, - 'project_name': self.project_name, - 'domain': self.domain, - 'read_deleted': self.read_deleted, - 'roles': self.roles, - 'remote_address': self.remote_address, - 'timestamp': self.timestamp.isoformat(), - 'quota_class': self.quota_class, - 'service_catalog': self.service_catalog, - 'request_id': self.request_id} - return dict(default.items() + extra.items()) + result = super(RequestContext, self).to_dict() + result['user_id'] = self.user_id + result['project_id'] = self.project_id + result['project_name'] = self.project_name + result['domain'] = self.domain + result['read_deleted'] = self.read_deleted + result['roles'] = self.roles + result['remote_address'] = self.remote_address + result['timestamp'] = self.timestamp.isoformat() + result['quota_class'] = self.quota_class + result['service_catalog'] = self.service_catalog + result['request_id'] = self.request_id + return result @classmethod def from_dict(cls, values): diff --git a/cinder/volume/drivers/huawei/rest_common.py b/cinder/volume/drivers/huawei/rest_common.py index f75358782..7b064e4cd 100644 --- a/cinder/volume/drivers/huawei/rest_common.py +++ b/cinder/volume/drivers/huawei/rest_common.py @@ -1638,20 +1638,19 @@ class RestCommon(object): localtime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) # Package QoS name. qos_name = QOS_NAME_PREFIX + lun_id + '_' + localtime - baseData = {"TYPE": "230", - "NAME": qos_name, - "LUNLIST": ["%s" % lun_id], - "CLASSTYPE": "1", - "SCHEDULEPOLICY": "2", - "SCHEDULESTARTTIME": "1410969600", - "STARTTIME": "08:00", - "DURATION": "86400", - "CYCLESET": "[1,2,3,4,5,6,0]" - } - - mergedata = dict(baseData.items() + qos.items()) - url = self.url + "/ioclass/" + + mergedata = {"TYPE": "230", + "NAME": qos_name, + "LUNLIST": ["%s" % lun_id], + "CLASSTYPE": "1", + "SCHEDULEPOLICY": "2", + "SCHEDULESTARTTIME": "1410969600", + "STARTTIME": "08:00", + "DURATION": "86400", + "CYCLESET": "[1,2,3,4,5,6,0]"} + mergedata.update(qos) data = json.dumps(mergedata) + url = self.url + "/ioclass/" result = self.call(url, data) self._assert_rest_result(result, 'Create QoS policy error.') diff --git a/cinder/volume/drivers/windows/vhdutils.py b/cinder/volume/drivers/windows/vhdutils.py index 455cfffc4..9e249cb24 100644 --- a/cinder/volume/drivers/windows/vhdutils.py +++ b/cinder/volume/drivers/windows/vhdutils.py @@ -359,7 +359,7 @@ class VHDUtils(object): try: for member in info_members: info = self._get_vhd_info_member(handle, member) - vhd_info = dict(vhd_info.items() + info.items()) + vhd_info.update(info) finally: self._close(handle) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 6dba70668..d059d586b 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -1205,9 +1205,7 @@ class VolumeManager(manager.SchedulerDependentManager): rpcapi = volume_rpcapi.VolumeAPI() # Create new volume on remote host - new_vol_values = {} - for k, v in volume.iteritems(): - new_vol_values[k] = v + new_vol_values = dict(volume) del new_vol_values['id'] del new_vol_values['_name_id'] # We don't copy volume_type because the db sets that according to