From 45e6e668233eab28c2e3202c01b0ac66ab7e7e2a Mon Sep 17 00:00:00 2001 From: "cao.yuan" Date: Thu, 21 Feb 2019 12:22:30 +0800 Subject: [PATCH] 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 --- .../load_balancer/v2/amphora_client.py | 6 ++--- .../services/load_balancer/v2/base_client.py | 27 +++++++++---------- .../load_balancer/v2/listener_client.py | 6 ++--- .../load_balancer/v2/loadbalancer_client.py | 10 +++---- .../load_balancer/v2/member_client.py | 5 ++-- requirements.txt | 1 + 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py b/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py index 54f280ec..ce324cb8 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/amphora_client.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import json +from oslo_serialization import jsonutils from tempest import config @@ -154,6 +154,6 @@ class AmphoraClient(base_client.BaseLBaaSClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))[self.stats_root_tag] + return jsonutils.loads(body.decode('utf-8'))[self.stats_root_tag] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) diff --git a/octavia_tempest_plugin/services/load_balancer/v2/base_client.py b/octavia_tempest_plugin/services/load_balancer/v2/base_client.py index 397c7354..a3ad1536 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/base_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/base_client.py @@ -13,9 +13,8 @@ # under the License. # -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils from tempest import config from tempest.lib.common import rest_client from tempest.lib.common.utils import test_utils @@ -99,12 +98,12 @@ class BaseLBaaSClient(rest_client.RestClient): else: request_uri = self.uri - response, body = self.post(request_uri, json.dumps(obj_dict)) + response, body = self.post(request_uri, jsonutils.dumps(obj_dict)) self.expected_success(201, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))[self.root_tag] + return jsonutils.loads(body.decode('utf-8'))[self.root_tag] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) def _show_object(self, obj_id, parent_id=None, query_params=None, return_object_only=True): @@ -156,9 +155,9 @@ class BaseLBaaSClient(rest_client.RestClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))[self.root_tag] + return jsonutils.loads(body.decode('utf-8'))[self.root_tag] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) def _list_objects(self, parent_id=None, query_params=None, return_object_only=True): @@ -208,9 +207,9 @@ class BaseLBaaSClient(rest_client.RestClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))[self.list_root_tag] + return jsonutils.loads(body.decode('utf-8'))[self.list_root_tag] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) def _update_object(self, obj_id, parent_id=None, return_object_only=True, **kwargs): @@ -258,12 +257,12 @@ class BaseLBaaSClient(rest_client.RestClient): uri = self.uri request_uri = '{0}/{1}'.format(uri, obj_id) - response, body = self.put(request_uri, json.dumps(obj_dict)) + response, body = self.put(request_uri, jsonutils.dumps(obj_dict)) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))[self.root_tag] + return jsonutils.loads(body.decode('utf-8'))[self.root_tag] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) def _delete_obj(self, obj_id, parent_id=None, ignore_errors=False, cascade=False): @@ -365,7 +364,7 @@ class BaseLBaaSClient(rest_client.RestClient): try: request_uri = '{0}/{1}'.format(uri, obj_id) response, body = self.get(request_uri) - resp_obj = json.loads(body.decode('utf-8'))[self.root_tag] + resp_obj = jsonutils.loads(body.decode('utf-8'))[self.root_tag] if (response.status == 404 or resp_obj['provisioning_status'] == const.DELETED): raise exceptions.NotFound() @@ -447,7 +446,7 @@ class BaseLBaaSClient(rest_client.RestClient): response, body = self.get('/') self.expected_success(200, response.status) - versions_list = json.loads(body.decode('utf-8'))['versions'] + versions_list = jsonutils.loads(body.decode('utf-8'))['versions'] current_versions = (version for version in versions_list if version['status'] == 'CURRENT') max_version = '0.0' diff --git a/octavia_tempest_plugin/services/load_balancer/v2/listener_client.py b/octavia_tempest_plugin/services/load_balancer/v2/listener_client.py index ce41b0f2..de84bd14 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/listener_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/listener_client.py @@ -13,7 +13,7 @@ # under the License. # -import json +from oslo_serialization import jsonutils from tempest import config @@ -340,6 +340,6 @@ class ListenerClient(base_client.BaseLBaaSClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))['stats'] + return jsonutils.loads(body.decode('utf-8'))['stats'] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) diff --git a/octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py b/octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py index 6ea83f00..9a287cf3 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/loadbalancer_client.py @@ -13,7 +13,7 @@ # under the License. # -import json +from oslo_serialization import jsonutils from tempest import config @@ -337,9 +337,9 @@ class LoadbalancerClient(base_client.BaseLBaaSClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))['stats'] + return jsonutils.loads(body.decode('utf-8'))['stats'] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) def get_loadbalancer_status(self, lb_id, query_params=None, return_object_only=True): @@ -387,6 +387,6 @@ class LoadbalancerClient(base_client.BaseLBaaSClient): response, body = self.get(request_uri) self.expected_success(200, response.status) if return_object_only: - return json.loads(body.decode('utf-8'))['statuses'] + return jsonutils.loads(body.decode('utf-8'))['statuses'] else: - return json.loads(body.decode('utf-8')) + return jsonutils.loads(body.decode('utf-8')) diff --git a/octavia_tempest_plugin/services/load_balancer/v2/member_client.py b/octavia_tempest_plugin/services/load_balancer/v2/member_client.py index 3909ac29..63e836a2 100644 --- a/octavia_tempest_plugin/services/load_balancer/v2/member_client.py +++ b/octavia_tempest_plugin/services/load_balancer/v2/member_client.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from oslo_log import log as logging +from oslo_serialization import jsonutils from tempest import config from octavia_tempest_plugin.services.load_balancer.v2 import base_client @@ -269,7 +268,7 @@ class MemberClient(base_client.BaseLBaaSClient): obj_dict = {self.list_root_tag: members_list} request_uri = self.uri.format(parent=pool_id) - response, body = self.put(request_uri, json.dumps(obj_dict)) + response, body = self.put(request_uri, jsonutils.dumps(obj_dict)) self.expected_success(202, response.status) return diff --git a/requirements.txt b/requirements.txt index 815be940..c9f839cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0 octavia-lib>=1.0.0 # Apache-2.0 oslo.config>=5.2.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 +oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0 python-barbicanclient>=4.5.2 # Apache-2.0