From 8eae8053a41b32cdb27cbfb034fdb0e4f77108e8 Mon Sep 17 00:00:00 2001 From: Nicholas Jones Date: Thu, 2 Nov 2017 10:36:56 -0500 Subject: [PATCH] Add oslo_config and oslo_log to Ranger Adds basic functionality for oslo_config and oslo_log to Ranger uuidgen Change-Id: I041e4e2013fec83d3ff0b5befc581a455cb04ffe --- etc/orm.conf | 31 ---------- orm/_i18n.py | 24 ++++++++ orm/cmd/uuidgen.py | 7 +++ orm/common/config.py | 69 +++++++++++++++++++++++ orm/services/id_generator/config.py | 53 +++-------------- orm/services/id_generator/uuidgen/app.py | 9 +-- requirements.txt | 3 +- setup.cfg | 6 +- tools/config/ranger-config-generator.conf | 4 ++ tox.ini | 3 + 10 files changed, 125 insertions(+), 84 deletions(-) delete mode 100644 etc/orm.conf create mode 100644 orm/_i18n.py create mode 100644 orm/common/config.py create mode 100644 tools/config/ranger-config-generator.conf diff --git a/etc/orm.conf b/etc/orm.conf deleted file mode 100644 index a310146f..00000000 --- a/etc/orm.conf +++ /dev/null @@ -1,31 +0,0 @@ -[DEFAULT] -api_workers = 1 -debug = True -verbose = True -pecan_debug = True -region = local -#Log files location -log_dir = /var/log/ranger -local_repo = ranger_repo -cms_log_file: /var/log/orm/cms_rest.log -fms_log_file: /var/log/orm/fms_rest.log -ims_log_file: /var/log/orm/ims.log -rds_log_file: /var/log/orm/rds.log -uuidgen_log_file: /var/log/orm/uuidgen.log -audit_log_file: /var/log/orm/audit_server.log -rms_log_file: /var/log/orm/rms.log -orm_base_url: https://127.0.0.1 -cms_listen_port: 7080 -rms_listen_port: 8080 -rds_http_listen_port: 8777 -rds_listen_port: 8778 -fms_listen_port: 8082 -ims_listen_port: 8084 -uuidgen_listen_port: 8090 -audit_server_listen_port: 8776 - -[api] -# Address to bind the API server to -host = 0.0.0.0 -# Port the bind the API server to -port = 9010 diff --git a/orm/_i18n.py b/orm/_i18n.py new file mode 100644 index 00000000..b71f7df3 --- /dev/null +++ b/orm/_i18n.py @@ -0,0 +1,24 @@ +# 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. + +"""oslo.i18n integration module. +See https://docs.openstack.org/oslo.i18n/latest/user/usage.html +""" + +import oslo_i18n + +DOMAIN = 'ranger' + +_translators = oslo_i18n.TranslatorFactory(domain=DOMAIN) + +# The primary translation function using the well-known name "_" +_ = _translators.primary diff --git a/orm/cmd/uuidgen.py b/orm/cmd/uuidgen.py index dbf8844f..99fa99f9 100644 --- a/orm/cmd/uuidgen.py +++ b/orm/cmd/uuidgen.py @@ -12,8 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_config import cfg + +from orm.common import config from orm.services.id_generator.uuidgen import app +CONF = cfg.CONF + + def main(): + config.parse_args() app.main() diff --git a/orm/common/config.py b/orm/common/config.py new file mode 100644 index 00000000..1eaa8f44 --- /dev/null +++ b/orm/common/config.py @@ -0,0 +1,69 @@ +# 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. + +""" +Configuration options registration. +""" + +from oslo_config import cfg +from oslo_log import log as logging + +CONF = cfg.CONF + +api_opts = [ + cfg.HostAddressOpt( + 'host', + default='0.0.0.0', + help='Ranger API server host' + ), + cfg.BoolOpt('ssl_verify', default=False, help='Enable HTTPS') +] + +uuid_opts = [ + cfg.PortOpt('port', default=7001, help='uuid server port'), + +] + +db_opts = [ + cfg.StrOpt('connection', default='', + help='Ranger database connection string') +] + +API_GROUP = 'api' +UUID_GROUP = 'uuid' +DB_GROUP = 'database' + + +CONF.register_opts(api_opts, group=API_GROUP) +CONF.register_opts(uuid_opts, group=UUID_GROUP) +CONF.register_opts(db_opts, group=DB_GROUP) + +logging.register_options(CONF) + + +def list_opts(): + return [ + (API_GROUP, api_opts), + (UUID_GROUP, uuid_opts), + (DB_GROUP, db_opts) + ] + + +def parse_args(args=None): + + logging.setup(CONF, 'ranger') + + CONF( + args=args, + project='ranger', + default_config_files=[] + ) diff --git a/orm/services/id_generator/config.py b/orm/services/id_generator/config.py index 49a00942..e7f01983 100755 --- a/orm/services/id_generator/config.py +++ b/orm/services/id_generator/config.py @@ -1,8 +1,12 @@ -import orm.base_config as config +from oslo_config import cfg + + +CONF = cfg.CONF + # Server Specific Configurations server = { - 'port': config.uuid['port'], - 'host': config.orm_host + 'port': CONF.uuid.port, + 'host': CONF.api.host } # Pecan Application Configurations app = { @@ -11,49 +15,10 @@ app = { 'debug': True, } -logging = { - 'root': {'level': 'INFO', 'handlers': ['console']}, - 'loggers': { - 'uuidgen': {'level': 'DEBUG', 'handlers': ['console', 'Logfile'], - 'propagate': False}, - 'pecan': {'level': 'DEBUG', 'handlers': ['console'], - 'propagate': False}, - 'py.warnings': {'handlers': ['console']}, - '__force_dict__': True - }, - 'handlers': { - 'console': { - 'level': 'DEBUG', - 'class': 'logging.StreamHandler', - 'formatter': 'color' - }, - 'Logfile': { - 'level': 'DEBUG', - 'class': 'logging.handlers.RotatingFileHandler', - 'maxBytes': 50000000, - 'backupCount': 10, - 'filename': config.uuid['log'], - 'formatter': 'simple' - } - }, - 'formatters': { - 'simple': { - 'format': ('%(asctime)s %(levelname)-5.5s [%(name)s]' - '[%(threadName)s] %(message)s') - }, - 'color': { - '()': 'pecan.log.ColorFormatter', - 'format': ('%(asctime)s [%(padded_color_levelname)s] [%(name)s]' - '[%(threadName)s] %(message)s'), - '__force_dict__': True - } - } -} - -verify = config.ssl_verify +verify = CONF.api.ssl_verify database = { - 'connection_string': config.db_url + 'orm' + 'connection_string': CONF.database.connection + '/orm' } # Custom Configurations must be in Python dictionary format:: # diff --git a/orm/services/id_generator/uuidgen/app.py b/orm/services/id_generator/uuidgen/app.py index 08ac188c..2bde154d 100755 --- a/orm/services/id_generator/uuidgen/app.py +++ b/orm/services/id_generator/uuidgen/app.py @@ -1,19 +1,20 @@ -import logging import os +from oslo_log import log as logging + from pecan.commands import CommandRunner from pecan import make_app -logger = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) def setup_app(config): app_conf = dict(config.app) - app = make_app(app_conf.pop('root'), logging=getattr(config, 'logging', {}), **app_conf) - logger.info('Starting uuidgen...') + LOG.info('Starting uuidgen...') + return app diff --git a/requirements.txt b/requirements.txt index f3925f41..9a8f2783 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,5 +12,6 @@ MySQL-python==1.2.5 requests==2.6.0 oslo.db==1.7.2 oslo.serialization -oslo.config +oslo.config>=4.6.0 # Apache-2.0 oslo.policy +oslo.log>=3.30.0 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 7213a6a0..d9edf87c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,10 +24,6 @@ setup-hooks = [files] packages = orm -data_files = - /etc/orm = - etc/orm.conf - [entry_points] console_scripts= @@ -38,6 +34,8 @@ console_scripts= orm-ims = orm.cmd.ims:main orm-audit = orm.cmd.audit:main orm-uuidgen = orm.cmd.uuidgen:main +oslo.config.opts = + ranger = orm.common.config:list_opts [build_sphinx] source-dir = doc/source diff --git a/tools/config/ranger-config-generator.conf b/tools/config/ranger-config-generator.conf new file mode 100644 index 00000000..b62ac49f --- /dev/null +++ b/tools/config/ranger-config-generator.conf @@ -0,0 +1,4 @@ +[DEFAULT] +output_file=etc/ranger.conf +wrap_width=79 +namespace=ranger diff --git a/tox.ini b/tox.ini index d062feb3..a03f55d3 100644 --- a/tox.ini +++ b/tox.ini @@ -39,6 +39,9 @@ commands = [testenv:debug] commands = oslo_debug_helper {posargs} +[testenv:genconfig] +commands = oslo-config-generator --config-file=tools/config/ranger-config-generator.conf + [flake8] show-source = True ignore = H301,F821,H202,H101,H104,H238,H401,H405,E501,F811,F403,H233,F841