def publish(self, artifact): try: artifact_changed = (self.db_api.artifact_publish( self.context, artifact.id, artifact.type_name, artifact.type_version)) return serialization.deserialize_from_db(artifact_changed, self.plugins) except (exception.NotFound, exception.Forbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg)
def save(self, artifact): artifact_values = serialization.serialize_for_db(artifact) try: db_api_artifact = self.db_api.artifact_update( self.context, artifact_values, artifact.id, artifact.type_name, artifact.type_version) except (exception.ArtifactNotFound, exception.ArtifactForbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg) return serialization.deserialize_from_db(db_api_artifact, self.plugins)
def publish(self, artifact): try: artifact_changed = ( self.db_api.artifact_publish( self.context, artifact.id, artifact.type_name, artifact.type_version)) return serialization.deserialize_from_db(artifact_changed, self.plugins) except (exception.NotFound, exception.Forbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg)
def list(self, marker=None, limit=None, sort_keys=None, sort_dirs=None, filters=None, show_level=None): sort_keys = ['created_at'] if sort_keys is None else sort_keys sort_dirs = ['desc'] if sort_dirs is None else sort_dirs if show_level is None: show_level = ga.Showlevel.NONE db_api_artifacts = self.db_api.artifact_get_all( self.context, filters=filters, marker=marker, limit=limit, sort_keys=sort_keys, sort_dirs=sort_dirs, show_level=show_level) artifacts = [] for db_api_artifact in db_api_artifacts: artifact = serialization.deserialize_from_db(db_api_artifact, self.plugins) artifacts.append(artifact) return artifacts
def get(self, artifact_id, type_name=None, type_version=None, show_level=None, include_deleted=False): if show_level is None: show_level = ga.Showlevel.BASIC try: db_api_artifact = self.db_api.artifact_get(self.context, artifact_id, type_name, type_version, show_level) if db_api_artifact["state"] == 'deleted' and not include_deleted: raise exception.ArtifactNotFound(artifact_id) except (exception.ArtifactNotFound, exception.ArtifactForbidden): msg = _("No artifact found with ID %s") % artifact_id raise exception.ArtifactNotFound(msg) return serialization.deserialize_from_db(db_api_artifact, self.plugins)
def list(self, marker=None, limit=None, sort_keys=None, sort_dirs=None, filters=None, show_level=None): sort_keys = ['created_at'] if sort_keys is None else sort_keys sort_dirs = ['desc'] if sort_dirs is None else sort_dirs if show_level is None: show_level = ga.Showlevel.NONE db_api_artifacts = self.db_api.artifact_get_all(self.context, filters=filters, marker=marker, limit=limit, sort_keys=sort_keys, sort_dirs=sort_dirs, show_level=show_level) artifacts = [] for db_api_artifact in db_api_artifacts: artifact = serialization.deserialize_from_db( db_api_artifact, self.plugins) artifacts.append(artifact) return artifacts
def test_deserialize_from_db(self): ts = datetime.datetime.now() db_dict = { "type_name": 'SerTestType', "type_version": '1.0', "id": "123", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": { 'some_string': { 'type': 'string', 'value': 'bar' }, 'some_text': { 'type': 'text', 'value': 'bazz' }, 'some_version': { 'type': 'string', 'value': '11.22.33-beta' }, 'some_int': { 'type': 'int', 'value': 50 }, 'some_numeric': { 'type': 'numeric', 'value': 10.341 }, 'some_bool': { 'type': 'bool', 'value': True }, 'some_array': { 'type': 'array', 'value': [ { 'type': 'string', 'value': 'q' }, { 'type': 'string', 'value': 'w' }, { 'type': 'string', 'value': 'e' }, { 'type': 'string', 'value': 'r' }, { 'type': 'string', 'value': 't' }, { 'type': 'string', 'value': 'y' } ] }, 'another_array': { 'type': 'array', 'value': [ { 'type': 'int', 'value': 1 }, { 'type': 'numeric', 'value': 1.2 }, { 'type': 'bool', 'value': False } ] }, 'some_dict.foobar': { 'type': 'string', 'value': 'FOOBAR' }, 'some_dict.baz': { 'type': 'string', 'value': 'QUX' }, 'another_dict.foo': { 'type': 'int', 'value': 1 }, 'another_dict.bar': { 'type': 'bool', 'value': True } }, 'blobs': { 'some_blob': [ { 'size': 100, 'checksum': 'abc', 'item_key': 'some_key', 'locations': ['http://example.com/blob1'] }], 'some_blob_list': [ { 'size': 200, 'checksum': 'fff', 'item_key': 'another_key', 'locations': ['http://example.com/blob2'] }, { 'size': 300, 'checksum': '123', 'item_key': 'third_key', 'locations': ['http://example.com/blob3'] } ] }, 'dependencies': { 'some_ref': [ { "type_name": 'ArtifactType', "type_version": '1.0', "id": "1", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} } ], 'some_ref_list': [ { "type_name": 'ArtifactType', "type_version": '1.0', "id": "2", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} }, { "type_name": 'ArtifactType', "type_version": '1.0', "id": "3", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} } ] } } plugins_dict = {'SerTestType': [SerTestType], 'ArtifactType': [defs.ArtifactType]} def _retrieve_plugin(name, version): return next((p for p in plugins_dict.get(name, []) if version and p.version == version), plugins_dict.get(name, [None])[0]) plugins = mock.Mock() plugins.get_class_by_typename = _retrieve_plugin art = serialization.deserialize_from_db(db_dict, plugins) self.assertEqual('123', art.id) self.assertEqual('11.2', art.version) self.assertIsNone(art.description) self.assertEqual('Foo', art.name) self.assertEqual('private', art.visibility) self.assertEqual('private', art.visibility)
def test_deserialize_from_db(self): ts = datetime.datetime.now() db_dict = { "type_name": 'SerTestType', "type_version": '1.0', "id": "123", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": { 'some_string': { 'type': 'string', 'value': 'bar' }, 'some_text': { 'type': 'text', 'value': 'bazz' }, 'some_version': { 'type': 'string', 'value': '11.22.33-beta' }, 'some_int': { 'type': 'int', 'value': 50 }, 'some_numeric': { 'type': 'numeric', 'value': 10.341 }, 'some_bool': { 'type': 'bool', 'value': True }, 'some_array': { 'type': 'array', 'value': [{ 'type': 'string', 'value': 'q' }, { 'type': 'string', 'value': 'w' }, { 'type': 'string', 'value': 'e' }, { 'type': 'string', 'value': 'r' }, { 'type': 'string', 'value': 't' }, { 'type': 'string', 'value': 'y' }] }, 'another_array': { 'type': 'array', 'value': [{ 'type': 'int', 'value': 1 }, { 'type': 'numeric', 'value': 1.2 }, { 'type': 'bool', 'value': False }] }, 'some_dict.foobar': { 'type': 'string', 'value': 'FOOBAR' }, 'some_dict.baz': { 'type': 'string', 'value': 'QUX' }, 'another_dict.foo': { 'type': 'int', 'value': 1 }, 'another_dict.bar': { 'type': 'bool', 'value': True } }, 'blobs': { 'some_blob': [{ 'size': 100, 'checksum': 'abc', 'item_key': 'some_key', 'locations': ['http://example.com/blob1'] }], 'some_blob_list': [{ 'size': 200, 'checksum': 'fff', 'item_key': 'another_key', 'locations': ['http://example.com/blob2'] }, { 'size': 300, 'checksum': '123', 'item_key': 'third_key', 'locations': ['http://example.com/blob3'] }] }, 'dependencies': { 'some_ref': [{ "type_name": 'ArtifactType', "type_version": '1.0', "id": "1", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} }], 'some_ref_list': [{ "type_name": 'ArtifactType', "type_version": '1.0', "id": "2", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} }, { "type_name": 'ArtifactType', "type_version": '1.0', "id": "3", "version": "11.2", "description": None, "name": "Foo", "visibility": "private", "state": "creating", "owner": "my_tenant", "created_at": ts, "updated_at": ts, "deleted_at": None, "published_at": None, "tags": ["test", "fixture"], "properties": {}, "blobs": {}, "dependencies": {} }] } } plugins_dict = { 'SerTestType': [SerTestType], 'ArtifactType': [defs.ArtifactType] } def _retrieve_plugin(name, version): return next((p for p in plugins_dict.get(name, []) if version and p.version == version), plugins_dict.get(name, [None])[0]) plugins = mock.Mock() plugins.get_class_by_typename = _retrieve_plugin art = serialization.deserialize_from_db(db_dict, plugins) self.assertEqual('123', art.id) self.assertEqual('11.2', art.version) self.assertIsNone(art.description) self.assertEqual('Foo', art.name) self.assertEqual('private', art.visibility) self.assertEqual('private', art.visibility)