Browse Source

FIX: "dict" issue for Python 2/3 compatible code

Replace dict.iteritems() with dict.items()
Change dict.keys() to list(dict.keys())

Story: 2004585
Task: 28449

Change-Id: I674c499fd575800fa307a835d8f7f272f2b2cd03
Signed-off-by: Sun Austin <austin.sun@intel.com>
Sun Austin 3 months ago
parent
commit
5e9dc48384

+ 2
- 2
dcmanager/manager/sw_update_manager.py View File

@@ -707,7 +707,7 @@ class PatchOrchThread(threading.Thread):
707 707
         # removed to match the applied patches in RegionOne. Check the
708 708
         # repostate, which indicates whether it is applied or removed in
709 709
         # the repo.
710
-        subcloud_patch_ids = subcloud_patches.keys()
710
+        subcloud_patch_ids = list(subcloud_patches.keys())
711 711
         for patch_id in subcloud_patch_ids:
712 712
             if subcloud_patches[patch_id]['repostate'] == \
713 713
                     patching_v1.PATCH_STATE_APPLIED:
@@ -1386,7 +1386,7 @@ class PatchOrchThread(threading.Thread):
1386 1386
         # which should be deleted. We check the patchstate here because
1387 1387
         # patches cannot be deleted or committed if they are in a partial
1388 1388
         # state (e.g. Partial-Apply or Partial-Remove).
1389
-        subcloud_patch_ids = subcloud_patches.keys()
1389
+        subcloud_patch_ids = list(subcloud_patches.keys())
1390 1390
         for patch_id in subcloud_patch_ids:
1391 1391
             if subcloud_patches[patch_id]['patchstate'] == \
1392 1392
                     patching_v1.PATCH_STATE_AVAILABLE:

+ 8
- 8
dcorch/api/proxy/apps/acceptor.py View File

@@ -74,8 +74,8 @@ class Acceptor(Router):
74 74
         api_controller = ComputeAPIController(app, conf)
75 75
         orch_controller = OrchAPIController(app, conf)
76 76
 
77
-        for key, value in proxy_consts.COMPUTE_PATH_MAP.iteritems():
78
-            for k, v in value.iteritems():
77
+        for key, value in proxy_consts.COMPUTE_PATH_MAP.items():
78
+            for k, v in value.items():
79 79
                 self._add_resource(mapper, api_controller, v, k,
80 80
                                    CONF.type, key)
81 81
 
@@ -87,14 +87,14 @@ class Acceptor(Router):
87 87
     def add_platform_routes(self, app, conf, mapper):
88 88
         api_controller = SysinvAPIController(app, conf)
89 89
 
90
-        for key, value in proxy_consts.SYSINV_PATH_MAP.iteritems():
90
+        for key, value in proxy_consts.SYSINV_PATH_MAP.items():
91 91
             self._add_resource(mapper, api_controller, value, key, CONF.type)
92 92
 
93 93
     def add_volume_routes(self, app, conf, mapper):
94 94
         api_controller = CinderAPIController(app, conf)
95 95
 
96
-        for key, value in proxy_consts.CINDER_PATH_MAP.iteritems():
97
-            for k, v in value.iteritems():
96
+        for key, value in proxy_consts.CINDER_PATH_MAP.items():
97
+            for k, v in value.items():
98 98
                 self._add_resource(mapper, api_controller, v, k,
99 99
                                    CONF.type, key)
100 100
 
@@ -102,7 +102,7 @@ class Acceptor(Router):
102 102
         api_controller = NeutronAPIController(app, conf)
103 103
         orch_controller = OrchAPIController(app, conf)
104 104
 
105
-        for key, value in proxy_consts.NEUTRON_PATH_MAP.iteritems():
105
+        for key, value in proxy_consts.NEUTRON_PATH_MAP.items():
106 106
             self._add_resource(mapper, api_controller, value, key, CONF.type)
107 107
 
