]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Rewrite code merging two dictionaries
authorVictor Stinner <vstinner@redhat.com>
Fri, 12 Jun 2015 13:05:00 +0000 (15:05 +0200)
committerVictor Stinner <vstinner@redhat.com>
Fri, 12 Jun 2015 13:19:18 +0000 (15:19 +0200)
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

cinder/context.py
cinder/volume/drivers/huawei/rest_common.py
cinder/volume/drivers/windows/vhdutils.py
cinder/volume/manager.py

index f99f314804551ac6e4a4c34c1d35e987e5e16e14..774769cd733d91a3463ea5b3b75c7bb0bd32c372 100644 (file)
@@ -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):
index f7535878218397adb830fba40fc0c2a40ed1c356..7b064e4cde24e2db7cc2c2cdbbb6d9f61973a744 100644 (file)
@@ -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.')
index 455cfffc40a3de2d397caa2f823255f853fca1ca..9e249cb249db1b561cb5514ee9a9402e41548049 100644 (file)
@@ -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)
 
index 6dba70668a0ce593a669463e7f56a32a1a4c61f7..d059d586b6a98bf018dfc87d6e9f5e98c4c262f1 100644 (file)
@@ -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