Update json module to jsonutils

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

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

Change-Id: I958a711db17bb1aa86fc4cd23c00cec185b84ab2
This commit is contained in:
zhulingjie 2019-02-20 23:43:12 +08:00 committed by caoyuan
parent 8a1d398770
commit 1984fb4136
12 changed files with 30 additions and 22 deletions

View File

@ -1,5 +1,5 @@
Barbican Style Commandments
============================
===========================
- Step 1: Read the OpenStack Style Commandments
https://docs.openstack.org/hacking/latest/
@ -7,7 +7,7 @@ Barbican Style Commandments
Barbican Specific Commandments
-------------------------------
------------------------------
- [B310] Check for improper use of logging format arguments.
- [B311] Use assertIsNone(...) instead of assertEqual(None, ...).

View File

@ -15,7 +15,7 @@
import pecan
import webob
from oslo_serialization import jsonutils
from oslo_serialization import jsonutils as json
try:
import newrelic.agent
@ -29,7 +29,7 @@ from barbican.model import repositories
class JSONErrorHook(pecan.hooks.PecanHook):
def on_error(self, state, exc):
if isinstance(exc, webob.exc.HTTPError):
exc.body = jsonutils.dump_as_bytes({
exc.body = json.dump_as_bytes({
'code': exc.status_int,
'title': exc.title,
'description': exc.detail

View File

@ -11,12 +11,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import base64
import json
import traceback
from oslo_db.sqlalchemy import session
from oslo_serialization import jsonutils as json
from sqlalchemy import orm
from sqlalchemy.orm import scoping

View File

@ -11,13 +11,14 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import base64
import json
import six
import traceback
from oslo_db.sqlalchemy import session
from oslo_serialization import jsonutils as json
from sqlalchemy import orm
from sqlalchemy.orm import scoping

View File

@ -11,8 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six

View File

@ -12,9 +12,11 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import mock
import os
import mock
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from barbican.tests import utils

View File

@ -21,11 +21,12 @@ required including the Barbican Python client. Note that this script is not
intended to replace DevStack or Tempest style testing.
"""
import json
import logging
import requests
import sys
from oslo_serialization import jsonutils as json
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)

View File

@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import json
from oslo_serialization import jsonutils as json
from functionaltests.api.v1.behaviors import base_behaviors

View File

@ -12,10 +12,11 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_serialization import jsonutils
import sys
import time
from oslo_serialization import jsonutils as json
import testtools
from testtools import testcase
@ -296,7 +297,7 @@ class OrdersTestCase(base.TestCase):
resp, order_ref = self.behaviors.create_order(test_model)
# Make sure we actually get a message back
error_msg = jsonutils.loads(resp.content).get('title')
error_msg = json.loads(resp.content).get('title')
self.assertEqual(400, resp.status_code)
self.assertIsNotNone(error_msg)

View File

@ -12,7 +12,9 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_serialization import jsonutils
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from testtools import testcase
from barbican.tests import utils
@ -20,7 +22,6 @@ from functionaltests.api import base
from functionaltests.api.v1.behaviors import secret_behaviors
from functionaltests.api.v1.behaviors import secretmeta_behaviors
from functionaltests.api.v1.models import secret_models
from oslo_utils import uuidutils
@utils.parameterized_test_case
@ -107,7 +108,7 @@ class SecretMetadataTestCase(base.TestCase):
get_resp = self.behaviors.get_metadata(secret_ref)
self.assertEqual(200, get_resp.status_code)
self.assertEqual(jsonutils.loads(get_resp.content),
self.assertEqual(json.loads(get_resp.content),
self.valid_metadata)
@testcase.attr('negative')
@ -171,7 +172,7 @@ class SecretMetadataTestCase(base.TestCase):
get_resp = self.behaviors.get_metadatum(secret_ref,
self.valid_metadatum_key)
self.assertEqual(200, get_resp.status_code)
self.assertEqual(jsonutils.loads(get_resp.content),
self.assertEqual(json.loads(get_resp.content),
self.valid_metadatum)
@testcase.attr('negative')

View File

@ -15,7 +15,7 @@
import datetime
from oslo_serialization import base64 as oslo_base64
from oslo_serialization import jsonutils
from oslo_serialization import jsonutils as json
import six
import sys
import testtools
@ -512,7 +512,7 @@ class SecretsTestCase(base.TestCase):
# first, ensure that the return code is 400
self.assertEqual(400, resp.status_code)
resp_dict = jsonutils.loads(resp.content)
resp_dict = json.loads(resp.content)
self.assertIn(
"Provided object does not match schema 'Secret': "

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
from oslo_serialization import jsonutils
from oslo_serialization import jsonutils as json
LOG = logging.getLogger(__name__)
@ -34,7 +34,7 @@ class BaseModel(object):
:return: A string of JSON containing the fields in this object
"""
return jsonutils.dump_as_bytes(self.obj_to_dict())
return json.dump_as_bytes(self.obj_to_dict())
def obj_to_dict(self):
"""Create a dict of the values for this model object.
@ -74,7 +74,7 @@ class BaseModel(object):
:return: a secret object
"""
try:
json_dict = jsonutils.loads(serialized_str)
json_dict = json.loads(serialized_str)
return cls.dict_to_obj(json_dict)
except TypeError as e:
LOG.error('Couldn\'t deserialize input: %s\n Because: %s',