108 108
         self._add_resource(mapper, orch_controller,
@@ -113,11 +113,11 @@ class Acceptor(Router):
113 113
     def add_patch_routes(self, app, conf, mapper):
114 114
         api_controller = PatchAPIController(app, conf)
115 115
 
116
-        for key, value in proxy_consts.PATCH_PATH_MAP.iteritems():
116
+        for key, value in proxy_consts.PATCH_PATH_MAP.items():
117 117
             self._add_resource(mapper, api_controller, value, key, CONF.type)
118 118
 
119 119
     def add_identity_routes(self, app, conf, mapper):
120 120
         api_controller = IdentityAPIController(app, conf)
121 121
 
122
-        for key, value in proxy_consts.IDENTITY_PATH_MAP.iteritems():
122
+        for key, value in proxy_consts.IDENTITY_PATH_MAP.items():
123 123
             self._add_resource(mapper, api_controller, value, key, CONF.type)

+ 2
- 2
dcorch/api/proxy/apps/controller.py View File

@@ -157,7 +157,7 @@ class APIController(Middleware):
157 157
                  environ['REQUEST_METHOD'], length)
158 158
         LOG.info("Request URL: (%s)\n", self.get_request_header(environ))
159 159
         LOG.info("Request header: \n")
160
-        for k, v in req.headers.iteritems():
160
+        for k, v in req.headers.items():
161 161
             LOG.info("  %s: %s\n", k, v)
162 162
         self.print_environ(environ)
163 163
         self.print_request_body(req.body)
@@ -485,7 +485,7 @@ class IdentityAPIController(APIController):
485 485
         else:
486 486
             if operation_type == consts.OPERATION_TYPE_POST:
487 487
                 # Retrieve the ID from the response
488
-                resource = json.loads(response.body).items()[0][1]
488
+                resource = list(json.loads(response.body).items())[0][1]
489 489
                 resource_id = resource['id']
490 490
             else:
491 491
                 resource_id = self.get_resource_id_from_link(request_header)

+ 1
- 1
dcorch/api/proxy/apps/patch.py View File

@@ -176,7 +176,7 @@ class PatchAPIController(Middleware):
176 176
 
177 177
     def patch_upload_dir_req(self, request, response):
178 178
         files = []
179
-        for key, path in request.GET.iteritems():
179
+        for key, path in request.GET.items():
180 180
             LOG.info("upload-dir: Retrieving patches from %s" % path)
181 181
             for f in glob.glob(path + '/*.patch'):
182 182
                 if os.path.isfile(f):

+ 1
- 1
dcorch/api/proxy/common/utils.py View File

@@ -71,7 +71,7 @@ def get_routing_match_value(environ, key):
71 71
         return match[key]
72 72
     else:
73 73
         LOG.info("(%s) is not available in routing match arguments.", key)
74
-        for k, v in match.iteritems():
74
+        for k, v in match.items():
75 75
             LOG.info("Match key:(%s), value:(%s)", k, v)
76 76
         return None
77 77
 

+ 1
- 1
dcorch/common/endpoint_cache.py View File

@@ -161,7 +161,7 @@ class EndpointCache(object):
161 161
 
162 162
         return: List of regions
163 163
         """
164
-        return self.endpoint_map.keys()
164
+        return list(self.endpoint_map.keys())
165 165
 
166 166
     def get_session_from_token(self, token, project_id):
167 167
         """Get session based on token to communicate with openstack services.

+ 4
- 4
dcorch/drivers/openstack/sysinv_v1.py View File

@@ -36,7 +36,7 @@ API_VERSION = '1'
36 36
 
37 37
 def make_sysinv_patch(update_dict):
38 38
     patch = []
39
-    for k, v in update_dict.iteritems():
39
+    for k, v in update_dict.items():
40 40
         key = k
41 41
         if not k.startswith('/'):
42 42
             key = '/' + key
@@ -265,7 +265,7 @@ class SysinvClient(base.DriverBase):
265 265
         #     {"ip_address": "10.10.10.12", "community": "cgcs"}
266 266
         itrapdest = None
267 267
         trapdest_create_dict = {}
268
-        for k, v in trapdest_dict.iteritems():
268
+        for k, v in trapdest_dict.items():
269 269
             if k in SNMP_TRAPDEST_CREATION_ATTRIBUTES:
270 270
                 trapdest_create_dict[str(k)] = v
271 271
 
@@ -329,7 +329,7 @@ class SysinvClient(base.DriverBase):
329 329
         # Example community_dict: {"community": "cgcs"}
330 330
         icommunity = None
331 331
         community_create_dict = {}
332
-        for k, v in community_dict.iteritems():
332
+        for k, v in community_dict.items():
333 333
             if k in SNMP_COMMUNITY_CREATION_ATTRIBUTES:
334 334
                 community_create_dict[str(k)] = v
335 335
 
@@ -399,7 +399,7 @@ class SysinvClient(base.DriverBase):
399 399
     def create_remote_logging_patch_from_dict(self, values):
