Batch: add jobname validation (#5720)
This commit is contained in:
parent
3d16834e6f
commit
4844af09cc
@ -39,6 +39,7 @@ logger = logging.getLogger(__name__)
|
||||
COMPUTE_ENVIRONMENT_NAME_REGEX = re.compile(
|
||||
r"^[A-Za-z0-9][A-Za-z0-9_-]{1,126}[A-Za-z0-9]$"
|
||||
)
|
||||
JOB_NAME_REGEX = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_-]{1,127}$")
|
||||
|
||||
|
||||
def datetime2int_milliseconds(date: datetime.datetime) -> int:
|
||||
@ -1523,6 +1524,9 @@ class BatchBackend(BaseBackend):
|
||||
"""
|
||||
Parameters RetryStrategy and Parameters are not yet implemented.
|
||||
"""
|
||||
if JOB_NAME_REGEX.match(job_name) is None:
|
||||
raise ClientException("Job name should match valid pattern")
|
||||
|
||||
# Look for job definition
|
||||
job_def = self.get_job_definition(job_def_id)
|
||||
if job_def is None:
|
||||
|
@ -884,3 +884,33 @@ def test_submit_job_with_timeout_set_at_definition():
|
||||
|
||||
# This should fail, as the job-duration is longer than the attemptDurationSeconds
|
||||
_wait_for_job_status(batch_client, job_id, "FAILED")
|
||||
|
||||
|
||||
@mock_batch
|
||||
def test_submit_job_invalid_name():
|
||||
"""
|
||||
Test verifies that a `ClientException` is raised if `jobName` isn't valid
|
||||
"""
|
||||
_, _, _, _, batch_client = _get_clients()
|
||||
with pytest.raises(botocore.exceptions.ClientError) as exc:
|
||||
batch_client.submit_job(
|
||||
jobName="containsinvalidcharacter.",
|
||||
jobQueue="arn",
|
||||
jobDefinition="job_def_name",
|
||||
)
|
||||
assert exc.match("ClientException")
|
||||
|
||||
with pytest.raises(botocore.exceptions.ClientError) as exc:
|
||||
batch_client.submit_job(
|
||||
jobName="-startswithinvalidcharacter",
|
||||
jobQueue="arn",
|
||||
jobDefinition="job_def_name",
|
||||
)
|
||||
assert exc.match("ClientException")
|
||||
|
||||
with pytest.raises(botocore.exceptions.ClientError) as exc:
|
||||
too_long_job_name = "a" * 129
|
||||
batch_client.submit_job(
|
||||
jobName=too_long_job_name, jobQueue="arn", jobDefinition="job_def_name"
|
||||
)
|
||||
assert exc.match("ClientException")
|
||||
|
Loading…
Reference in New Issue
Block a user