Use oslo_serialization instead of the json module directly
* Always use oslo jsonutils. * Consistently import jsonutils as-is. * Use dump_as_bytes instead of dumps. https://wiki.openstack.org/wiki/Python3#Serialization:_base64.2C_JSON.2C_etc. Change-Id: I2b65faa7df43a1d58205e8ff106ff62f73d78198
This commit is contained in:
parent
6e19837ad1
commit
daf34d9df8
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
from glanceclient import exc as glance_exception
|
from glanceclient import exc as glance_exception
|
||||||
from novaclient import exceptions as nova_exception
|
from novaclient import exceptions as nova_exception
|
||||||
from oslo_serialization import jsonutils as json
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from magnum.api import utils as api_utils
|
from magnum.api import utils as api_utils
|
||||||
from magnum.common import clients
|
from magnum.common import clients
|
||||||
@ -165,7 +165,7 @@ def validate_labels_executor_env_variables(labels):
|
|||||||
mesos_slave_executor_env_val = labels.get(
|
mesos_slave_executor_env_val = labels.get(
|
||||||
'mesos_slave_executor_env_variables')
|
'mesos_slave_executor_env_variables')
|
||||||
try:
|
try:
|
||||||
json.loads(mesos_slave_executor_env_val)
|
jsonutils.loads(mesos_slave_executor_env_val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
err = (_("Json format error"))
|
err = (_("Json format error"))
|
||||||
raise exception.InvalidParameterValue(err)
|
raise exception.InvalidParameterValue(err)
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
# 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
|
||||||
import six
|
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ class HTTPNotAcceptableAPIVersion(exc.HTTPNotAcceptable):
|
|||||||
for err_str in self.app_iter:
|
for err_str in self.app_iter:
|
||||||
err = {}
|
err = {}
|
||||||
try:
|
try:
|
||||||
err = json.loads(err_str.decode('utf-8'))
|
err = jsonutils.loads(err_str.decode('utf-8'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -63,7 +62,7 @@ class HTTPNotAcceptableAPIVersion(exc.HTTPNotAcceptable):
|
|||||||
err['links'] = [links]
|
err['links'] = [links]
|
||||||
err['title'] = "Requested microversion is unsupported"
|
err['title'] = "Requested microversion is unsupported"
|
||||||
|
|
||||||
self.app_iter = [six.b(json.dumps(err))]
|
self.app_iter = [jsonutils.dump_as_bytes(err)]
|
||||||
self.headers['Content-Length'] = str(len(self.app_iter[0]))
|
self.headers['Content-Length'] = str(len(self.app_iter[0]))
|
||||||
|
|
||||||
return super(HTTPNotAcceptableAPIVersion, self).__call__(
|
return super(HTTPNotAcceptableAPIVersion, self).__call__(
|
||||||
|
@ -18,8 +18,7 @@ response with one formatted so the client can parse it.
|
|||||||
Based on pecan.middleware.errordocument
|
Based on pecan.middleware.errordocument
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
|
|
||||||
from magnum.i18n import _
|
from magnum.i18n import _
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ class ParsableErrorMiddleware(object):
|
|||||||
for err_str in app_iter:
|
for err_str in app_iter:
|
||||||
err = {}
|
err = {}
|
||||||
try:
|
try:
|
||||||
err = json.loads(err_str.decode('utf-8'))
|
err = jsonutils.loads(err_str.decode('utf-8'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -96,7 +95,7 @@ class ParsableErrorMiddleware(object):
|
|||||||
|
|
||||||
if (state['status_code'] // 100) not in (2, 3):
|
if (state['status_code'] // 100) not in (2, 3):
|
||||||
errs = self._update_errors(app_iter, state['status_code'])
|
errs = self._update_errors(app_iter, state['status_code'])
|
||||||
body = [six.b(json.dumps({'errors': errs}))]
|
body = [jsonutils.dump_as_bytes({'errors': errs})]
|
||||||
state['headers'].append(('Content-Type', 'application/json'))
|
state['headers'].append(('Content-Type', 'application/json'))
|
||||||
state['headers'].append(('Content-Length', str(len(body[0]))))
|
state['headers'].append(('Content-Length', str(len(body[0]))))
|
||||||
|
|
||||||
|
@ -16,10 +16,9 @@
|
|||||||
SQLAlchemy models for container service
|
SQLAlchemy models for container service
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from oslo_db.sqlalchemy import models
|
from oslo_db.sqlalchemy import models
|
||||||
from oslo_db.sqlalchemy.types import String
|
from oslo_db.sqlalchemy.types import String
|
||||||
|
from oslo_serialization import jsonutils
|
||||||
import six.moves.urllib.parse as urlparse
|
import six.moves.urllib.parse as urlparse
|
||||||
from sqlalchemy import Boolean
|
from sqlalchemy import Boolean
|
||||||
from sqlalchemy import Column
|
from sqlalchemy import Column
|
||||||
@ -61,12 +60,12 @@ class JsonEncodedType(TypeDecorator):
|
|||||||
"given" % {'class': self.__class__.__name__,
|
"given" % {'class': self.__class__.__name__,
|
||||||
'type': self.type.__name__,
|
'type': self.type.__name__,
|
||||||
'value': type(value).__name__})
|
'value': type(value).__name__})
|
||||||
serialized_value = json.dumps(value)
|
serialized_value = jsonutils.dumps(value)
|
||||||
return serialized_value
|
return serialized_value
|
||||||
|
|
||||||
def process_result_value(self, value, dialect):
|
def process_result_value(self, value, dialect):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
value = json.loads(value)
|
value = jsonutils.loads(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import sys
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
HEAT_PARAMS_PATH = '/etc/sysconfig/heat-params'
|
HEAT_PARAMS_PATH = '/etc/sysconfig/heat-params'
|
||||||
PUBLIC_IP_URL = 'http://169.254.169.254/latest/meta-data/public-ipv4'
|
PUBLIC_IP_URL = 'http://169.254.169.254/latest/meta-data/public-ipv4'
|
||||||
CERT_DIR = '/etc/docker'
|
CERT_DIR = '/etc/docker'
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# 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
|
||||||
|
|
||||||
from magnum.tests.functional.common import models
|
from magnum.tests.functional.common import models
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class BayModelPatchCollection(models.CollectionModel):
|
|||||||
collection = []
|
collection = []
|
||||||
for d in data:
|
for d in data:
|
||||||
collection.append(d.to_dict())
|
collection.append(d.to_dict())
|
||||||
return json.dumps(collection)
|
return jsonutils.dumps(collection)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# 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
|
||||||
|
|
||||||
from magnum.tests.functional.common import models
|
from magnum.tests.functional.common import models
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class BayPatchCollection(models.CollectionModel):
|
|||||||
collection = []
|
collection = []
|
||||||
for d in data:
|
for d in data:
|
||||||
collection.append(d.to_dict())
|
collection.append(d.to_dict())
|
||||||
return json.dumps(collection)
|
return jsonutils.dumps(collection)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# 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
|
||||||
|
|
||||||
from magnum.tests.functional.common import models
|
from magnum.tests.functional.common import models
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class ClusterTemplatePatchCollection(models.CollectionModel):
|
|||||||
collection = []
|
collection = []
|
||||||
for d in data:
|
for d in data:
|
||||||
collection.append(d.to_dict())
|
collection.append(d.to_dict())
|
||||||
return json.dumps(collection)
|
return jsonutils.dumps(collection)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# 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
|
||||||
|
|
||||||
from magnum.tests.functional.common import models
|
from magnum.tests.functional.common import models
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class ClusterPatchCollection(models.CollectionModel):
|
|||||||
collection = []
|
collection = []
|
||||||
for d in data:
|
for d in data:
|
||||||
collection.append(d.to_dict())
|
collection.append(d.to_dict())
|
||||||
return json.dumps(collection)
|
return jsonutils.dumps(collection)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(object):
|
class BaseModel(object):
|
||||||
@ -18,10 +18,10 @@ class BaseModel(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, json_str):
|
def from_json(cls, json_str):
|
||||||
return cls.from_dict(json.loads(json_str))
|
return cls.from_dict(jsonutils.loads(json_str))
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return json.dumps(self.to_dict())
|
return jsonutils.dumps(self.to_dict())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data):
|
def from_dict(cls, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user