Add cli option to subunit2sql to specify run_id
This commit adds a new cli option to subunit2sql to specify the id to use for the run being added. This can be used in with a ci system, like zuul, which already has a unique id to correlate the 2 data sets. This should be more efficient than storing the external uuid in the metadata table which was the suggested path prior to this commit. Change-Id: I5a3e03f1cbf64f4e3ea40ac14bbcb9d1983331f4
This commit is contained in:
parent
db8572796d
commit
b0301f5520
@ -105,7 +105,7 @@ def update_test(values, test_id, session=None):
|
||||
|
||||
|
||||
def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None,
|
||||
session=None):
|
||||
id=None, session=None):
|
||||
"""Create a new run record in the database
|
||||
|
||||
:param int skips: total number of skiped tests defaults to 0
|
||||
@ -114,6 +114,7 @@ def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None,
|
||||
:param float run_time: total run timed defaults to 0
|
||||
:param str artifacts: A link to any artifacts from the test run defaults to
|
||||
None
|
||||
:param str id: the run id for the new run, needs to be a unique value
|
||||
:param session: optional session object if one isn't provided a new session
|
||||
will be acquired for the duration of this operation
|
||||
|
||||
@ -121,6 +122,8 @@ def create_run(skips=0, fails=0, passes=0, run_time=0, artifacts=None,
|
||||
:rtype: subunit2sql.models.Run
|
||||
"""
|
||||
run = models.Run()
|
||||
if id:
|
||||
run.id = id
|
||||
run.skips = skips
|
||||
run.fails = fails
|
||||
run.passes = passes
|
||||
|
@ -32,7 +32,10 @@ SHELL_OPTS = shell_opts = [
|
||||
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')
|
||||
help='Location of run artifacts'),
|
||||
cfg.StrOpt('run_id', short='i', default=None,
|
||||
help='Run id to use for the specified subunit stream, can only'
|
||||
' be used if a single stream is provided')
|
||||
]
|
||||
|
||||
_version_ = version.VersionInfo('subunit2sql').version_string()
|
||||
@ -106,7 +109,7 @@ def process_results(results):
|
||||
totals = get_run_totals(results)
|
||||
db_run = api.create_run(totals['skips'], totals['fails'],
|
||||
totals['success'], run_time, CONF.artifacts,
|
||||
session=session)
|
||||
id=CONF.run_id, session=session)
|
||||
if CONF.run_meta:
|
||||
api.add_run_metadata(CONF.run_meta, db_run.id, session)
|
||||
for test in results:
|
||||
@ -146,6 +149,9 @@ def main():
|
||||
cli_opts()
|
||||
parse_args(sys.argv)
|
||||
if CONF.subunit_files:
|
||||
if len(CONF.subunit_files) > 1 and CONF.run_id:
|
||||
print("You can not specify a run id for adding more than 1 stream")
|
||||
return 3
|
||||
streams = [subunit.ReadSubunit(open(s, 'r')) for s in
|
||||
CONF.subunit_files]
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user