Add db api method to get uuid from test_id

This commit adds 2 new db api methods to deal with taking the test_id
column and finding the value of the matching id. The first method will
return the id value for a given test_id, while the second returns the
list of all ids in the tests table.

Change-Id: I696aebd499ed47a20af0c13415fc568f2b54f188
This commit is contained in:
Matthew Treinish 2015-05-06 16:26:34 -04:00
parent 76e0c04e03
commit f519640c7b
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177

View File

@ -672,3 +672,29 @@ def delete_old_test_runs(expire_age=186, session=None):
db_utils.model_query(models.TestRun, session).filter(
models.TestRun.start_time < expire_date).delete(
synchronize_session='evaluate')
def get_id_from_test_id(test_id, session=None):
"""Return the id (uuid primary key) for a test given it's test_id value
:param str test_id:
:param session: optional session object if one isn't provided a new session
will be acquired for the duration of this operation
:return: The id for the specified test
:rtype: str
"""
session = session or get_session()
return db_utils.model_query(models.Test, session).filter_by(
test_id=test_id).value('id')
def get_ids_for_all_tests(session=None):
"""Return a list of ids (uuid primary key) for all tests in the database
:param session: optional session object if one isn't provided a new session
will be acquired for the duration of this operation
:return: The list of all ids for tests in the tests table
:rtype: list
"""
session = session or get_session()
return db_utils.model_query(models.Test, session).value(models.Test.id)