Browse Source

Update json module to jsonutils

oslo project provide jsonutils, and octavia use it in many place[1],
this PS to update the remained json moudule to oslo jsonutils for
consistency.

[1]: https://github.com/openstack/octavia-tempest-plugin/search?utf8=%E2%9C%93&q=jsonutils&type=

Change-Id: I1cf966595bbabd3e33b1e33033dfb6a8b16381f8
cao.yuan 1 month ago
parent
commit
45e6e66823

+ 3
- 3
octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py View File

@@ -12,7 +12,7 @@
12 12
 #   License for the specific language governing permissions and limitations
13 13
 #   under the License.
14 14
 
15
-import json
15
+from oslo_serialization import jsonutils
16 16
 
17 17
 from tempest import config
18 18
 
@@ -154,6 +154,6 @@ class AmphoraClient(base_client.BaseLBaaSClient):
154 154
         response, body = self.get(request_uri)
155 155
         self.expected_success(200, response.status)
156 156
         if return_object_only:
157
-            return json.loads(body.decode('utf-8'))[self.stats_root_tag]
157
+            return jsonutils.loads(body.decode('utf-8'))[self.stats_root_tag]
158 158
         else:
159
-            return json.loads(body.decode('utf-8'))
159
+            return jsonutils.loads(body.decode('utf-8'))

+ 13
- 14
octavia_tempest_plugin/services/load_balancer/v2/base_client.py View File

@@ -13,9 +13,8 @@
13 13
 #   under the License.
14 14
 #
15 15
 
16
-import json
17
-
18 16
 from oslo_log import log as logging
17
+from oslo_serialization import jsonutils
19 18
 from tempest import config
20 19
 from tempest.lib.common import rest_client
21 20
 from tempest.lib.common.utils import test_utils
@@ -99,12 +98,12 @@ class BaseLBaaSClient(rest_client.RestClient):
99 98
         else:
100 99
             request_uri = self.uri
101 100
 
102
-        response, body = self.post(request_uri, json.dumps(obj_dict))
101
+        response, body = self.post(request_uri, jsonutils.dumps(obj_dict))
103 102
         self.expected_success(201, response.status)
104 103
         if return_object_only:
105
-            return json.loads(body.decode('utf-8'))[self.root_tag]
104
+            return jsonutils.loads(body.decode('utf-8'))[self.root_tag]
106 105
         else:
107
-            return json.loads(body.decode('utf-8'))
106
+            return jsonutils.loads(body.decode('utf-8'))
108 107
 
109 108
     def _show_object(self, obj_id, parent_id=None, query_params=None,
110 109
                      return_object_only=True):
@@ -156,9 +155,9 @@ class BaseLBaaSClient(rest_client.RestClient):
156 155
         response, body = self.get(request_uri)
157 156
         self.expected_success(200, response.status)
158 157
         if return_object_only:
159
-            return json.loads(body.decode('utf-8'))[self.root_tag]
158
+            return jsonutils.loads(body.decode('utf-8'))[self.root_tag]
160 159
         else:
161
-            return json.loads(body.decode('utf-8'))
160
+            return jsonutils.loads(body.decode('utf-8'))
162 161
 
163 162
     def _list_objects(self, parent_id=None, query_params=None,
164 163
                       return_object_only=True):
@@ -208,9 +207,9 @@ class BaseLBaaSClient(rest_client.RestClient):
208 207
         response, body = self.get(request_uri)
209 208
         self.expected_success(200, response.status)
210 209
         if return_object_only:
211
-            return json.loads(body.decode('utf-8'))[self.list_root_tag]
210
+            return jsonutils.loads(body.decode('utf-8'))[self.list_root_tag]
212 211
         else:
213
-            return json.loads(body.decode('utf-8'))
212
+            return jsonutils.loads(body.decode('utf-8'))
214 213
 
215 214
     def _update_object(self, obj_id, parent_id=None, return_object_only=True,
216 215
                        **kwargs):
@@ -258,12 +257,12 @@ class BaseLBaaSClient(rest_client.RestClient):
258 257
             uri = self.uri
259 258
 
260 259
         request_uri = '{0}/{1}'.format(uri, obj_id)
261
-        response, body = self.put(request_uri, json.dumps(obj_dict))
260
+        response, body = self.put(request_uri, jsonutils.dumps(obj_dict))
262 261
         self.expected_success(200, response.status)
263 262
         if return_object_only:
264
-            return json.loads(body.decode('utf-8'))[self.root_tag]
263
+            return jsonutils.loads(body.decode('utf-8'))[self.root_tag]
265 264
         else:
266
-            return json.loads(body.decode('utf-8'))
265
+            return jsonutils.loads(body.decode('utf-8'))
267 266
 
268 267
     def _delete_obj(self, obj_id, parent_id=None, ignore_errors=False,
269 268
                     cascade=False):
