]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace dict(obj.iteritems() with dict(obj)
authorVictor Stinner <vstinner@redhat.com>
Fri, 12 Jun 2015 12:55:37 +0000 (14:55 +0200)
committerVictor Stinner <vstinner@redhat.com>
Fri, 12 Jun 2015 13:19:18 +0000 (15:19 +0200)
Since oslo.db 1.10, it's possible to convert directly a SQLAlchemy
object to a dictionary using dict(obj) instead of having to write
dict(obj.iteritems()).

dict(obj) works also on regular dictionaries to duplicate a dictionary.

Blueprint cinder-python3
Change-Id: I868a055d5bbfe6646aad3e36e1bf6c7a1ad7b449

15 files changed:
cinder/api/contrib/backups.py
cinder/api/contrib/cgsnapshots.py
cinder/api/contrib/consistencygroups.py
cinder/api/contrib/volume_image_metadata.py
cinder/api/contrib/volume_manage.py
cinder/api/contrib/volume_transfer.py
cinder/api/v1/volumes.py
cinder/api/v2/volumes.py
cinder/backup/api.py
cinder/consistencygroup/api.py
cinder/db/sqlalchemy/api.py
cinder/scheduler/host_manager.py
cinder/tests/unit/test_volume.py
cinder/transfer/api.py
cinder/volume/api.py

index 51d3fb496a90ce16476db54b8ac4ebe9195d016e..1b68e1234e375dbae74c9312bea9afed747655a0 100644 (file)
@@ -272,7 +272,7 @@ class BackupsController(wsgi.Controller):
         except exception.ServiceNotFound as error:
             raise exc.HTTPInternalServerError(explanation=error.msg)
 
-        retval = self._view_builder.summary(req, dict(new_backup.iteritems()))
+        retval = self._view_builder.summary(req, dict(new_backup))
         return retval
 
     @wsgi.response(202)
@@ -316,7 +316,7 @@ class BackupsController(wsgi.Controller):
                 explanation=error.msg, headers={'Retry-After': 0})
 
         retval = self._view_builder.restore_summary(
-            req, dict(new_restore.iteritems()))
+            req, dict(new_restore))
         return retval
 
     @wsgi.response(200)
@@ -334,7 +334,7 @@ class BackupsController(wsgi.Controller):
             raise exc.HTTPBadRequest(explanation=error.msg)
 
         retval = self._view_builder.export_summary(
-            req, dict(backup_info.iteritems()))
+            req, dict(backup_info))
         LOG.debug('export record output: %s.', retval)
         return retval
 
@@ -370,7 +370,7 @@ class BackupsController(wsgi.Controller):
         except exception.ServiceNotFound as error:
             raise exc.HTTPInternalServerError(explanation=error.msg)
 
-        retval = self._view_builder.summary(req, dict(new_backup.iteritems()))
+        retval = self._view_builder.summary(req, dict(new_backup))
         LOG.debug('import record output: %s.', retval)
         return retval
 
index 77bd046b73890d4ada0c17548a425162ec8a796d..76aa382391376ebd2142ef81c49481a185241975 100644 (file)
@@ -196,7 +196,7 @@ class CgsnapshotsController(wsgi.Controller):
 
         retval = self._view_builder.summary(
             req,
-            dict(new_cgsnapshot.iteritems()))
+            dict(new_cgsnapshot))
 
         return retval
 
index 8e531f18a468477dbadfa56888cc6b81b5b73831..9a147292a7250eb60d7d2d55db800b5540d4fc81 100644 (file)
@@ -248,7 +248,7 @@ class ConsistencyGroupsController(wsgi.Controller):
 
         retval = self._view_builder.summary(
             req,
-            dict(new_consistencygroup.iteritems()))
+            dict(new_consistencygroup))
         return retval
 
     @wsgi.response(202)
@@ -300,7 +300,7 @@ class ConsistencyGroupsController(wsgi.Controller):
 
         retval = self._view_builder.summary(
             req,
-            dict(new_consistencygroup.iteritems()))
+            dict(new_consistencygroup))
         return retval
 
     @wsgi.serializers(xml=ConsistencyGroupTemplate)
index 454bc5092d9c3269d4d49c3b5b63db51daa43df7..729d577f88cd538e1e73168f86c305bbc41f6491 100644 (file)
@@ -62,8 +62,7 @@ class VolumeImageMetadataController(wsgi.Controller):
             except Exception:
                 return
         if image_meta:
