diff --git a/glare/objects/base.py b/glare/objects/base.py index 32051e1..7f38d46 100644 --- a/glare/objects/base.py +++ b/glare/objects/base.py @@ -845,9 +845,13 @@ class BaseArtifact(base.VersionedObject): pass @classmethod - def get_default_store(cls, context, af, field_name, blob_key): + def get_default_store(cls, context=None, af=None, + field_name=None, blob_key=None): """Return a default store type for artifact type.""" - pass + for t in CONF.enabled_artifact_types: + type_name, __, store_name = t.partition(':') + if type_name == cls.get_type_name(): + return store_name def to_notification(self): """Return notification body that can be send to listeners. diff --git a/glare/objects/meta/registry.py b/glare/objects/meta/registry.py index d7a44a0..d378182 100644 --- a/glare/objects/meta/registry.py +++ b/glare/objects/meta/registry.py @@ -19,7 +19,7 @@ import pkgutil import sys from oslo_config import cfg -from oslo_config import types +from oslo_config import types as conf_types from oslo_log import log as logging from oslo_versionedobjects import base as vo_base import six @@ -36,11 +36,11 @@ registry_options = [ cfg.ListOpt('enabled_artifact_types', default=['heat_templates', 'heat_environments', 'murano_packages', 'tosca_templates', 'images'], - item_type=types.String(), + item_type=conf_types.String(), help=_("List of enabled artifact types that will be " "available to user")), cfg.ListOpt('custom_artifact_types_modules', default=[], - item_type=types.String(), + item_type=conf_types.String(), help=_("List of custom user modules with artifact types that " "will be uploaded by Glare dynamically during service " "startup.")) @@ -104,7 +104,8 @@ class ArtifactRegistry(vo_base.VersionedObjectRegistry): supported_types = [] for module in modules: supported_types.extend(get_subclasses(module, base.BaseArtifact)) - for type_name in set(CONF.enabled_artifact_types + ['all']): + types = [t.partition(':')[0] for t in CONF.enabled_artifact_types] + for type_name in set(types + ['all']): for af_type in supported_types: if type_name == af_type.get_type_name(): cls.register(af_type) diff --git a/glare/tests/unit/test_multistore.py b/glare/tests/unit/test_multistore.py new file mode 100644 index 0000000..9deda56 --- /dev/null +++ b/glare/tests/unit/test_multistore.py @@ -0,0 +1,36 @@ +# Copyright 2017 OpenStack Foundation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from glare.objects.meta import registry +from glare.tests.unit import base + + +class TestMultistore(base.BaseTestCase): + + def test_multistore(self): + types = {'images': 'swift', + 'heat_templates': 'rbd', 'heat_environments': '', + 'tosca_templates': 'sheepdog', + 'murano_packages': 'vmware_store'} + + self.config( + enabled_artifact_types=[":".join(_) for _ in types.items()]) + registry.ArtifactRegistry.register_all_artifacts() + + for t in registry.ArtifactRegistry.obj_classes().values(): + name = t[0].get_type_name() + if name == 'all': + continue + self.assertEqual(t[0].get_default_store(), types[name])