@@ -365,7 +364,7 @@ class BaseLBaaSClient(rest_client.RestClient):
365 364
         try:
366 365
             request_uri = '{0}/{1}'.format(uri, obj_id)
367 366
             response, body = self.get(request_uri)
368
-            resp_obj = json.loads(body.decode('utf-8'))[self.root_tag]
367
+            resp_obj = jsonutils.loads(body.decode('utf-8'))[self.root_tag]
369 368
             if (response.status == 404 or
370 369
                     resp_obj['provisioning_status'] == const.DELETED):
371 370
                 raise exceptions.NotFound()
@@ -447,7 +446,7 @@ class BaseLBaaSClient(rest_client.RestClient):
447 446
         response, body = self.get('/')
448 447
         self.expected_success(200, response.status)
449 448
 
450
-        versions_list = json.loads(body.decode('utf-8'))['versions']
449
+        versions_list = jsonutils.loads(body.decode('utf-8'))['versions']
451 450
         current_versions = (version for version in versions_list if
452 451
                             version['status'] == 'CURRENT')
453 452
         max_version = '0.0'

+ 3
- 3
octavia_tempest_plugin/services/load_balancer/v2/listener_client.py View File

@@ -13,7 +13,7 @@
13 13
 #   under the License.
14 14
 #
15 15
 
16
-import json
16
+from oslo_serialization import jsonutils
17 17
 
18 18
 from tempest import config
19 19
 
@@ -340,6 +340,6 @@ class ListenerClient(base_client.BaseLBaaSClient):
340 340
         response, body = self.get(request_uri)
341 341
         self.expected_success(200, response.status)
342 342
         if return_object_only:
343
-            return json.loads(body.decode('utf-8'))['stats']
343
+            return jsonutils.loads(body.decode('utf-8'))['stats']
344 344
         else:
345
-            return json.loads(body.decode('utf-8'))
345
+            return jsonutils.loads(body.decode('utf-8'))

+ 5
- 5
octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py View File

@@ -13,7 +13,7 @@
13 13
 #   under the License.
14 14
 #
15 15
 
16
-import json
16
+from oslo_serialization import jsonutils
17 17
 
18 18
 from tempest import config
19 19
 
@@ -337,9 +337,9 @@ class LoadbalancerClient(base_client.BaseLBaaSClient):
337 337
         response, body = self.get(request_uri)
338 338
         self.expected_success(200, response.status)
339 339
         if return_object_only:
340
-            return json.loads(body.decode('utf-8'))['stats']
340
+            return jsonutils.loads(body.decode('utf-8'))['stats']
341 341
         else:
342
-            return json.loads(body.decode('utf-8'))
342
+            return jsonutils.loads(body.decode('utf-8'))
343 343
 
344 344
     def get_loadbalancer_status(self, lb_id, query_params=None,
345 345
                                 return_object_only=True):
@@ -387,6 +387,6 @@ class LoadbalancerClient(base_client.BaseLBaaSClient):
387 387
         response, body = self.get(request_uri)
388 388
         self.expected_success(200, response.status)
389 389
         if return_object_only:
390
-            return json.loads(body.decode('utf-8'))['statuses']
390
+            return jsonutils.loads(body.decode('utf-8'))['statuses']
391 391
         else:
392
-            return json.loads(body.decode('utf-8'))
392
+            return jsonutils.loads(body.decode('utf-8'))

+ 2
- 3
octavia_tempest_plugin/services/load_balancer/v2/member_client.py View File

@@ -12,9 +12,8 @@
12 12
 #   License for the specific language governing permissions and limitations
13 13
 #   under the License.
14 14
 
15
-import json
16
-
17 15
 from oslo_log import log as logging
16
+from oslo_serialization import jsonutils
18 17
 from tempest import config
19 18
 
20 19
 from octavia_tempest_plugin.services.load_balancer.v2 import base_client
@@ -269,7 +268,7 @@ class MemberClient(base_client.BaseLBaaSClient):
269 268
         obj_dict = {self.list_root_tag: members_list}
270 269
         request_uri = self.uri.format(parent=pool_id)
271 270
 
272
-        response, body = self.put(request_uri, json.dumps(obj_dict))
271
+        response, body = self.put(request_uri, jsonutils.dumps(obj_dict))
273 272
         self.expected_success(202, response.status)
274 273
         return
275 274
 

+ 1
- 0
requirements.txt View File

@@ -9,6 +9,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
9 9
 octavia-lib>=1.0.0 # Apache-2.0
10 10
 oslo.config>=5.2.0 # Apache-2.0
11 11
 oslo.log>=3.36.0  # Apache-2.0
12
+oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
12 13
 oslo.utils>=3.33.0  # Apache-2.0
13 14
 oslotest>=3.2.0 # Apache-2.0
14 15
 python-barbicanclient>=4.5.2 # Apache-2.0

Loading…
Cancel
Save