diff --git a/spinnman/spalloc/spalloc_client.py b/spinnman/spalloc/spalloc_client.py index cd2758d4a..90bd74179 100644 --- a/spinnman/spalloc/spalloc_client.py +++ b/spinnman/spalloc/spalloc_client.py @@ -21,7 +21,6 @@ from packaging.version import Version import queue import requests -import sqlite3 import struct import threading from typing import Dict, List, Tuple @@ -98,7 +97,8 @@ 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) @@ -457,8 +438,8 @@ def __init__(self, session, job_handle): self.__proxy_thread = None self.__proxy_ping = None - @overrides(SpallocJob._write_session_credentials_to_db) - def _write_session_credentials_to_db(self, cur): + @overrides(SpallocJob.get_session_credentials_for_db) + def get_session_credentials_for_db(self): config = {} config["SPALLOC", "service uri"] = self._service_url config["SPALLOC", "job uri"] = self._url @@ -471,10 +452,7 @@ def _write_session_credentials_to_db(self, cur): # We never write the auth headers themselves; we just extend the # session del headers["Authorization"] - cur.executemany(""" - INSERT INTO proxy_configuration(kind, name, value) - VALUES(?, ?, ?) - """, [(k1, k2, v) for (k1, k2), v in config.items()]) + return config @overrides(SpallocJob.get_state) def get_state(self): diff --git a/spinnman/spalloc/spalloc_job.py b/spinnman/spalloc/spalloc_job.py index 3ed3edd16..3666a5746 100644 --- a/spinnman/spalloc/spalloc_job.py +++ b/spinnman/spalloc/spalloc_job.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from sqlite3 import Cursor from typing import Dict, Tuple from spinn_utilities.abstract_base import AbstractBase, abstractmethod from spinn_utilities.abstract_context_manager import AbstractContextManager @@ -194,17 +193,13 @@ def where_is_machine(self, x: int, y: int) -> Tuple[int, int, int]: """ @abstractmethod - def _write_session_credentials_to_db(self, cur: Cursor): + def get_session_credentials_for_db(self): """ - Write the session credentials for the job to the database accessed by - the given cursor. + Get the session credentials for the job to be written into a database .. note:: May assume that there is a ``proxy_configuration`` table with ``kind``, ``name`` and ``value`` columns. - - :param ~sqlite3.Cursor cur: - The open cursor to the database. """ def __enter__(self):