From b0301f5520e693ef317fd6c4bfd5cddb7566c456 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 27 Oct 2014 18:45:15 -0400 Subject: [PATCH] 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 --- subunit2sql/db/api.py | 5 ++++- subunit2sql/shell.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 15f272c..3bc913b 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -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 diff --git a/subunit2sql/shell.py b/subunit2sql/shell.py index 0b14bfa..ee1b9f3 100644 --- a/subunit2sql/shell.py +++ b/subunit2sql/shell.py @@ -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: