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:
parent
8a1d398770
commit
1984fb4136
@ -1,5 +1,5 @@
|
|||||||
Barbican Style Commandments
|
Barbican Style Commandments
|
||||||
============================
|
===========================
|
||||||
|
|
||||||
- Step 1: Read the OpenStack Style Commandments
|
- Step 1: Read the OpenStack Style Commandments
|
||||||
https://docs.openstack.org/hacking/latest/
|
https://docs.openstack.org/hacking/latest/
|
||||||
@ -7,7 +7,7 @@ Barbican Style Commandments
|
|||||||
|
|
||||||
|
|
||||||
Barbican Specific Commandments
|
Barbican Specific Commandments
|
||||||
-------------------------------
|
------------------------------
|
||||||
|
|
||||||
- [B310] Check for improper use of logging format arguments.
|
- [B310] Check for improper use of logging format arguments.
|
||||||
- [B311] Use assertIsNone(...) instead of assertEqual(None, ...).
|
- [B311] Use assertIsNone(...) instead of assertEqual(None, ...).
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
import pecan
|
import pecan
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import newrelic.agent
|
import newrelic.agent
|
||||||
@ -29,7 +29,7 @@ from barbican.model import repositories
|
|||||||
class JSONErrorHook(pecan.hooks.PecanHook):
|
class JSONErrorHook(pecan.hooks.PecanHook):
|
||||||
def on_error(self, state, exc):
|
def on_error(self, state, exc):
|
||||||
if isinstance(exc, webob.exc.HTTPError):
|
if isinstance(exc, webob.exc.HTTPError):
|
||||||
exc.body = jsonutils.dump_as_bytes({
|
exc.body = json.dump_as_bytes({
|
||||||
'code': exc.status_int,
|
'code': exc.status_int,
|
||||||
'title': exc.title,
|
'title': exc.title,
|
||||||
'description': exc.detail
|
'description': exc.detail
|
||||||
|
@ -11,12 +11,13 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
import base64
|
||||||
import json
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from oslo_db.sqlalchemy import session
|
from oslo_db.sqlalchemy import session
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from sqlalchemy.orm import scoping
|
from sqlalchemy.orm import scoping
|
||||||
|
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
import base64
|
||||||
import json
|
|
||||||
import six
|
import six
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from oslo_db.sqlalchemy import session
|
from oslo_db.sqlalchemy import session
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
from sqlalchemy.orm import scoping
|
from sqlalchemy.orm import scoping
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import json
|
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from oslo_versionedobjects import fields
|
from oslo_versionedobjects import fields
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -12,9 +12,11 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import json
|
|
||||||
import mock
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import mock
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from barbican.tests import utils
|
from barbican.tests import utils
|
||||||
|
@ -21,11 +21,12 @@ required including the Barbican Python client. Note that this script is not
|
|||||||
intended to replace DevStack or Tempest style testing.
|
intended to replace DevStack or Tempest style testing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
LOG.setLevel(logging.DEBUG)
|
LOG.setLevel(logging.DEBUG)
|
||||||
|
@ -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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
import json
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
from functionaltests.api.v1.behaviors import base_behaviors
|
from functionaltests.api.v1.behaviors import base_behaviors
|
||||||
|
|
||||||
|
@ -12,10 +12,11 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from oslo_serialization import jsonutils
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from oslo_serialization import jsonutils as json
|
||||||
import testtools
|
import testtools
|
||||||
from testtools import testcase
|
from testtools import testcase
|
||||||
|
|
||||||
@ -296,7 +297,7 @@ class OrdersTestCase(base.TestCase):
|
|||||||
resp, order_ref = self.behaviors.create_order(test_model)
|
resp, order_ref = self.behaviors.create_order(test_model)
|
||||||
|
|
||||||
# Make sure we actually get a message back
|
# 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.assertEqual(400, resp.status_code)
|
||||||
self.assertIsNotNone(error_msg)
|
self.assertIsNotNone(error_msg)
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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 testtools import testcase
|
||||||
|
|
||||||
from barbican.tests import utils
|
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 secret_behaviors
|
||||||
from functionaltests.api.v1.behaviors import secretmeta_behaviors
|
from functionaltests.api.v1.behaviors import secretmeta_behaviors
|
||||||
from functionaltests.api.v1.models import secret_models
|
from functionaltests.api.v1.models import secret_models
|
||||||
from oslo_utils import uuidutils
|
|
||||||
|
|
||||||
|
|
||||||
@utils.parameterized_test_case
|
@utils.parameterized_test_case
|
||||||
@ -107,7 +108,7 @@ class SecretMetadataTestCase(base.TestCase):
|
|||||||
|
|
||||||
get_resp = self.behaviors.get_metadata(secret_ref)
|
get_resp = self.behaviors.get_metadata(secret_ref)
|
||||||
self.assertEqual(200, get_resp.status_code)
|
self.assertEqual(200, get_resp.status_code)
|
||||||
self.assertEqual(jsonutils.loads(get_resp.content),
|
self.assertEqual(json.loads(get_resp.content),
|
||||||
self.valid_metadata)
|
self.valid_metadata)
|
||||||
|
|
||||||
@testcase.attr('negative')
|
@testcase.attr('negative')
|
||||||
@ -171,7 +172,7 @@ class SecretMetadataTestCase(base.TestCase):
|
|||||||
get_resp = self.behaviors.get_metadatum(secret_ref,
|
get_resp = self.behaviors.get_metadatum(secret_ref,
|
||||||
self.valid_metadatum_key)
|
self.valid_metadatum_key)
|
||||||
self.assertEqual(200, get_resp.status_code)
|
self.assertEqual(200, get_resp.status_code)
|
||||||
self.assertEqual(jsonutils.loads(get_resp.content),
|
self.assertEqual(json.loads(get_resp.content),
|
||||||
self.valid_metadatum)
|
self.valid_metadatum)
|
||||||
|
|
||||||
@testcase.attr('negative')
|
@testcase.attr('negative')
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from oslo_serialization import base64 as oslo_base64
|
from oslo_serialization import base64 as oslo_base64
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils as json
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
import testtools
|
import testtools
|
||||||
@ -512,7 +512,7 @@ class SecretsTestCase(base.TestCase):
|
|||||||
# first, ensure that the return code is 400
|
# first, ensure that the return code is 400
|
||||||
self.assertEqual(400, resp.status_code)
|
self.assertEqual(400, resp.status_code)
|
||||||
|
|
||||||
resp_dict = jsonutils.loads(resp.content)
|
resp_dict = json.loads(resp.content)
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"Provided object does not match schema 'Secret': "
|
"Provided object does not match schema 'Secret': "
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils as json
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class BaseModel(object):
|
|||||||
|
|
||||||
:return: A string of JSON containing the fields in this 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):
|
def obj_to_dict(self):
|
||||||
"""Create a dict of the values for this model object.
|
"""Create a dict of the values for this model object.
|
||||||
@ -74,7 +74,7 @@ class BaseModel(object):
|
|||||||
:return: a secret object
|
:return: a secret object
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
json_dict = jsonutils.loads(serialized_str)
|
json_dict = json.loads(serialized_str)
|
||||||
return cls.dict_to_obj(json_dict)
|
return cls.dict_to_obj(json_dict)
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
LOG.error('Couldn\'t deserialize input: %s\n Because: %s',
|
LOG.error('Couldn\'t deserialize input: %s\n Because: %s',
|
||||||
|
Loading…
Reference in New Issue
Block a user