diff --git a/moto/batch/models.py b/moto/batch/models.py index 887f6f48c..20f280e7e 100644 --- a/moto/batch/models.py +++ b/moto/batch/models.py @@ -1734,7 +1734,7 @@ class BatchBackend(BaseBackend): depends_on: Optional[List[Dict[str, str]]] = None, container_overrides: Optional[Dict[str, Any]] = None, timeout: Optional[Dict[str, int]] = None, - ) -> Tuple[str, str]: + ) -> Tuple[str, str, str]: """ Parameters RetryStrategy and Parameters are not yet implemented. """ @@ -1789,7 +1789,7 @@ class BatchBackend(BaseBackend): else: # Here comes the fun job.start() - return job_name, job.job_id + return job_name, job.job_id, job.arn def describe_jobs(self, jobs: Optional[List[str]]) -> List[Dict[str, Any]]: job_filter = set() diff --git a/moto/batch/responses.py b/moto/batch/responses.py index ef933f3e4..558fcdfa6 100644 --- a/moto/batch/responses.py +++ b/moto/batch/responses.py @@ -212,7 +212,7 @@ class BatchResponse(BaseResponse): timeout = self._get_param("timeout") array_properties = self._get_param("arrayProperties", {}) - name, job_id = self.batch_backend.submit_job( + name, job_id, job_arn = self.batch_backend.submit_job( job_name, job_def, job_queue, @@ -222,7 +222,7 @@ class BatchResponse(BaseResponse): array_properties=array_properties, ) - result = {"jobId": job_id, "jobName": name} + result = {"jobId": job_id, "jobName": name, "jobArn": job_arn} return json.dumps(result) diff --git a/moto/batch_simple/models.py b/moto/batch_simple/models.py index 6d8079ced..14d6572ef 100644 --- a/moto/batch_simple/models.py +++ b/moto/batch_simple/models.py @@ -61,7 +61,7 @@ class BatchSimpleBackend(BaseBackend): depends_on: Optional[List[Dict[str, str]]] = None, container_overrides: Optional[Dict[str, Any]] = None, timeout: Optional[Dict[str, int]] = None, - ) -> Tuple[str, str]: + ) -> Tuple[str, str, str]: # Look for job definition job_def = self.get_job_definition(job_def_id) if job_def is None: @@ -106,7 +106,7 @@ class BatchSimpleBackend(BaseBackend): else: self._mark_job_as_finished(include_start_attempt=True, job=job) - return job_name, job.job_id + return job_name, job.job_id, job.arn def _mark_job_as_finished(self, include_start_attempt: bool, job: Job) -> None: self.backend._jobs[job.job_id] = job diff --git a/tests/test_batch/test_batch_jobs.py b/tests/test_batch/test_batch_jobs.py index 402dbc3c3..5d10fbbea 100644 --- a/tests/test_batch/test_batch_jobs.py +++ b/tests/test_batch/test_batch_jobs.py @@ -1,12 +1,13 @@ -from . import _get_clients, _setup - -import datetime -from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_logs import botocore.exceptions +import datetime import pytest import time from uuid import uuid4 +from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_logs +from tests import DEFAULT_ACCOUNT_ID + +from . import _get_clients, _setup from ..markers import requires_docker @@ -86,10 +87,15 @@ def test_submit_job_by_name(): assert resp_jobs["jobs"][0]["jobDefinition"] == job_definition_arn +# SLOW TESTS + + @mock_ec2 @mock_ecs @mock_iam @mock_batch +@pytest.mark.network +@requires_docker def test_submit_job_array_size(): # Setup job_definition_name = f"sleep10_{str(uuid4())[0:6]}" @@ -130,9 +136,6 @@ def test_submit_job_array_size(): assert len(child_job_1["attempts"]) == 1 -# SLOW TESTS - - @mock_logs @mock_ec2 @mock_ecs @@ -1024,13 +1027,19 @@ def test_submit_job_with_timeout(): commands = ["sleep", "30"] job_def_arn, queue_arn = prepare_job(batch_client, commands, iam_arn, job_def_name) + job_name = str(uuid4())[0:6] resp = batch_client.submit_job( - jobName=str(uuid4())[0:6], + jobName=job_name, jobQueue=queue_arn, jobDefinition=job_def_arn, timeout={"attemptDurationSeconds": 1}, ) job_id = resp["jobId"] + assert resp["jobName"] == job_name + assert ( + resp["jobArn"] + == f"arn:aws:batch:eu-central-1:{DEFAULT_ACCOUNT_ID}:job/{job_id}" + ) # This should fail, as the job-duration is longer than the attemptDurationSeconds _wait_for_job_status(batch_client, job_id, "FAILED")