From 54e2a86d220a822fc327b8a0bf611dd51a5d126a Mon Sep 17 00:00:00 2001 From: Vladislav Kuzmin Date: Tue, 3 Feb 2015 12:03:43 +0400 Subject: [PATCH] Add config auto generator Add possibility to generate a config file with default values. Run `tox -e genconfig` and etc/refstack.conf.sample appears. Change-Id: Ie7c7d90ec056ad254f4247d4b0adc06bdd096ee6 --- doc/refstack.md | 3 +- etc/refstack.conf.sample | 113 ++++++++++++++++++++++++++++++++++++++- refstack/opts.py | 41 ++++++++++++++ setup.cfg | 4 ++ tox.ini | 6 +++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 refstack/opts.py diff --git a/doc/refstack.md b/doc/refstack.md index 4e7b21af..f1de807d 100755 --- a/doc/refstack.md +++ b/doc/refstack.md @@ -54,7 +54,8 @@ Refstack Quickstart ####Configuration file preparation -- Make a copy of the sample config and update it with the correct information of your environment. Example of config file available in etc directory. +- Make a copy of the sample config and update it with the correct information of your environment. Example of config file with default values available in etc directory. +Note value of `connection` in `database` section should be corrected. ####Database sync diff --git a/etc/refstack.conf.sample b/etc/refstack.conf.sample index a375f5ec..70342478 100644 --- a/etc/refstack.conf.sample +++ b/etc/refstack.conf.sample @@ -1,2 +1,113 @@ [DEFAULT] -sql_connection = mysql://refstack:@127.0.0.1/refstack + +# +# From refstack +# + +# The backend to use for database. (string value) +#db_backend = sqlalchemy + + +[database] + +# +# From oslo.db +# + +# The file name to use with SQLite. (string value) +# Deprecated group/name - [DEFAULT]/sqlite_db +#sqlite_db = oslo.sqlite + +# If True, SQLite uses synchronous mode. (boolean value) +# Deprecated group/name - [DEFAULT]/sqlite_synchronous +#sqlite_synchronous = true + +# The back end to use for the database. (string value) +# Deprecated group/name - [DEFAULT]/db_backend +#backend = sqlalchemy + +# The SQLAlchemy connection string to use to connect to the database. +# (string value) +# Deprecated group/name - [DEFAULT]/sql_connection +# Deprecated group/name - [DATABASE]/sql_connection +# Deprecated group/name - [sql]/connection +#connection = + +# The SQLAlchemy connection string to use to connect to the slave +# database. (string value) +#slave_connection = + +# The SQL mode to be used for MySQL sessions. This option, including +# the default, overrides any server-set SQL mode. To use whatever SQL +# mode is set by the server configuration, set this to no value. +# Example: mysql_sql_mode= (string value) +#mysql_sql_mode = TRADITIONAL + +# Timeout before idle SQL connections are reaped. (integer value) +# Deprecated group/name - [DEFAULT]/sql_idle_timeout +# Deprecated group/name - [DATABASE]/sql_idle_timeout +# Deprecated group/name - [sql]/idle_timeout +#idle_timeout = 3600 + +# Minimum number of SQL connections to keep open in a pool. (integer +# value) +# Deprecated group/name - [DEFAULT]/sql_min_pool_size +# Deprecated group/name - [DATABASE]/sql_min_pool_size +#min_pool_size = 1 + +# Maximum number of SQL connections to keep open in a pool. (integer +# value) +# Deprecated group/name - [DEFAULT]/sql_max_pool_size +# Deprecated group/name - [DATABASE]/sql_max_pool_size +#max_pool_size = + +# Maximum number of database connection retries during startup. Set to +# -1 to specify an infinite retry count. (integer value) +# Deprecated group/name - [DEFAULT]/sql_max_retries +# Deprecated group/name - [DATABASE]/sql_max_retries +#max_retries = 10 + +# Interval between retries of opening a SQL connection. (integer +# value) +# Deprecated group/name - [DEFAULT]/sql_retry_interval +# Deprecated group/name - [DATABASE]/reconnect_interval +#retry_interval = 10 + +# If set, use this value for max_overflow with SQLAlchemy. (integer +# value) +# Deprecated group/name - [DEFAULT]/sql_max_overflow +# Deprecated group/name - [DATABASE]/sqlalchemy_max_overflow +#max_overflow = + +# Verbosity of SQL debugging information: 0=None, 100=Everything. +# (integer value) +# Deprecated group/name - [DEFAULT]/sql_connection_debug +#connection_debug = 0 + +# Add Python stack traces to SQL as comment strings. (boolean value) +# Deprecated group/name - [DEFAULT]/sql_connection_trace +#connection_trace = false + +# If set, use this value for pool_timeout with SQLAlchemy. (integer +# value) +# Deprecated group/name - [DATABASE]/sqlalchemy_pool_timeout +#pool_timeout = + +# Enable the experimental use of database reconnect on connection +# lost. (boolean value) +#use_db_reconnect = false + +# Seconds between database connection retries. (integer value) +#db_retry_interval = 1 + +# If True, increases the interval between database connection retries +# up to db_max_retry_interval. (boolean value) +#db_inc_retry_interval = true + +# If db_inc_retry_interval is set, the maximum seconds between +# database connection retries. (integer value) +#db_max_retry_interval = 10 + +# Maximum database connection retries before error is raised. Set to +# -1 to specify an infinite retry count. (integer value) +#db_max_retries = 20 diff --git a/refstack/opts.py b/refstack/opts.py new file mode 100644 index 00000000..6afa88d5 --- /dev/null +++ b/refstack/opts.py @@ -0,0 +1,41 @@ +# Copyright (c) 2015 Mirantis, Inc. +# 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. +""" + Function list_opts intended for oslo-config-generator. It tool used for + generate config file with help info and default values for options defined + anywhere in application. + All new options must be imported here and must be returned from + list_opts function as list that contain tuple. + Use itertools.chain if config section contain more than one imported module + with options. For example: + + ... + def list_opts(): + return [ + ('DEFAULT', refstack.db.api.db_opts), + ('api', + itertools.chain(refstack.api.first.module.opts, + refstack.api.second.modulei.opts,)), + ] + ... +""" +import refstack.db.api + + +def list_opts(): + return [ + # Keep a list in alphabetical order + ('DEFAULT', refstack.db.api.db_opts), + ] diff --git a/setup.cfg b/setup.cfg index 2f6f762e..235f2962 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,3 +29,7 @@ scripts = [global] setup-hooks = pbr.hooks.setup_hook + +[entry_points] +oslo.config.opts = + refstack = refstack.opts:list_opts diff --git a/tox.ini b/tox.ini index f534bb59..a0edcf9b 100644 --- a/tox.ini +++ b/tox.ini @@ -36,6 +36,12 @@ commands = flake8 --filename=refstack* bin distribute = false +[testenv:genconfig] +commands = + oslo-config-generator --output-file etc/refstack.conf.sample \ + --namespace refstack \ + --namespace oslo.db + [testenv:venv] commands = {posargs}