From 1c8ed01da9d159d5de6edbb70d12531110aa754a Mon Sep 17 00:00:00 2001 From: Artem Roma Date: Mon, 22 Dec 2014 16:27:58 +0200 Subject: [PATCH] json module replaced with jsonutils Now for operations with JSON data jsonutils module from oslo.serialization package is used. Depends on patch [1] to fuel-main. [1]: https://review.openstack.org/#/c/143639/ Change-Id: If872d46fc23eb71860f3e6b8508eef7ce7b4f223 Closes-Bug: #1404856 --- fuel_health/glancemanager.py | 6 +++--- fuel_health/muranomanager.py | 9 +++++---- fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py | 8 ++++---- fuel_plugin/ostf_adapter/storage/fields.py | 8 ++++---- fuel_plugin/ostf_adapter/wsgi/controllers.py | 6 +++--- fuel_plugin/ostf_client/client.py | 5 +++-- requirements.txt | 1 + 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/fuel_health/glancemanager.py b/fuel_health/glancemanager.py index 78f3923a..37261c41 100644 --- a/fuel_health/glancemanager.py +++ b/fuel_health/glancemanager.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import json import logging +from oslo.serialization import jsonutils import requests import fuel_health.common.ssh @@ -110,8 +110,8 @@ class GlanceTest(fuel_health.nmanager.NovaNetworkScenarioTest): if client == self.glance_client_v1: for group in object.properties: if group == group_props: - for i in json.loads(object.properties[group]): - k = json.loads(object.properties[group])[prop] + for i in jsonutils.loads(object.properties[group]): + k = jsonutils.loads(object.properties[group])[prop] if i == prop and k == unicode(value_prop): return 'OK' else: diff --git a/fuel_health/muranomanager.py b/fuel_health/muranomanager.py index f132e64c..97dbd420 100644 --- a/fuel_health/muranomanager.py +++ b/fuel_health/muranomanager.py @@ -13,11 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import json import logging import time import traceback +from oslo.serialization import jsonutils + import muranoclient.common.exceptions as exceptions import requests @@ -80,7 +81,7 @@ class MuranoTest(fuel_health.nmanager.PlatformServicesBaseClass): for image in self.compute_client.images.list(): if tag in image.metadata: - metadata = json.loads(image.metadata[tag]) + metadata = jsonutils.loads(image.metadata[tag]) if image_type == metadata['type']: return image @@ -105,7 +106,7 @@ class MuranoTest(fuel_health.nmanager.PlatformServicesBaseClass): post_body = {'name': name} resp = requests.post(self.endpoint + 'environments', - data=json.dumps(post_body), + data=jsonutils.dumps(post_body), headers=self.headers) return resp.json() @@ -215,7 +216,7 @@ class MuranoTest(fuel_health.nmanager.PlatformServicesBaseClass): headers.update({'x-configuration-session': session_id}) endpoint = '{0}environments/{1}/services'.format(self.endpoint, environment_id) - return requests.post(endpoint, data=json.dumps(json_data), + return requests.post(endpoint, data=jsonutils.dumps(json_data), headers=headers).json() def list_services(self, environment_id, session_id=None): diff --git a/fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py b/fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py index 5c92a6f6..7934ed21 100644 --- a/fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py +++ b/fuel_plugin/ostf_adapter/nose_plugin/nose_utils.py @@ -12,19 +12,19 @@ # License for the specific language governing permissions and limitations # under the License. +from distutils import version import itertools -import json import logging import multiprocessing import os import re import traceback -from distutils import version - from nose import case from nose.suite import ContextSuite +from oslo.serialization import jsonutils + LOG = logging.getLogger(__name__) @@ -33,7 +33,7 @@ def parse_json_file(file_path): commands_path = os.path.join( current_directory, file_path) with open(commands_path, 'r') as f: - return json.load(f) + return jsonutils.load(f) def get_exc_message(exception_value): diff --git a/fuel_plugin/ostf_adapter/storage/fields.py b/fuel_plugin/ostf_adapter/storage/fields.py index b528a05f..17c955e6 100644 --- a/fuel_plugin/ostf_adapter/storage/fields.py +++ b/fuel_plugin/ostf_adapter/storage/fields.py @@ -12,23 +12,23 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from sqlalchemy.types import TypeDecorator, VARCHAR +from oslo.serialization import jsonutils + class JsonField(TypeDecorator): impl = VARCHAR def process_bind_param(self, value, dialect): if value is not None: - value = json.dumps(value) + value = jsonutils.dumps(value) return value def process_result_value(self, value, dialect): if value is not None: - value = json.loads(value) + value = jsonutils.loads(value) return value diff --git a/fuel_plugin/ostf_adapter/wsgi/controllers.py b/fuel_plugin/ostf_adapter/wsgi/controllers.py index 54d8d5d1..85d5c270 100644 --- a/fuel_plugin/ostf_adapter/wsgi/controllers.py +++ b/fuel_plugin/ostf_adapter/wsgi/controllers.py @@ -12,10 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import json import logging from oslo.config import cfg +from oslo.serialization import jsonutils from pecan import abort from pecan import expose from pecan import request @@ -123,7 +123,7 @@ class TestrunsController(BaseRestController): @expose('json') def post(self): - test_runs = json.loads(request.body) + test_runs = jsonutils.loads(request.body) if 'objects' in test_runs: test_runs = test_runs['objects'] @@ -170,7 +170,7 @@ class TestrunsController(BaseRestController): @expose('json') def put(self): - test_runs = json.loads(request.body) + test_runs = jsonutils.loads(request.body) if 'objects' in test_runs: test_runs = test_runs['objects'] diff --git a/fuel_plugin/ostf_client/client.py b/fuel_plugin/ostf_client/client.py index d2dc14c9..3489502e 100644 --- a/fuel_plugin/ostf_client/client.py +++ b/fuel_plugin/ostf_client/client.py @@ -12,10 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. -import json import requests import time +from oslo.serialization import jsonutils + class TestingAdapterClient(object): def __init__(self, url): @@ -38,7 +39,7 @@ class TestingAdapterClient(object): else: data_el['ostf_os_access_creds'] = ostf_os_access_creds - data = json.dumps({'objects': data}) + data = jsonutils.dumps({'objects': data}) r = requests.request( method, diff --git a/requirements.txt b/requirements.txt index 25dc4d51..db6e05e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,7 @@ gevent==0.13.8 importlib keystonemiddleware>=1.2.0 kombu +oslo.serialization>=1.0.0 pecan>=0.3.0,<0.6.0 psycopg2>=2.5.1 stevedore>=0.10