diff --git a/.gitignore b/.gitignore index 7fd1200..c9a3436 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ build .coverage* !.coveragerc cover/ - +etc/*.conf diff --git a/config-generator/sql2subunit.conf b/config-generator/sql2subunit.conf new file mode 100644 index 0000000..8926482 --- /dev/null +++ b/config-generator/sql2subunit.conf @@ -0,0 +1,4 @@ +[DEFAULT] +output_file = etc/sql2subunit.conf.sample +namespace = oslo.db +namespace = subunit2sql.write_subunit diff --git a/config-generator/subunit2sql-db-manage.conf b/config-generator/subunit2sql-db-manage.conf new file mode 100644 index 0000000..5629182 --- /dev/null +++ b/config-generator/subunit2sql-db-manage.conf @@ -0,0 +1,3 @@ +[DEFAULT] +output_file = etc/subunit2sql-db-manage.conf.sample +namespace = oslo.db diff --git a/config-generator/subunit2sql.conf b/config-generator/subunit2sql.conf new file mode 100644 index 0000000..9777144 --- /dev/null +++ b/config-generator/subunit2sql.conf @@ -0,0 +1,4 @@ +[DEFAULT] +output_file = etc/subunit2sql.conf.sample +namespace = oslo.db +namespace = subunit2sql.shell diff --git a/etc/sql2subunit.conf.sample b/etc/sql2subunit.conf.sample new file mode 100644 index 0000000..de02513 --- /dev/null +++ b/etc/sql2subunit.conf.sample @@ -0,0 +1,117 @@ +[DEFAULT] + +# +# From subunit2sql.write_subunit +# + +# Path to write the subunit stream output, if none is specified STDOUT +# will be used (string value) +#out_path = + +# Run id to use for creating a subunit stream (string value) +#run_id = + + +[database] + +# +# From oslo.db +# + +# 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 = + +# 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 True, increases the interval between database connection retries +# up to db_max_retry_interval. (boolean value) +#db_inc_retry_interval = true + +# Maximum database connection retries before error is raised. Set to +# -1 to specify an infinite retry count. (integer value) +#db_max_retries = 20 + +# If db_inc_retry_interval is set, the maximum seconds between +# database connection retries. (integer value) +#db_max_retry_interval = 10 + +# Seconds between database connection retries. (integer value) +#db_retry_interval = 1 + +# 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 + +# 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 = + +# 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 db 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 + +# 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 + +# 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 + +# If set, use this value for pool_timeout with SQLAlchemy. (integer +# value) +# Deprecated group/name - [DATABASE]/sqlalchemy_pool_timeout +#pool_timeout = + +# 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 + +# The SQLAlchemy connection string to use to connect to the slave +# database. (string value) +#slave_connection = + +# 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 + +# Enable the experimental use of database reconnect on connection +# lost. (boolean value) +#use_db_reconnect = false diff --git a/etc/subunit2sql-db-manage.conf.sample b/etc/subunit2sql-db-manage.conf.sample new file mode 100644 index 0000000..a0c8555 --- /dev/null +++ b/etc/subunit2sql-db-manage.conf.sample @@ -0,0 +1,106 @@ +[DEFAULT] + + +[database] + +# +# From oslo.db +# + +# 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 = + +# 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 True, increases the interval between database connection retries +# up to db_max_retry_interval. (boolean value) +#db_inc_retry_interval = true + +# Maximum database connection retries before error is raised. Set to +# -1 to specify an infinite retry count. (integer value) +#db_max_retries = 20 + +# If db_inc_retry_interval is set, the maximum seconds between +# database connection retries. (integer value) +#db_max_retry_interval = 10 + +# Seconds between database connection retries. (integer value) +#db_retry_interval = 1 + +# 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 + +# 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 = + +# 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 db 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 + +# 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 + +# 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 + +# If set, use this value for pool_timeout with SQLAlchemy. (integer +# value) +# Deprecated group/name - [DATABASE]/sqlalchemy_pool_timeout +#pool_timeout = + +# 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 + +# The SQLAlchemy connection string to use to connect to the slave +# database. (string value) +#slave_connection = + +# 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 + +# Enable the experimental use of database reconnect on connection +# lost. (boolean value) +#use_db_reconnect = false diff --git a/etc/subunit2sql.conf.sample b/etc/subunit2sql.conf.sample new file mode 100644 index 0000000..d912fdf --- /dev/null +++ b/etc/subunit2sql.conf.sample @@ -0,0 +1,119 @@ +[DEFAULT] + +# +# From subunit2sql.shell +# + +# Location of run artifacts (string value) +#artifacts = + +# Dict of metadata about the run(s) (dict value) +#run_meta = + +# list of subunit files to put into the database (multi valued) +#subunit_files = + + +[database] + +# +# From oslo.db +# + +# 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 = + +# 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 True, increases the interval between database connection retries +# up to db_max_retry_interval. (boolean value) +#db_inc_retry_interval = true + +# Maximum database connection retries before error is raised. Set to +# -1 to specify an infinite retry count. (integer value) +#db_max_retries = 20 + +# If db_inc_retry_interval is set, the maximum seconds between +# database connection retries. (integer value) +#db_max_retry_interval = 10 + +# Seconds between database connection retries. (integer value) +#db_retry_interval = 1 + +# 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 + +# 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 = + +# 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 db 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 + +# 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 + +# 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 + +# If set, use this value for pool_timeout with SQLAlchemy. (integer +# value) +# Deprecated group/name - [DATABASE]/sqlalchemy_pool_timeout +#pool_timeout = + +# 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 + +# The SQLAlchemy connection string to use to connect to the slave +# database. (string value) +#slave_connection = + +# 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 + +# Enable the experimental use of database reconnect on connection +# lost. (boolean value) +#use_db_reconnect = false diff --git a/setup.cfg b/setup.cfg index 6266c61..a968c7a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,9 @@ console_scripts = subunit2sql = subunit2sql.shell:main sql2subunit = subunit2sql.write_subunit:main subunit2sql-db-manage = subunit2sql.migrations.cli:main +oslo.config.opts = + subunit2sql.shell = subunit2sql.shell:list_opts + subunit2sql.write_subunit = subunit2sql.write_subunit:list_opts [build_sphinx] source-dir = doc/source diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 512a2ea..676524f 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy import sys from oslo.config import cfg @@ -24,22 +25,30 @@ from subunit2sql import read_subunit as subunit CONF = cfg.CONF +SHELL_OPTS = shell_opts = [ + cfg.MultiStrOpt('subunit_files', positional=True, + help='list of subunit files to put into the database'), + cfg.DictOpt('run_meta', short='r', default=None, + help='Dict of metadata about the run(s)'), + cfg.StrOpt('artifacts', short='a', default=None, + help='Location of run artifacts') +] + def cli_opts(): - shell_opts = [ - cfg.StrOpt('state_path', default='$pybasedir', - help='Top level dir for maintaining subunit2sql state'), - cfg.MultiStrOpt('subunit_files', positional=True), - cfg.DictOpt('run_meta', short='r', default=None, - help='Dict of metadata about the run(s)'), - cfg.StrOpt('artifacts', short='a', default=None, - help='Location of run artifacts') - ] - - for opt in shell_opts: + for opt in SHELL_OPTS: CONF.register_cli_opt(opt) +def list_opts(): + """Return a list of oslo.config options available. + + The purpose of this is to allow tools like the Oslo sample config file + generator to discover the options exposed to users. + """ + return [('DEFAULT', copy.deepcopy(SHELL_OPTS))] + + def parse_args(argv, default_config_files=None): cfg.CONF.register_cli_opts(options.database_opts, group='database') cfg.CONF(argv[1:], project='subunit2sql', diff --git a/subunit2sql/write_subunit.py b/subunit2sql/write_subunit.py index 380d832..9dc98b4 100644 --- a/subunit2sql/write_subunit.py +++ b/subunit2sql/write_subunit.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import copy import functools import sys @@ -33,16 +34,17 @@ STATUS_CODES = frozenset([ CONF = cfg.CONF +SHELL_OPTS = [ + cfg.StrOpt('run_id', required=True, positional=True, + help='Run id to use for creating a subunit stream'), + cfg.StrOpt('out_path', short='o', default=None, + help='Path to write the subunit stream output, if none ' + 'is specified STDOUT will be used') +] + def cli_opts(): - shell_opts = [ - cfg.StrOpt('run_id', required=True, positional=True, - help='Run id to use for creating a subunit stream'), - cfg.StrOpt('out_path', short='o', default=None, - help='Path to write the subunit stream output, if none ' - 'is specified STDOUT will be used') - ] - for opt in shell_opts: + for opt in SHELL_OPTS: cfg.CONF.register_cli_opt(opt) @@ -84,6 +86,11 @@ def sql2subunit(run_id, output=sys.stdout): session.close() +def list_opts(): + opt_list = copy.deepcopy(SHELL_OPTS) + return [('DEFAULT', opt_list)] + + def main(): cli_opts() shell.parse_args(sys.argv) diff --git a/tox.ini b/tox.ini index 88f7e78..4c03645 100644 --- a/tox.ini +++ b/tox.ini @@ -37,3 +37,10 @@ commands = python setup.py build_sphinx # H305 skipped because it is inconsistent between python versions ignore = E125,H402,E123,E129,H305 exclude = .venv,.git,.tox,dist,doc,*egg,build + +[testenv:generate_samples] +commands = + oslo-config-generator --config-file config-generator/subunit2sql.conf + oslo-config-generator --config-file config-generator/sql2subunit.conf + oslo-config-generator --config-file config-generator/subunit2sql-db-manage.conf +