Allow to set default store for artifact type in config
Now there is a config parameter 'enabled_artifact_types = type1,type2,type3'. It defines a list of available artifact types for Glare. This code extends the syntax to 'enabled_artifact_types = type1[:store1],type2[:store2],type3[:store3]', where optional parameter 'store' is a name of one of the enabled glance_store drivers (swift, rbd, file, etc.) Change-Id: Iffadd37cb474e9a54e0b4c98af24112a905668f8
This commit is contained in:
parent
2280b332a4
commit
d03295bd69
@ -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.
|
||||
|
@ -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)
|
||||
|
36
glare/tests/unit/test_multistore.py
Normal file
36
glare/tests/unit/test_multistore.py
Normal file
@ -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])
|
Loading…
Reference in New Issue
Block a user