Add host to batch (#4801)

This commit is contained in:
Todd Morse 2022-01-27 18:25:18 -05:00 committed by GitHub
parent 3ae6841b48
commit bbe4402b33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -28,6 +28,7 @@ from moto.iam.exceptions import IAMNotFoundException
from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID
from moto.core.utils import unix_time_millis, BackendDict
from moto.utilities.docker_utilities import DockerModel
from moto import settings
from ..utilities.tagging_service import TaggingService
logger = logging.getLogger(__name__)
@ -562,6 +563,20 @@ class Job(threading.Thread, BaseModel, DockerModel):
else {}
)
environment["MOTO_HOST"] = settings.moto_server_host()
environment["MOTO_PORT"] = settings.moto_server_port()
environment[
"MOTO_HTTP_ENDPOINT"
] = f'{environment["MOTO_HOST"]}:{environment["MOTO_PORT"]}'
run_kwargs = dict()
network_name = settings.moto_network_name()
network_mode = settings.moto_network_mode()
if network_name:
run_kwargs["network"] = network_name
elif network_mode:
run_kwargs["network_mode"] = network_mode
log_config = docker.types.LogConfig(type=docker.types.LogConfig.types.JSON)
self.job_state = "STARTING"
container = self.docker_client.containers.run(
@ -574,6 +589,7 @@ class Job(threading.Thread, BaseModel, DockerModel):
mounts=mounts,
privileged=privileged,
extra_hosts=extra_hosts,
**run_kwargs,
)
self.job_state = "RUNNING"
try:

View File

@ -166,7 +166,7 @@ def test_list_jobs():
job.should.have.key("createdAt")
job.should.have.key("jobDefinition")
job.should.have.key("jobName")
job.should.have.key("status").equals("STARTING")
job.should.have.key("status").which.should.be.within(["STARTING", "RUNNABLE"])
batch_client.list_jobs(jobQueue=queue_arn, jobStatus="SUCCEEDED")[
"jobSummaryList"