From 4d5c2f7da983b15b3a58cf2367675ae3e340f164 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 20 Sep 2023 09:39:41 +0100 Subject: [PATCH] move database call out --- spinnman/spalloc/spalloc_client.py | 31 ++++++------------------------ 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/spinnman/spalloc/spalloc_client.py b/spinnman/spalloc/spalloc_client.py index 1563406b5..d8981a412 100644 --- a/spinnman/spalloc/spalloc_client.py +++ b/spinnman/spalloc/spalloc_client.py @@ -98,7 +98,7 @@ def __init__( logger.info("established session to {} for {}", service_url, username) @staticmethod - def open_job_from_database(conn: sqlite3.Cursor) -> SpallocJob: + def open_job_from_database(service_url, job_url, cookies, headers) -> SpallocJob: """ Create a job from the description in the attached database. This is intended to allow for access to the job's allocated resources from @@ -110,35 +110,16 @@ def open_job_from_database(conn: sqlite3.Cursor) -> SpallocJob: credentials may have expired; if so, the job will be unable to regenerate them. - :param ~sqlite3.Cursor conn: - The database cursor to retrieve the job details from. Assumes - the presence of a ``proxy_configuration`` table with ``kind``, - ``name`` and ``value`` columns. + :param str service_url: + :param str job_url: + :param dict(str, str) cookies: + :param dict(str, str) headers: + :return: The job handle, or ``None`` if the records in the database are absent or incomplete. :rtype: SpallocJob """ - service_url = None - job_url = None - cookies = {} - headers = {} - for row in conn.execute(""" - SELECT kind, name, value FROM proxy_configuration - """): - kind, name, value = row - if kind == "SPALLOC": - if name == "service uri": - service_url = value - elif name == "job uri": - job_url = value - elif kind == "COOKIE": - cookies[name] = value - elif kind == "HEADER": - headers[name] = value - if not service_url or not job_url or not cookies or not headers: - # Cannot possibly work without a session or job - return None session = Session(service_url, session_credentials=(cookies, headers)) return _SpallocJob(session, job_url)