From deb487d8c0e6485200ba7d3cdf2b25b97a6b7ac1 Mon Sep 17 00:00:00 2001 From: zhurong Date: Thu, 7 Apr 2016 06:09:52 +0000 Subject: [PATCH] Generate separate db for murano service broker 1) Create separate config use the separate config.py to use: tox -egencfconfig 2) Create separate db for murano service broker to use: tox -e venv murano-cfapi-db-manage \ --config-file etc/murano/murano-cfapi.conf upgrade Change-Id: Ifd3551ace000e496d99725f46dbead62f7ef64b0 partial-implement: bp separate-service-broker-from-murano --- .gitignore | 2 + etc/oslo-config-generator/murano-cfapi.conf | 6 ++ murano/api/v1/cloudfoundry/cfapi.py | 17 +--- murano/cmd/cfapi.py | 2 +- murano/cmd/cfapi_db_manage.py | 80 +++++++++++++++++++ murano/common/cf_config.py | 73 +++++++++++++++++ .../cfapi_migration/alembic_migrations/README | 15 ++++ murano/opts.py | 14 ++++ setup.cfg | 2 + tox.ini | 7 +- 10 files changed, 200 insertions(+), 18 deletions(-) create mode 100644 etc/oslo-config-generator/murano-cfapi.conf create mode 100644 murano/cmd/cfapi_db_manage.py create mode 100644 murano/common/cf_config.py create mode 100644 murano/db/cfapi_migration/alembic_migrations/README diff --git a/.gitignore b/.gitignore index 4ccfb4541..58b0025f5 100644 --- a/.gitignore +++ b/.gitignore @@ -39,9 +39,11 @@ murano/tests/functional/engine/config.conf #Autogenerated sample config file etc/murano/murano.conf.sample +etc/murano/murano-cfapi.conf.sample #User Config file for Murano etc/murano/murano.conf +etc/murano/murano-cfapi.conf etc/murano/logging.conf # pylint autogenerated support files diff --git a/etc/oslo-config-generator/murano-cfapi.conf b/etc/oslo-config-generator/murano-cfapi.conf new file mode 100644 index 000000000..52a0775b4 --- /dev/null +++ b/etc/oslo-config-generator/murano-cfapi.conf @@ -0,0 +1,6 @@ +[DEFAULT] +output_file = etc/murano/murano-cfapi.conf.sample +namespace = keystone_authtoken +namespace = murano.cfapi +namespace = oslo.db +namespace = oslo.log diff --git a/murano/api/v1/cloudfoundry/cfapi.py b/murano/api/v1/cloudfoundry/cfapi.py index 2d3c2df5f..e1111d7bd 100644 --- a/murano/api/v1/cloudfoundry/cfapi.py +++ b/murano/api/v1/cloudfoundry/cfapi.py @@ -21,7 +21,7 @@ import retrying import six from webob import response -from murano.common.i18n import _, _LI, _LW +from murano.common.i18n import _LI, _LW from murano.common import auth_utils # noqa from murano.common import wsgi from murano.db.services import cf_connections as db_cf @@ -29,23 +29,8 @@ import muranoclient.client as muranoclient from muranoclient.glance import client as glare_client -cfapi_opts = [ - cfg.StrOpt('tenant', default='admin', - help=_('Project for service broker')), - cfg.StrOpt('bind_host', default='localhost', - help=_('Host for service broker')), - cfg.StrOpt('bind_port', default='8083', - help=_('Port for service broker')), - cfg.StrOpt('auth_url', default='localhost:5000', - help=_('Authentication URL')), - cfg.StrOpt('user_domain_name', default='default', - help=_('Domain name of the user')), - cfg.StrOpt('project_domain_name', default='default', - help=_('Domain name of the project'))] - LOG = logging.getLogger(__name__) CONF = cfg.CONF -CONF.register_opts(cfapi_opts, group='cfapi') class Controller(object): diff --git a/murano/cmd/cfapi.py b/murano/cmd/cfapi.py index 5870e60e0..b2752ff3a 100644 --- a/murano/cmd/cfapi.py +++ b/murano/cmd/cfapi.py @@ -35,7 +35,7 @@ from oslo_service import service from murano.api.v1 import request_statistics from murano.common import app_loader -from murano.common import config +from murano.common import cf_config as config from murano.common import policy from murano.common import server from murano.common import wsgi diff --git a/murano/cmd/cfapi_db_manage.py b/murano/cmd/cfapi_db_manage.py new file mode 100644 index 000000000..27f5e9f17 --- /dev/null +++ b/murano/cmd/cfapi_db_manage.py @@ -0,0 +1,80 @@ +# 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 oslo_config import cfg +from oslo_db import options + +from murano.db.cfapi_migration import migration + +CONF = cfg.CONF +options.set_defaults(CONF) + + +class ApiDBCommand(object): + + def upgrade(self, config): + migration.upgrade(CONF.command.revision, config=config) + + def downgrade(self, config): + migration.downgrade(CONF.command.revision, config=config) + + def revision(self, config): + migration.revision(CONF.command.message, + CONF.command.autogenerate, + config=config) + + def stamp(self, config): + migration.stamp(CONF.command.revision, config=config) + + def version(self, config): + print(migration.version()) + + +def add_command_parsers(subparsers): + command_object = ApiDBCommand() + + parser = subparsers.add_parser('upgrade') + parser.set_defaults(func=command_object.upgrade) + parser.add_argument('--revision', nargs='?') + + parser = subparsers.add_parser('downgrade') + parser.set_defaults(func=command_object.downgrade) + parser.add_argument('--revision', nargs='?') + + parser = subparsers.add_parser('stamp') + parser.add_argument('--revision', nargs='?') + parser.set_defaults(func=command_object.stamp) + + parser = subparsers.add_parser('revision') + parser.add_argument('-m', '--message') + parser.add_argument('--autogenerate', action='store_true') + parser.set_defaults(func=command_object.revision) + + parser = subparsers.add_parser('version') + parser.set_defaults(func=command_object.version) + + +command_opt = cfg.SubCommandOpt('command', + title='Command', + help='Available commands', + handler=add_command_parsers) + +CONF.register_cli_opt(command_opt) + + +def main(): + config = migration.get_alembic_config() + # attach the Murano conf to the Alembic conf + config.murano_config = CONF + + CONF(project='murano') + CONF.command.func(config) diff --git a/murano/common/cf_config.py b/murano/common/cf_config.py new file mode 100644 index 000000000..2b5615829 --- /dev/null +++ b/murano/common/cf_config.py @@ -0,0 +1,73 @@ +# Copyright 2011 OpenStack LLC. +# 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 oslo_config import cfg +from oslo_log import log as logging +from oslo_middleware import cors + +from murano.common.i18n import _ +from murano import version + + +cfapi_opts = [ + cfg.StrOpt('tenant', default='admin', + help=_('Project for service broker')), + cfg.StrOpt('bind_host', default='localhost', + help=_('Host for service broker')), + cfg.StrOpt('bind_port', default='8083', + help=_('Port for service broker')), + cfg.StrOpt('auth_url', default='localhost:5000', + help=_('Authentication URL')), + cfg.StrOpt('user_domain_name', default='default', + help=_('Domain name of the user')), + cfg.StrOpt('project_domain_name', default='default', + help=_('Domain name of the project'))] + +CONF = cfg.CONF +CONF.register_opts(cfapi_opts, group='cfapi') + + +def parse_args(args=None, usage=None, default_config_files=None): + logging.register_options(CONF) + CONF(args=args, + project='murano', + version=version.version_string, + usage=usage, + default_config_files=default_config_files) + + +def set_middleware_defaults(): + """Update default configuration options for oslo.middleware.""" + # CORS Defaults + # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ + cfg.set_defaults(cors.CORS_OPTS, + allow_headers=['X-Auth-Token', + 'X-Openstack-Request-Id', + 'X-Configuration-Session', + 'X-Roles', + 'X-User-Id', + 'X-Tenant-Id'], + expose_headers=['X-Auth-Token', + 'X-Openstack-Request-Id', + 'X-Configuration-Session', + 'X-Roles', + 'X-User-Id', + 'X-Tenant-Id'], + allow_methods=['GET', + 'PUT', + 'POST', + 'DELETE', + 'PATCH'] + ) diff --git a/murano/db/cfapi_migration/alembic_migrations/README b/murano/db/cfapi_migration/alembic_migrations/README new file mode 100644 index 000000000..f81a8c70e --- /dev/null +++ b/murano/db/cfapi_migration/alembic_migrations/README @@ -0,0 +1,15 @@ +Please see https://alembic.readthedocs.org/en/latest/index.html for general documentation + +To create alembic migrations use: +$ murano-cfapi-db-manage revision --message --autogenerate + +Stamp db with most recent migration version, without actually running migrations +$ murano-cfapi-db-manage stamp --revision head + +Upgrade can be performed by: +$ murano-cfapi-db-manage upgrade +$ murano-cfapi-db-manage upgrade --revision head + +Downgrading db: +$ murano-cfapi-db-manage downgrade +$ murano-cfapi-db-manage downgrade --revision base diff --git a/murano/opts.py b/murano/opts.py index f9e932b48..dacfc2e80 100644 --- a/murano/opts.py +++ b/murano/opts.py @@ -12,6 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +__all__ = [ + 'list_opts', + 'list_cfapi_opts', +] import copy import itertools @@ -19,6 +23,7 @@ import itertools import oslo_service.sslutils import murano.api.middleware.ssl +import murano.common.cf_config import murano.common.config import murano.common.wsgi @@ -48,6 +53,10 @@ _opt_lists = [ ])), ] +_cfapi_opt_lists = [ + ('cfapi', murano.common.cf_config.cfapi_opts), +] + _opt_lists.extend(oslo_service.sslutils.list_opts()) @@ -68,3 +77,8 @@ def list_opts(): :returns: a list of (group_name, opts) tuples """ return [(g, copy.deepcopy(o)) for g, o in _opt_lists] + + +def list_cfapi_opts(): + """Return a list of oslo_config options available in service broker.""" + return [(g, copy.deepcopy(o)) for g, o in _cfapi_opt_lists] diff --git a/setup.cfg b/setup.cfg index ab908f035..6cd7c4258 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,11 +46,13 @@ console_scripts = murano-engine = murano.cmd.engine:main murano-manage = murano.cmd.manage:main murano-db-manage = murano.cmd.db_manage:main + murano-cfapi-db-manage = murano.cmd.cfapi_db_manage:main murano-test-runner = murano.cmd.test_runner:main murano-cfapi = murano.cmd.cfapi:main oslo.config.opts = murano = murano.opts:list_opts keystone_authtoken = keystonemiddleware.opts:list_auth_token_opts + murano.cfapi = murano.opts:list_cfapi_opts oslo.config.opts.defaults = murano = murano.common.config:set_middleware_defaults tempest.test_plugins = diff --git a/tox.ini b/tox.ini index 9e6652289..f7dfa2f8e 100644 --- a/tox.ini +++ b/tox.ini @@ -66,7 +66,12 @@ setenv = VIRTUAL_ENV={envdir} commands = bash tools/lintstack.sh [testenv:genconfig] -commands = oslo-config-generator --config-file etc/oslo-config-generator/murano.conf +commands = + oslo-config-generator --config-file etc/oslo-config-generator/murano.conf + +[testenv:gencfconfig] +commands = + oslo-config-generator --config-file etc/oslo-config-generator/murano-cfapi.conf [testenv:releasenotes] commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html