From 90992c72031da6fe650a2566078948f89bbd1fa6 Mon Sep 17 00:00:00 2001 From: "Felipe N. Schuch" Date: Wed, 9 Aug 2023 11:40:57 -0300 Subject: [PATCH] PENG-1556 replace file container from dict to list --- cluster_agent/jobbergate/schemas.py | 9 ++++++--- cluster_agent/jobbergate/submit.py | 4 ++-- tests/jobbergate/conftest.py | 9 ++++----- tests/jobbergate/test_submit.py | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cluster_agent/jobbergate/schemas.py b/cluster_agent/jobbergate/schemas.py index d505e12..10d339d 100644 --- a/cluster_agent/jobbergate/schemas.py +++ b/cluster_agent/jobbergate/schemas.py @@ -9,17 +9,20 @@ class JobScriptFile(pydantic.BaseModel, extra=pydantic.Extra.ignore): """Model for the job_script_files field of the JobScript resource.""" - id: int + parent_id: int filename: str file_type: FileType + parent_id: int - path: str + @property + def path(self) -> str: + return f"jobbergate/job-scripts/{self.parent_id}/upload/{self.filename}" class JobScript(pydantic.BaseModel, extra=pydantic.Extra.ignore): """Model to match database for the JobScript resource.""" - files: Dict[str, JobScriptFile] + files: List[JobScriptFile] class PendingJobSubmission(pydantic.BaseModel, extra=pydantic.Extra.ignore): diff --git a/cluster_agent/jobbergate/submit.py b/cluster_agent/jobbergate/submit.py index 3283257..e824976 100644 --- a/cluster_agent/jobbergate/submit.py +++ b/cluster_agent/jobbergate/submit.py @@ -86,8 +86,8 @@ async def submit_job_script( job_script = None - for filename, metadata in pending_job_submission.job_script.files.items(): - local_script_path = submit_dir / filename + for metadata in pending_job_submission.job_script.files: + local_script_path = submit_dir / metadata.filename local_script_path.parent.mkdir(parents=True, exist_ok=True) response = await backend_client.get(metadata.path) diff --git a/tests/jobbergate/conftest.py b/tests/jobbergate/conftest.py index 9766127..a028037 100644 --- a/tests/jobbergate/conftest.py +++ b/tests/jobbergate/conftest.py @@ -26,14 +26,13 @@ def dummy_template_source(): @pytest.fixture def dummy_job_script_files(): - return { - "application.sh": { - "id": 1, + return [ + { + "parent_id": 1, "filename": "application.sh", "file_type": "ENTRYPOINT", - "path": "jobbergate/job-scripts/1/upload/application.sh", }, - } + ] @pytest.fixture diff --git a/tests/jobbergate/test_submit.py b/tests/jobbergate/test_submit.py index 626e23c..be4610d 100644 --- a/tests/jobbergate/test_submit.py +++ b/tests/jobbergate/test_submit.py @@ -169,7 +169,7 @@ async def test_submit_job_script__raises_exception_if_no_executable_script_was_f and that the job submission status is updated to rejected. """ pending_job_submission = PendingJobSubmission(**dummy_pending_job_submission_data) - pending_job_submission.job_script.files = {} + pending_job_submission.job_script.files = [] async with respx.mock: respx.post(f"https://{SETTINGS.OIDC_DOMAIN}/oauth/token").mock(