400 400
         patch = {}
401 401
         action_found = False
402
-        for k, v in values.iteritems():
402
+        for k, v in values.items():
403 403
             if k in self.REMOTELOGGING_PATCH_ATTRS:
404 404
                 if k == 'action':
405 405
                     action_found = True

+ 2
- 2
dcorch/engine/quota_manager.py View File

@@ -251,7 +251,7 @@ class QuotaManager(manager.Manager):
251 251
                                                              project_id)
252 252
         except exceptions.ProjectQuotaNotFound:
253 253
             limits_from_db = {}
254
-        for current_resource in CONF.dc_orch_global_limit.iteritems():
254
+        for current_resource in CONF.dc_orch_global_limit.items():
255 255
             resource = re.sub('quota_', '', current_resource[0])
256 256
             # If resource limit in DB, then use it or else use limit
257 257
             # from conf file
@@ -481,7 +481,7 @@ class QuotaManager(manager.Manager):
481 481
         # endpoint types, so we need to figure out which ones we want.
482 482
         desired_fields = consts.ENDPOINT_QUOTA_MAPPING[endpoint_type]
483 483
         usage_dict = {}
484
-        for k, v in total_project_usages.iteritems():
484
+        for k, v in total_project_usages.items():
485 485
             if k in desired_fields:
486 486
                 usage_dict[k] = v
487 487
         return usage_dict

+ 6
- 6
dcorch/engine/sync_services/compute.py View File

@@ -292,7 +292,7 @@ class ComputeSyncThread(SyncThread):
292 292
             consts.ACTION_EXTRASPECS_POST: self.set_extra_specs,
293 293
             consts.ACTION_EXTRASPECS_DELETE: self.unset_extra_specs,
294 294
         }
295
-        action = action_dict.keys()[0]
295
+        action = list(action_dict.keys())[0]
296 296
         if action not in switcher.keys():
297 297
             LOG.error("Unsupported flavor action {}".format(action),
298 298
                       extra=self.log_extra)
@@ -343,10 +343,10 @@ class ComputeSyncThread(SyncThread):
343 343
                     metadata[metadatum] = None
344 344
 
345 345
             try:
346
-                flavor.unset_keys(metadata.keys())
346
+                flavor.unset_keys(list(metadata.keys()))
347 347
             except novaclient_exceptions.NotFound:
348 348
                 LOG.info("Extra-spec {} not found {}:{}"
349
-                         .format(metadata.keys(), rsrc, action_dict),
349
+                         .format(list(metadata.keys()), rsrc, action_dict),
350 350
                          extra=self.log_extra)
351 351
 
352 352
     def get_flavor_resources(self, nc):
@@ -449,9 +449,9 @@ class ComputeSyncThread(SyncThread):
449 449
         # Extra-spec needs to be audited. Extra-spec details are
450 450
         # filled in m_resources and sc_resources during query.
451 451
         metadata = {}
452
-        for m_key, m_value in m_flavor.attach_es.iteritems():
452
+        for m_key, m_value in m_flavor.attach_es.items():
453 453
             found = False
454
-            for sc_key, sc_value in sc_es_attachment.iteritems():
454
+            for sc_key, sc_value in sc_es_attachment.items():
455 455
                 if m_key == sc_key and m_value == sc_value:
456 456
                     found = True
457 457
                     sc_es_attachment.pop(sc_key)
@@ -466,7 +466,7 @@ class ComputeSyncThread(SyncThread):
466 466
             num_of_audit_jobs += 1
467 467
 
468 468
         keys_to_delete = ""
469
-        for sc_key, sc_value in sc_es_attachment.iteritems():
469
+        for sc_key, sc_value in sc_es_attachment.items():
470 470
             keys_to_delete += sc_key + ";"
471 471
         if keys_to_delete:
472 472
             action_dict = {consts.ACTION_EXTRASPECS_DELETE: keys_to_delete}

+ 1
- 1
dcorch/snmp/controller.py View File

@@ -97,7 +97,7 @@ class Controller(object):
97 97
 
98 98
     def handle_delayed_notifications(self):
99 99
         curr_time = datetime.datetime.utcnow()
100
-        for system, notify_time in self.system_throttle_timers.iteritems():
100
+        for system, notify_time in self.system_throttle_timers.items():
101 101
             if notify_time is not None:
102 102
                 if curr_time > notify_time:
103 103
                     self.send_notification(system)

Loading…
Cancel
Save