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
This commit is contained in:
parent
5b9f790b1d
commit
dee1f2c18a
@ -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.
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user