-            resp_volume['volume_image_metadata'] = dict(
-                image_meta.iteritems())
+            resp_volume['volume_image_metadata'] = dict(image_meta)
 
     @wsgi.extends
     def show(self, req, resp_obj, id):
index ca9c3b174ea54f9320e4a0662568be5549c02d73..55e681f842802d8f49e1fa8fc2d25c3726f892a5 100644 (file)
@@ -145,7 +145,7 @@ class VolumeManageController(wsgi.Controller):
             msg = _("Service not found.")
             raise exc.HTTPNotFound(explanation=msg)
 
-        new_volume = dict(new_volume.iteritems())
+        new_volume = dict(new_volume)
         utils.add_visible_admin_metadata(new_volume)
 
         return self._view_builder.detail(req, new_volume)
index 132e122af4bf488aeebcd9b96911a298be7308a1..469f591ea0c3126455b2bba022071d6318a32a8b 100644 (file)
@@ -175,7 +175,7 @@ class VolumeTransferController(wsgi.Controller):
             raise exc.HTTPNotFound(explanation=error.msg)
 
         transfer = self._view_builder.create(req,
-                                             dict(new_transfer.iteritems()))
+                                             dict(new_transfer))
         return transfer
 
     @wsgi.response(202)
@@ -211,7 +211,7 @@ class VolumeTransferController(wsgi.Controller):
 
         transfer = \
             self._view_builder.summary(req,
-                                       dict(accepted_transfer.iteritems()))
+                                       dict(accepted_transfer))
         return transfer
 
     def delete(self, req, id):
index 781acb1572dcb1dfe9a14d9aa7a03a39ba11038c..ba9fdf3967c9b24e5a263b809e9d81de63d6474b 100644 (file)
@@ -292,7 +292,7 @@ class VolumeController(wsgi.Controller):
                                           filters=search_opts,
                                           viewable_admin_meta=True)
 
-        volumes = [dict(vol.iteritems()) for vol in volumes]
+        volumes = [dict(vol) for vol in volumes]
 
         for volume in volumes:
             utils.add_visible_admin_metadata(volume)
@@ -401,7 +401,7 @@ class VolumeController(wsgi.Controller):
         # TODO(vish): Instance should be None at db layer instead of
         #             trying to lazy load, but for now we turn it into
         #             a dict to avoid an error.
-        new_volume = dict(new_volume.iteritems())
+        new_volume = dict(new_volume)
 
         retval = _translate_volume_detail_view(context, new_volume, image_uuid)
 
index 6c8c47ffc2eb1d9ff9cf3e496a3703a3b2377fe2..4be05fed1c2f28e5d799e697fee1a6fd70495ee5 100644 (file)
@@ -256,7 +256,7 @@ class VolumeController(wsgi.Controller):
                                           filters=filters,
                                           viewable_admin_meta=True)
 
-        volumes = [dict(vol.iteritems()) for vol in volumes]
+        volumes = [dict(vol) for vol in volumes]
 
         for volume in volumes:
             utils.add_visible_admin_metadata(volume)
@@ -442,7 +442,7 @@ class VolumeController(wsgi.Controller):
         # TODO(vish): Instance should be None at db layer instead of
         #             trying to lazy load, but for now we turn it into
         #             a dict to avoid an error.
-        new_volume = dict(new_volume.iteritems())
+        new_volume = dict(new_volume)
         retval = self._view_builder.detail(req, new_volume)
 
         return retval
index 1c94dd059363b9c54fe27fc596594e3bcdc62569..06918174dd734c2ca957cc56d657c1b2424e6ef5 100644 (file)
@@ -61,7 +61,7 @@ class API(base.Base):
     def get(self, context, backup_id):
         check_policy(context, 'get')
         rv = self.db.backup_get(context, backup_id)
-        return dict(rv.iteritems())
+        return dict(rv)
 
     def delete(self, context, backup_id):
         """Make the RPC call to delete a volume backup."""
index 75506c475f0b3337f34ae71462ba2b720cb37a81..6d7c5e036c0b0ae2cb2a045e8190397d808a08d1 100644 (file)
@@ -580,7 +580,7 @@ class API(base.Base):
 
     def get(self, context, group_id):
         rv = self.db.consistencygroup_get(context, group_id)
-        group = dict(rv.iteritems())
+        group = dict(rv)
         check_policy(context, 'get', group)
         return group
 
@@ -676,7 +676,7 @@ class API(base.Base):
     def get_cgsnapshot(self, context, cgsnapshot_id):
         check_policy(context, 'get_cgsnapshot')
         rv = self.db.cgsnapshot_get(context, cgsnapshot_id)
-        return dict(rv.iteritems())
+        return dict(rv)
 
     def get_all_cgsnapshots(self, context, search_opts=None):
         check_policy(context, 'get_all_cgsnapshots')
index 2a5bf2ac1c673ff0e95d2ab87f68b4570b97dd05..12206516a1e07024e8082c4b83a1c345d33aa155 100644 (file)
@@ -69,7 +69,7 @@ def _create_facade_lazily():
         if _FACADE is None:
             _FACADE = db_session.EngineFacade(
                 CONF.database.connection,
-                **dict(CONF.database.iteritems())
+                **dict(CONF.database)
             )
 
             if CONF.profiler.profiler_enabled:
index 77faf1d2cb9911875426dd914147d2617574a6d2..0964048b1d216a5bfe33a4ddef3f10f4dccf2449 100644 (file)
@@ -495,12 +495,12 @@ class HostManager(object):
                 host_state = self.host_state_cls(host,
                                                  capabilities=capabilities,
                                                  service=
-                                                 dict(service.iteritems()))
+                                                 dict(service))
                 self.host_state_map[host] = host_state
             # update capabilities and attributes in host_state
             host_state.update_from_volume_capability(capabilities,
                                                      service=
-                                                     dict(service.iteritems()))
+                                                     dict(service))
             active_hosts.add(host)
 
         self._no_capabilities_hosts = no_capabilities_hosts
index 82b482fb0cce90807efd67dce47a3e4660d7bcf9..9f64045a6e8a8db68d9824f57dc7c2e65493c0b3 100644 (file)
@@ -2883,7 +2883,7 @@ class VolumeTestCase(BaseVolumeTestCase):
         snapshot_obj = objects.Snapshot.get_by_id(self.context, snapshot_id)
 
         snap = db.snapshot_get(context.get_admin_context(), snapshot_id)
-        result_dict = dict(snap.iteritems())
+        result_dict = dict(snap)
         result_meta = {
             result_dict['snapshot_metadata'][0].key:
             result_dict['snapshot_metadata'][0].value}
index d173280130bb2f9c6a1c3df7008fe1daae170027..0ad3fccf3af2e9bb01bd63c5d65ce212c4fe73ca 100644 (file)
@@ -56,7 +56,7 @@ class API(base.Base):
 
     def get(self, context, transfer_id):
         rv = self.db.transfer_get(context, transfer_id)
-        return dict(rv.iteritems())
+        return dict(rv)
 
     def delete(self, context, transfer_id):
         """Make the RPC call to delete a volume transfer."""
index ecfcbfa902d174bb83d134ada3f92ac8e754916f..e62144f8c3f09794d94690d7a052875f7abd1a85 100644 (file)
@@ -408,7 +408,7 @@ class API(base.Base):
         else:
             ctxt = context
         rv = self.db.volume_get(ctxt, volume_id)
-        volume = dict(rv.iteritems())
+        volume = dict(rv)
         try:
             check_policy(context, 'get', volume)
         except exception.PolicyNotAuthorized:
@@ -501,7 +501,7 @@ class API(base.Base):
         check_policy(context, 'get_volume')
         vref = self.db.volume_get(context, volume_id)
         LOG.info(_LI("Volume retrieved successfully."), resource=vref)
-        return dict(vref.iteritems())
+        return dict(vref)
 
     def get_all_snapshots(self, context, search_opts=None):
         check_policy(context, 'get_all_snapshots')
@@ -941,7 +941,7 @@ class API(base.Base):
         rv = self.db.volume_metadata_get(context, volume['id'])
         LOG.info(_LI("Get volume metadata completed successfully."),
                  resource=volume)
-        return dict(rv.iteritems())
+        return dict(rv)
 
     @wrap_check_policy
     def delete_volume_metadata(self, context, volume, key):
@@ -1011,7 +1011,7 @@ class API(base.Base):
         rv = self.db.volume_admin_metadata_get(context, volume['id'])
         LOG.info(_LI("Get volume admin metadata completed successfully."),
                  resource=volume)
-        return dict(rv.iteritems())
+        return dict(rv)
 
     @wrap_check_policy
     def delete_volume_admin_metadata(self, context, volume, key):