diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-10-08 17:05:37 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-10-08 17:05:37 +0000 |
commit | a3379c16e48a1414e11d16dbc69e984aac5ddf9d (patch) | |
tree | 37021a8a23032ee93da85080af7d866340d43146 | |
parent | 9825eb17d64d1b2134d553d41661e7499402fe72 (diff) | |
parent | da93f408dde9652a3f5e2daaa534852576b8f6f2 (diff) | |
download | glance-a3379c16e48a1414e11d16dbc69e984aac5ddf9d.tar.gz |
Merge "Metadef Property and Object schema columns should use JSONEncodedDict" into proposed/juno
-rw-r--r-- | glance/api/v2/metadef_namespaces.py | 3 | ||||
-rw-r--r-- | glance/api/v2/metadef_properties.py | 10 | ||||
-rw-r--r-- | glance/api/v2/model/metadef_namespace.py | 6 | ||||
-rw-r--r-- | glance/db/__init__.py | 6 | ||||
-rw-r--r-- | glance/db/sqlalchemy/migrate_repo/versions/035_add_metadef_tables.py | 4 | ||||
-rw-r--r-- | glance/db/sqlalchemy/models_metadef.py | 5 | ||||
-rw-r--r-- | glance/tests/unit/test_db_metadef.py | 4 | ||||
-rw-r--r-- | glance/tests/unit/v2/test_metadef_resources.py | 4 |
8 files changed, 19 insertions, 23 deletions
diff --git a/glance/api/v2/metadef_namespaces.py b/glance/api/v2/metadef_namespaces.py index 6e334faec..b807af9a4 100644 --- a/glance/api/v2/metadef_namespaces.py +++ b/glance/api/v2/metadef_namespaces.py @@ -171,9 +171,8 @@ class NamespaceController(object): def _to_property_dict(self, name, value): # Convert the model PropertyTypes dict to a JSON string - json_data = tojson(PropertyType, value) db_property_type_dict = dict() - db_property_type_dict['schema'] = json.dumps(json_data) + db_property_type_dict['schema'] = tojson(PropertyType, value) db_property_type_dict['name'] = name return db_property_type_dict diff --git a/glance/api/v2/metadef_properties.py b/glance/api/v2/metadef_properties.py index 5f2760695..06787e193 100644 --- a/glance/api/v2/metadef_properties.py +++ b/glance/api/v2/metadef_properties.py @@ -47,17 +47,17 @@ class NamespacePropertiesController(object): policy_enforcer=self.policy) def _to_dict(self, model_property_type): - # Convert the model PropertyTypes dict to a JSON string - json_data = tojson(PropertyType, model_property_type) + # Convert the model PropertyTypes dict to a JSON encoding db_property_type_dict = dict() - db_property_type_dict['schema'] = json.dumps(json_data) + db_property_type_dict['schema'] = 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 - json_props = json.loads(db_property_type.schema) - property_type = fromjson(PropertyType, json_props) + property_type = fromjson( + PropertyType, db_property_type.schema) property_type.name = db_property_type.name return property_type diff --git a/glance/api/v2/model/metadef_namespace.py b/glance/api/v2/model/metadef_namespace.py index b93ec568e..90a1b7aee 100644 --- a/glance/api/v2/model/metadef_namespace.py +++ b/glance/api/v2/model/metadef_namespace.py @@ -21,7 +21,6 @@ from glance.api.v2.model.metadef_object import MetadefObject from glance.api.v2.model.metadef_property_type import PropertyType from glance.api.v2.model.metadef_resource_type import ResourceTypeAssociation from glance.common.wsme_utils import WSMEModelTransformer -from glance.openstack.common import jsonutils as json class Namespace(types.Base, WSMEModelTransformer): @@ -57,9 +56,8 @@ 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 - json_props = json.loads(db_property_type.schema) - property_type = fromjson(PropertyType, json_props) - + property_type = 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 f6e402b5c..fd0b84cfa 100644 --- a/glance/db/__init__.py +++ b/glance/db/__init__.py @@ -27,7 +27,6 @@ from glance.common import location_strategy import glance.domain import glance.domain.proxy from glance.openstack.common import importutils -from glance.openstack.common import jsonutils as json CONF = cfg.CONF CONF.import_opt('image_size_cap', 'glance.common.config') @@ -508,7 +507,7 @@ class MetadefObjectRepo(object): # Convert the persisted json schema to a dict of PropertyTypes property_types = {} - json_props = json.loads(metadata_object['schema']) + json_props = metadata_object['schema'] for id in json_props: property_types[id] = fromjson(PropertyType, json_props[id]) @@ -535,13 +534,12 @@ class MetadefObjectRepo(object): for k, v in properties.items(): json_data = tojson(PropertyType, v) db_schema[k] = json_data - property_schema = json.dumps(db_schema) db_metadata_object = { 'name': metadata_object.name, 'required': required_str, 'description': metadata_object.description, - 'schema': property_schema + 'schema': db_schema } return db_metadata_object diff --git a/glance/db/sqlalchemy/migrate_repo/versions/035_add_metadef_tables.py b/glance/db/sqlalchemy/migrate_repo/versions/035_add_metadef_tables.py index 44b58aa59..c53d06700 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/035_add_metadef_tables.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/035_add_metadef_tables.py @@ -89,7 +89,7 @@ def define_metadef_objects_table(meta): Column('name', String(80), nullable=False), Column('description', Text()), Column('required', Text()), - Column('schema', Text()), + Column('schema', Text(), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), UniqueConstraint('namespace_id', 'name', @@ -118,7 +118,7 @@ def define_metadef_properties_table(meta): Column('namespace_id', Integer(), ForeignKey('metadef_namespaces.id'), nullable=False), Column('name', String(80), nullable=False), - Column('schema', Text()), + Column('schema', Text(), nullable=False), Column('created_at', DateTime(), nullable=False), Column('updated_at', DateTime()), UniqueConstraint('namespace_id', 'name', **_constr_kwargs), diff --git a/glance/db/sqlalchemy/models_metadef.py b/glance/db/sqlalchemy/models_metadef.py index a01946129..d156a4fee 100644 --- a/glance/db/sqlalchemy/models_metadef.py +++ b/glance/db/sqlalchemy/models_metadef.py @@ -28,6 +28,7 @@ from sqlalchemy.orm import relationship from sqlalchemy import String from sqlalchemy import Text +from glance.db.sqlalchemy.models import JSONEncodedDict from glance.openstack.common import timeutils @@ -88,7 +89,7 @@ class MetadefObject(BASE_DICT, GlanceMetadefBase): name = Column(String(80), nullable=False) description = Column(Text()) required = Column(Text()) - schema = Column(Text(), default={}) + schema = Column(JSONEncodedDict(), default={}) class MetadefProperty(BASE_DICT, GlanceMetadefBase): @@ -102,7 +103,7 @@ class MetadefProperty(BASE_DICT, GlanceMetadefBase): namespace_id = Column(Integer(), ForeignKey('metadef_namespaces.id'), nullable=False) name = Column(String(80), nullable=False) - schema = Column(Text(), default={}) + schema = Column(JSONEncodedDict(), default={}) class MetadefNamespaceResourceType(BASE_DICT, GlanceMetadefBase): diff --git a/glance/tests/unit/test_db_metadef.py b/glance/tests/unit/test_db_metadef.py index 74c11bead..f4900e5b8 100644 --- a/glance/tests/unit/test_db_metadef.py +++ b/glance/tests/unit/test_db_metadef.py @@ -62,7 +62,7 @@ def _db_namespace_fixture(**kwargs): def _db_property_fixture(name, **kwargs): property = { 'name': name, - 'schema': '{"type": "string", "title": "title"}', + 'schema': {"type": "string", "title": "title"}, } property.update(kwargs) return property @@ -72,7 +72,7 @@ def _db_object_fixture(name, **kwargs): obj = { 'name': name, 'description': None, - 'schema': '{}', + 'schema': {}, 'required': '[]', } obj.update(kwargs) diff --git a/glance/tests/unit/v2/test_metadef_resources.py b/glance/tests/unit/v2/test_metadef_resources.py index 9bd1599e5..87aff8a08 100644 --- a/glance/tests/unit/v2/test_metadef_resources.py +++ b/glance/tests/unit/v2/test_metadef_resources.py @@ -69,7 +69,7 @@ def _db_namespace_fixture(namespace, **kwargs): def _db_property_fixture(name, **kwargs): obj = { 'name': name, - 'schema': '{"type": "string", "title": "title"}', + 'schema': {"type": "string", "title": "title"}, } obj.update(kwargs) return obj @@ -79,7 +79,7 @@ def _db_object_fixture(name, **kwargs): obj = { 'name': name, 'description': None, - 'schema': '{}', + 'schema': {}, 'required': '[]', } obj.update(kwargs) |