From d25fa06db65d750ceda57b680114473b357fe7f2 Mon Sep 17 00:00:00 2001 From: Roman Vasilets Date: Fri, 14 Nov 2014 19:02:25 +0200 Subject: [PATCH] metadef modules should only use - from wsme.rest import json Several metadef module routines use: from wsme.rest.json import fromjson from wsme.rest.json import tojson To follow the import rules at http://docs.openstack.org/developer/hacking/ (only import modules), these should be replaced with: from wsme.rest import json Change-Id: Idc496c8753d93a3d39f0c9cbbb31205948eeb081 Closes-bug: 1392485 --- glance/api/v2/metadef_namespaces.py | 21 +++++++++---------- glance/api/v2/metadef_objects.py | 17 +++++++-------- glance/api/v2/metadef_properties.py | 21 +++++++++---------- glance/api/v2/metadef_resource_types.py | 19 ++++++++--------- glance/api/v2/model/metadef_namespace.py | 4 ++-- glance/db/__init__.py | 7 +++---- .../v2/test_metadef_resourcetypes.py | 19 ++++++++--------- 7 files changed, 51 insertions(+), 57 deletions(-) diff --git a/glance/api/v2/metadef_namespaces.py b/glance/api/v2/metadef_namespaces.py index 4db5a17240..64f06463af 100644 --- a/glance/api/v2/metadef_namespaces.py +++ b/glance/api/v2/metadef_namespaces.py @@ -14,12 +14,11 @@ # limitations under the License. from oslo.config import cfg -from oslo.serialization import jsonutils as json +from oslo.serialization import jsonutils import six import six.moves.urllib.parse as urlparse import webob.exc -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api import policy from glance.api.v2.model.metadef_namespace import Namespace @@ -172,7 +171,7 @@ class NamespaceController(object): def _to_property_dict(self, name, value): # Convert the model PropertyTypes dict to a JSON string db_property_type_dict = dict() - db_property_type_dict['schema'] = tojson(PropertyType, value) + db_property_type_dict['schema'] = json.tojson(PropertyType, value) db_property_type_dict['name'] = name return db_property_type_dict @@ -430,7 +429,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - namespace = fromjson(Namespace, body) + namespace = json.fromjson(Namespace, body) return dict(namespace=namespace) def update(self, request): @@ -440,7 +439,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - namespace = fromjson(Namespace, body) + namespace = json.fromjson(Namespace, body) return dict(user_ns=namespace) @@ -450,12 +449,12 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema def create(self, response, namespace): - ns_json = tojson(Namespace, namespace) + ns_json = json.tojson(Namespace, namespace) response = self.__render(ns_json, response, 201) response.location = get_namespace_href(namespace) def show(self, response, namespace): - ns_json = tojson(Namespace, namespace) + ns_json = json.tojson(Namespace, namespace) response = self.__render(ns_json, response) def index(self, response, result): @@ -471,11 +470,11 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): next_query = urlparse.urlencode(params) result.next = '/v2/metadefs/namespaces?%s' % next_query - ns_json = tojson(Namespaces, result) + ns_json = json.tojson(Namespaces, result) response = self.__render(ns_json, response) def update(self, response, namespace): - ns_json = tojson(Namespace, namespace) + ns_json = json.tojson(Namespace, namespace) response = self.__render(ns_json, response, 200) def delete(self, response, result): @@ -488,7 +487,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): response.status_int = 204 def __render(self, json_data, response, response_status=None): - body = json.dumps(json_data, ensure_ascii=False) + body = jsonutils.dumps(json_data, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' if response_status: diff --git a/glance/api/v2/metadef_objects.py b/glance/api/v2/metadef_objects.py index c2cec56290..139ef6a660 100644 --- a/glance/api/v2/metadef_objects.py +++ b/glance/api/v2/metadef_objects.py @@ -14,11 +14,10 @@ # limitations under the License. from oslo.config import cfg -from oslo.serialization import jsonutils as json +from oslo.serialization import jsonutils import six import webob.exc -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api import policy from glance.api.v2 import metadef_namespaces as namespaces @@ -233,7 +232,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - metadata_object = fromjson(MetadefObject, body) + metadata_object = json.fromjson(MetadefObject, body) return dict(metadata_object=metadata_object) def update(self, request): @@ -243,7 +242,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - metadata_object = fromjson(MetadefObject, body) + metadata_object = json.fromjson(MetadefObject, body) return dict(metadata_object=metadata_object) def index(self, request): @@ -300,8 +299,8 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.show(response, metadata_object) def show(self, response, metadata_object): - metadata_object_json = tojson(MetadefObject, metadata_object) - body = json.dumps(metadata_object_json, ensure_ascii=False) + metadata_object_json = json.tojson(MetadefObject, metadata_object) + body = jsonutils.dumps(metadata_object_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' @@ -311,8 +310,8 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def index(self, response, result): result.schema = "v2/schemas/metadefs/objects" - metadata_objects_json = tojson(MetadefObjects, result) - body = json.dumps(metadata_objects_json, ensure_ascii=False) + metadata_objects_json = json.tojson(MetadefObjects, result) + body = jsonutils.dumps(metadata_objects_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' diff --git a/glance/api/v2/metadef_properties.py b/glance/api/v2/metadef_properties.py index 75abf301a0..cfef0ffe18 100644 --- a/glance/api/v2/metadef_properties.py +++ b/glance/api/v2/metadef_properties.py @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from oslo.serialization import jsonutils as json +from oslo.serialization import jsonutils import six import webob.exc -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api import policy from glance.api.v2 import metadef_namespaces as namespaces @@ -49,14 +48,14 @@ class NamespacePropertiesController(object): def _to_dict(self, model_property_type): # Convert the model PropertyTypes dict to a JSON encoding db_property_type_dict = dict() - db_property_type_dict['schema'] = tojson( + db_property_type_dict['schema'] = json.tojson( PropertyType, model_property_type) db_property_type_dict['name'] = model_property_type.name return db_property_type_dict def _to_model(self, db_property_type): # Convert the persisted json schema to a dict of PropertyTypes - property_type = fromjson( + property_type = json.fromjson( PropertyType, db_property_type.schema) property_type.name = db_property_type.name return property_type @@ -188,7 +187,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - property_type = fromjson(PropertyType, body) + property_type = json.fromjson(PropertyType, body) return dict(property_type=property_type) def update(self, request): @@ -198,7 +197,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - property_type = fromjson(PropertyType, body) + property_type = json.fromjson(PropertyType, body) return dict(property_type=property_type) def show(self, request): @@ -215,14 +214,14 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema def show(self, response, result): - property_type_json = tojson(PropertyType, result) - body = json.dumps(property_type_json, ensure_ascii=False) + property_type_json = json.tojson(PropertyType, result) + body = jsonutils.dumps(property_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def index(self, response, result): - property_type_json = tojson(PropertyTypes, result) - body = json.dumps(property_type_json, ensure_ascii=False) + property_type_json = json.tojson(PropertyTypes, result) + body = jsonutils.dumps(property_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' diff --git a/glance/api/v2/metadef_resource_types.py b/glance/api/v2/metadef_resource_types.py index 96d48de99a..e586ea0566 100644 --- a/glance/api/v2/metadef_resource_types.py +++ b/glance/api/v2/metadef_resource_types.py @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from oslo.serialization import jsonutils as json +from oslo.serialization import jsonutils import six import webob.exc -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api import policy from glance.api.v2.model.metadef_resource_type import ResourceType @@ -160,7 +159,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - resource_type = fromjson(ResourceTypeAssociation, body) + resource_type = json.fromjson(ResourceTypeAssociation, body) return dict(resource_type=resource_type) @@ -170,21 +169,21 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema def show(self, response, result): - resource_type_json = tojson(ResourceTypeAssociations, result) - body = json.dumps(resource_type_json, ensure_ascii=False) + resource_type_json = json.tojson(ResourceTypeAssociations, result) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def index(self, response, result): - resource_type_json = tojson(ResourceTypes, result) - body = json.dumps(resource_type_json, ensure_ascii=False) + resource_type_json = json.tojson(ResourceTypes, result) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def create(self, response, result): - resource_type_json = tojson(ResourceTypeAssociation, result) + resource_type_json = json.tojson(ResourceTypeAssociation, result) response.status_int = 201 - body = json.dumps(resource_type_json, ensure_ascii=False) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' diff --git a/glance/api/v2/model/metadef_namespace.py b/glance/api/v2/model/metadef_namespace.py index 041ce35dd8..f951d40074 100644 --- a/glance/api/v2/model/metadef_namespace.py +++ b/glance/api/v2/model/metadef_namespace.py @@ -14,7 +14,7 @@ # limitations under the License. import wsme -from wsme.rest.json import fromjson +from wsme.rest import json from wsme import types from glance.api.v2.model.metadef_object import MetadefObject @@ -56,7 +56,7 @@ class Namespace(types.Base, WSMEModelTransformer): property_types = {} for db_property_type in db_property_types: # Convert the persisted json schema to a dict of PropertyTypes - property_type = fromjson( + property_type = json.fromjson( PropertyType, db_property_type.schema) property_type_name = db_property_type.name property_types[property_type_name] = property_type diff --git a/glance/db/__init__.py b/glance/db/__init__.py index 0cc5e37be7..ea2777d7bc 100644 --- a/glance/db/__init__.py +++ b/glance/db/__init__.py @@ -18,8 +18,7 @@ from oslo.config import cfg from oslo.utils import importutils -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api.v2.model.metadef_property_type import PropertyType from glance.common import crypt @@ -509,7 +508,7 @@ class MetadefObjectRepo(object): property_types = {} json_props = metadata_object['json_schema'] for id in json_props: - property_types[id] = fromjson(PropertyType, json_props[id]) + property_types[id] = json.fromjson(PropertyType, json_props[id]) return glance.domain.MetadefObject( namespace=namespace_entity, @@ -532,7 +531,7 @@ class MetadefObjectRepo(object): db_schema = {} if properties: for k, v in properties.items(): - json_data = tojson(PropertyType, v) + json_data = json.tojson(PropertyType, v) db_schema[k] = json_data db_metadata_object = { diff --git a/glance/tests/functional/v2/test_metadef_resourcetypes.py b/glance/tests/functional/v2/test_metadef_resourcetypes.py index 597530bfe4..98910cb2aa 100644 --- a/glance/tests/functional/v2/test_metadef_resourcetypes.py +++ b/glance/tests/functional/v2/test_metadef_resourcetypes.py @@ -13,11 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from oslo.serialization import jsonutils as json +from oslo.serialization import jsonutils import six import webob.exc -from wsme.rest.json import fromjson -from wsme.rest.json import tojson +from wsme.rest import json from glance.api import policy from glance.api.v2.model.metadef_resource_type import ResourceType @@ -164,7 +163,7 @@ class RequestDeserializer(wsgi.JSONRequestDeserializer): self.schema.validate(body) except exception.InvalidObject as e: raise webob.exc.HTTPBadRequest(explanation=e.msg) - resource_type = fromjson(ResourceTypeAssociation, body) + resource_type = json.fromjson(ResourceTypeAssociation, body) return dict(resource_type=resource_type) @@ -174,21 +173,21 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): self.schema = schema def show(self, response, result): - resource_type_json = tojson(ResourceTypeAssociations, result) - body = json.dumps(resource_type_json, ensure_ascii=False) + resource_type_json = json.tojson(ResourceTypeAssociations, result) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def index(self, response, result): - resource_type_json = tojson(ResourceTypes, result) - body = json.dumps(resource_type_json, ensure_ascii=False) + resource_type_json = json.tojson(ResourceTypes, result) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json' def create(self, response, result): - resource_type_json = tojson(ResourceTypeAssociation, result) + resource_type_json = json.tojson(ResourceTypeAssociation, result) response.status_int = 201 - body = json.dumps(resource_type_json, ensure_ascii=False) + body = jsonutils.dumps(resource_type_json, ensure_ascii=False) response.unicode_body = six.text_type(body) response.content_type = 'application/json'