From dee1f2c18ab62b7cb66e0ba275de0f5a2ed80b66 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 30 Nov 2015 11:03:47 -0500 Subject: [PATCH] Add support to subunit2sql cli to specify a run_at time This commit adds support to the subunit2sql cli command to specify the run_at field for a run being created. The db api has had support for this for quite some time but it was never exposed through the CLI. This resulted in the default behavior of using utcnow() to set the run_at column for a created run. However, if you're trying to insert old runs into the DB this isn't ideal because it will look like the test results were recent. This commit enables users to specify a different run_at time for these use cases. Change-Id: I0c00ef71633e043c9d80adf0bc2df0157d1a11b3 --- .../subunit2sql_run_at_cli_opt-ab65e3b69b29e0b0.yaml | 6 ++++++ requirements.txt | 1 + subunit2sql/shell.py | 11 ++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/subunit2sql_run_at_cli_opt-ab65e3b69b29e0b0.yaml 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: