From 23e11c1e9523ad661f6516db5f2764c0b773d477 Mon Sep 17 00:00:00 2001 From: Austin Clark Date: Mon, 3 Aug 2015 09:59:40 -0600 Subject: [PATCH] Adds method to get metadata by key/value pair This method will return all runs matching a certain metadata key/value pair (e.g., "build_name" and "[change-id]"). Applications for this method include querying all runs with a certain job config or all runs executed related to a specific patch. The method will be used primarily for visualization and analysis. Change-Id: I4efb3a32de5644ba899897efe74ee3bfd7cf9f22 --- subunit2sql/db/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subunit2sql/db/api.py b/subunit2sql/db/api.py index 8eabea4..ae6877c 100644 --- a/subunit2sql/db/api.py +++ b/subunit2sql/db/api.py @@ -230,6 +230,23 @@ def get_run_metadata(run_id, session=None): return query.all() +def get_runs_by_key_value(key, value, session=None): + """Return all run objects associated with a certain key/value metadata pair + + :param key: The key to be matched + :param value: The value to be matched + :param session: optional session object if one isn't provided a new session + will be acquired for the duration of this operation + :return list: The list of runs + :rtype: subunit2sql.models.Run + """ + session = session or get_session() + query = db_utils.model_query(models.Run, session=session).join( + models.RunMetadata).filter_by(key=key, value=value) + + return query.all() + + def create_test_run(test_id, run_id, status, start_time=None, end_time=None, session=None): """Create a new test run record in the database