diff --git a/releasenotes/notes/subunit2sql_run_at_cli_opt-ab65e3b69b29e0b0.yaml b/releasenotes/notes/subunit2sql_run_at_cli_opt-ab65e3b69b29e0b0.yaml new file mode 100644 index 0000000..843b5e9 --- /dev/null +++ b/releasenotes/notes/subunit2sql_run_at_cli_opt-ab65e3b69b29e0b0.yaml @@ -0,0 +1,6 @@ +--- +features: + - A new CLI option, "run_at" is available on the subunit2sql CLI. This + enables setting a specific date and time to use for the run_at column + of the run being created. If one is not specified the previous default + behavior of using the current time is still used. diff --git a/requirements.txt b/requirements.txt index 6416d59..c79b0ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ python-subunit>=0.0.18 six>=1.5.2 SQLAlchemy>=0.8.2 stevedore>=1.3.0 +python-dateutil>=2.4.2 diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 149feb3..29587b6 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -16,6 +16,7 @@ import copy import sys +from dateutil import parser as date_parser from oslo_config import cfg from oslo_db import options from pbr import version @@ -47,6 +48,10 @@ SHELL_OPTS = [ help='An optional prefix to identify global test attrs ' 'and treat it as test metadata instead of test_run ' 'metadata'), + cfg.StrOpt('run_at', default=None, + help="The optional datetime string for the run was started, " + "If one isn't provided the date and time of when " + "subunit2sql is called will be used") ] _version_ = version.VersionInfo('subunit2sql').version_string() @@ -128,9 +133,13 @@ def process_results(results): session = api.get_session() run_time = results.pop('run_time') totals = get_run_totals(results) + if CONF.run_at: + run_at = date_parser.parse(CONF.run_at) + else: + run_at = None db_run = api.create_run(totals['skips'], totals['fails'], totals['success'], run_time, CONF.artifacts, - id=CONF.run_id, session=session) + id=CONF.run_id, run_at=run_at, session=session) if CONF.run_meta: api.add_run_metadata(CONF.run_meta, db_run.id, session) for test in results: