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
This commit is contained in:
Vladislav Kuzmin 2015-02-03 12:03:43 +04:00
parent 7e8af456c4
commit 54e2a86d22
5 changed files with 165 additions and 2 deletions

View File

@ -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

View File

@ -1,2 +1,113 @@
[DEFAULT]
sql_connection = mysql://refstack:<your password>@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 = <None>
# The SQLAlchemy connection string to use to connect to the slave
# database. (string value)
#slave_connection = <None>
# 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 = <None>
# 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 = <None>
# 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 = <None>
# 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

41
refstack/opts.py Normal file
View File

@ -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),
]

View File

@ -29,3 +29,7 @@ scripts =
[global]
setup-hooks =
pbr.hooks.setup_hook
[entry_points]
oslo.config.opts =
refstack = refstack.opts:list_opts

View File

@ -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}