From dba51806f209adcee01c578bf1aded496886ebe9 Mon Sep 17 00:00:00 2001 From: Jeremy Liu Date: Fri, 2 Jun 2017 17:13:30 +0800 Subject: [PATCH] Generate the karbor.conf.sample with oslo-config-generator It's hard to maintain karbor.conf by hand, let's switch to use oslo-config-generator and follow OpenStack convention. Change-Id: I0dd0a63267e14321ff723d32bd6d90db07cc5f95 --- .gitignore | 1 + devstack/plugin.sh | 5 + etc/karbor.conf | 31 ------ etc/oslo-config-generator/karbor.conf | 9 ++ karbor/common/opts.py | 101 ++++++++++++++++++ ...slo-config-generator-f2a9be9e71d90b1f.yaml | 4 + setup.cfg | 2 + tox.ini | 7 +- 8 files changed, 128 insertions(+), 32 deletions(-) delete mode 100644 etc/karbor.conf create mode 100644 etc/oslo-config-generator/karbor.conf create mode 100644 karbor/common/opts.py create mode 100644 releasenotes/notes/use-oslo-config-generator-f2a9be9e71d90b1f.yaml diff --git a/.gitignore b/.gitignore index e0225607..a37b10b1 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ ChangeLog .*sw? releasenotes/build +etc/karbor.conf.sample diff --git a/devstack/plugin.sh b/devstack/plugin.sh index e3743342..769641ce 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -114,6 +114,11 @@ function configure_karbor_api { if is_service_enabled karbor-api ; then echo "Configuring Karbor API" + # generate configuration file + cd $KARBOR_DIR + tox -e genconfig + cp etc/karbor.conf.sample etc/karbor.conf + cp $KARBOR_DIR/etc/karbor.conf $KARBOR_API_CONF cp $KARBOR_DIR/etc/api-paste.ini $KARBOR_CONF_DIR cp $KARBOR_DIR/etc/policy.json $KARBOR_CONF_DIR diff --git a/etc/karbor.conf b/etc/karbor.conf deleted file mode 100644 index 3a7dae43..00000000 --- a/etc/karbor.conf +++ /dev/null @@ -1,31 +0,0 @@ -[keystone_authtoken] -#signing_dir = /var/cache/karbor -#cafile = /opt/stack/data/ca-bundle.pem -#auth_uri = http://192.168.1.102:5000 -#project_domain_id = default -#project_name = service -#user_domain_id = default -#password = nomoresecrete -#username = karbor -#auth_url = http://192.168.1.102:35357 -#auth_plugin = password - -[DEFAULT] -#api_paste_config = /etc/karbor/api-paste.ini -#logging_context_format_string = %(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [%(request_id)s %(user_id)s %(project_id)s%(color)s] %(instance)s%(color)s%(message)s -#logging_debug_format_suffix = from (pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d -#logging_default_format_string = %(asctime)s.%(msecs)03d %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s -#logging_exception_prefix = %(color)s%(asctime)s.%(msecs)03d TRACE %(name)s %(instance)s -#verbose = True -#debug = True -#auth_strategy = noauth -#log_dir = /var/log/ -#rpc_backend = rabbit - -#[database] -#connection = mysql+pymysql://root:stackdb@127.0.0.1/karbor?charset=utf8 - -#[oslo_messaging_rabbit] -#rabbit_userid = stackrabbit -#rabbit_password = stackqueue -#rabbit_hosts = 10.229.50.225 diff --git a/etc/oslo-config-generator/karbor.conf b/etc/oslo-config-generator/karbor.conf new file mode 100644 index 00000000..c71fc859 --- /dev/null +++ b/etc/oslo-config-generator/karbor.conf @@ -0,0 +1,9 @@ +[DEFAULT] +output_file = etc/karbor.conf.sample +namespace = karbor.common.opts +namespace = keystonemiddleware.auth_token +namespace = oslo.messaging +namespace = oslo.concurrency +namespace = oslo.db +namespace = oslo.log +namespace = oslo.policy diff --git a/karbor/common/opts.py b/karbor/common/opts.py new file mode 100644 index 00000000..dccca013 --- /dev/null +++ b/karbor/common/opts.py @@ -0,0 +1,101 @@ +# 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. + +import copy +import itertools + +import karbor.api.common +import karbor.api.v1.protectables +import karbor.api.v1.providers +import karbor.common.config +import karbor.db.api +import karbor.exception +import karbor.service +import karbor.services.operationengine.engine.executors.green_thread_executor as green_thread_executor # noqa +import karbor.services.operationengine.engine.executors.thread_pool_executor as thread_pool_executor # noqa +import karbor.services.operationengine.engine.triggers.timetrigger.time_trigger as time_trigger # noqa +import karbor.services.operationengine.karbor_client +import karbor.services.operationengine.manager +import karbor.services.operationengine.operations.base as base +import karbor.services.protection.clients.cinder +import karbor.services.protection.clients.glance +import karbor.services.protection.clients.heat +import karbor.services.protection.clients.manila +import karbor.services.protection.clients.neutron +import karbor.services.protection.clients.nova +import karbor.services.protection.flows.restore +import karbor.services.protection.flows.worker +import karbor.services.protection.manager +import karbor.services.protection.protection_plugins.image.image_protection_plugin as image_protection_plugin # noqa +import karbor.services.protection.protection_plugins.share.share_snapshot_plugin as share_snapshot_plugin # noqa +import karbor.services.protection.protection_plugins.volume.cinder_protection_plugin as cinder_protection_plugin # noqa +import karbor.services.protection.protection_plugins.volume.volume_snapshot_plugin as volume_snapshot_plugin # noqa +import karbor.wsgi.eventlet_server + +__all__ = ['list_opts'] + +_opts = [ + ('clients_keystone', list(itertools.chain( + karbor.common.config.keystone_client_opts))), + ('operationengine', list(itertools.chain( + green_thread_executor.green_thread_executor_opts, + karbor.services.operationengine.manager.trigger_manager_opts))), + ('karbor_client', list(itertools.chain( + karbor.common.config.service_client_opts))), + ('cinder_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.cinder.cinder_client_opts))), + ('glance_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.glance.glance_client_opts))), + ('heat_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.heat.heat_client_opts))), + ('manila_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.manila.manila_client_opts))), + ('neutron_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.neutron.neutron_client_opts))), + ('nova_client', list(itertools.chain( + karbor.common.config.service_client_opts, + karbor.services.protection.clients.nova.nova_client_opts))), + ('image_backup_plugin', list(itertools.chain( + image_protection_plugin.image_backup_opts))), + ('cinder_backup_protection_plugin', list(itertools.chain( + cinder_protection_plugin.cinder_backup_opts))), + ('volume_snapshot_plugin', list(itertools.chain( + volume_snapshot_plugin.volume_snapshot_opts))), + ('manila_snapshot_plugin', list(itertools.chain( + share_snapshot_plugin.manila_snapshot_opts))), + (None, list(itertools.chain( + karbor.common.config.core_opts, + karbor.common.config.debug_opts, + karbor.common.config.global_opts, + karbor.api.common.api_common_opts, + karbor.api.v1.protectables.query_instance_filters_opts, + karbor.api.v1.providers.query_provider_filters_opts, + karbor.api.v1.providers.query_checkpoint_filters_opts, + karbor.db.api.db_opts, + thread_pool_executor.executor_opts, + time_trigger.time_trigger_opts, + base.record_operation_log_executor_opts, + karbor.services.protection.flows.restore.sync_status_opts, + karbor.services.protection.flows.worker.workflow_opts, + karbor.services.protection.manager.protection_manager_opts, + karbor.wsgi.eventlet_server.socket_opts, + karbor.exception.exc_log_opts, + karbor.service.service_opts)))] + + +def list_opts(): + return [(g, copy.deepcopy(o)) for g, o in _opts] diff --git a/releasenotes/notes/use-oslo-config-generator-f2a9be9e71d90b1f.yaml b/releasenotes/notes/use-oslo-config-generator-f2a9be9e71d90b1f.yaml new file mode 100644 index 00000000..320e95fe --- /dev/null +++ b/releasenotes/notes/use-oslo-config-generator-f2a9be9e71d90b1f.yaml @@ -0,0 +1,4 @@ +--- +other: + - oslo-config-generator is now used to generate a + karbor.conf.sample file diff --git a/setup.cfg b/setup.cfg index 1885f772..220a7972 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,6 +35,8 @@ console_scripts = karbor-manage = karbor.cmd.manage:main karbor-operationengine = karbor.cmd.operationengine:main karbor-protection = karbor.cmd.protection:main +oslo.config.opts = + karbor.common.opts = karbor.common.opts:list_opts wsgi_scripts = karbor-wsgi = karbor.wsgi.wsgi:initialize_application karbor.database.migration_backend = diff --git a/tox.ini b/tox.ini index 2dc6c512..f73ae4b8 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,9 @@ commands = python setup.py test --slowest --testr-args='{posargs}' basepython = python2.7 setenv = OS_TEST_PATH=./karbor/tests/fullstack OS_TEST_TIMEOUT=3600 -commands = python setup.py test --slowest --testr-args="--concurrency=2 {posargs}" +commands = + oslo-config-generator --config-file etc/oslo-config-generator/karbor.conf --output-file etc/karbor.conf + python setup.py test --slowest --testr-args="--concurrency=2 {posargs}" [testenv:pep8] commands = flake8 @@ -53,6 +55,9 @@ commands = sphinx-build -a -E -d releasenotes/build/doctrees -b html releasenote [testenv:install-guide] commands = sphinx-build -a -E -W -d install-guide/build/doctrees -b html install-guide/source install-guide/build/html +[testenv:genconfig] +commands = oslo-config-generator --config-file etc/oslo-config-generator/karbor.conf + [flake8] show-source = True ignore =