From 0a2fb7b7acadf4f339373e6c1d36e40f0fbfba4a Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 3 Oct 2014 23:35:59 -0400 Subject: [PATCH] Fix get_duration db api method This commit fixes the db api method for getting the duration for a test_run. Originally this was just lazily copy and pasted from subunit-trace into the db_api without much thought. However now that there is a desire to use it, the method is refactored to actually work. Change-Id: Ib88a4774b1f0b23f57709aef9b7d34c457a4efdb --- subunit2sql/db/api.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 5494174..142b26a 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -18,6 +18,7 @@ from oslo.db.sqlalchemy import utils as db_utils from subunit2sql.db import models from subunit2sql import exceptions +from subunit2sql import read_subunit CONF = cfg.CONF @@ -232,16 +233,7 @@ def get_test_runs_by_run_id(run_id, session=None): return test_runs -def get_test_run_duration(test_run_id): - session = get_session() - +def get_test_run_duration(test_run_id, session=None): + session = session or get_session() test_run = get_test_run_by_id(test_run_id, session) - start = test_run.start_time - end = test_run.end_time - if not start or not end: - duration = '' - else: - delta = end - start - duration = '%d.%06ds' % ( - delta.days * DAY_SECONDS + delta.seconds, delta.microseconds) - return duration + return read_subunit.get_duration(test_run.start_time, test_run.stop_time)