Support for ecs describe_task_definition (#777)
* describe_task_definition support * Refactor fetch_task_definition * Add ECS Descriptors (#772) * Add support for "DescribeServices" in ecs mock * Add support for "DescribeTaskDefinition" in ecs * Let ecs responses handle baseobject for services * Update Cloudformation/parsing#load_parameters to split commadelimitedlists into lists (#774) * Fix JSON dump error in ecs.update_service with task_definition (#775) * Fix s3bucketpath handling for IP based requests (#765) * check HTTP header for IPv4 or IPv6 addresses and default to path based S3 * improved IPv4 and IPv6 checking with optional ports * typo * Freezetime. * Add S3 ACL for aws-exec-read. Closes #740. * Fixed time formatting in ec2/models.py (#778) * Fixed time formatting in ec2/models.py * Used freezegun on test that was failing due to time progression causing timestamp differences. * rename duplicate rds/models db_instance_identifier to physical_resource_id (#776) * rename duplicate db_instance_identifier to physical_resource_id * Update create_from_cloudformation_json to use db_source_identifier str * Update code to be more conventional. * describe_task_definition support * Refactor fetch_task_definition
This commit is contained in:
parent
c3c6eaf281
commit
ee8e72766a
@ -150,7 +150,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
self.services = {}
|
||||
self.container_instances = {}
|
||||
|
||||
def fetch_task_definition(self, task_definition_str):
|
||||
def describe_task_definition(self, task_definition_str):
|
||||
task_definition_components = task_definition_str.split(':')
|
||||
if len(task_definition_components) == 2:
|
||||
family, revision = task_definition_components
|
||||
@ -246,7 +246,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
cluster = self.clusters[cluster_name]
|
||||
else:
|
||||
raise Exception("{0} is not a cluster".format(cluster_name))
|
||||
task_definition = self.fetch_task_definition(task_definition_str)
|
||||
task_definition = self.describe_task_definition(task_definition_str)
|
||||
if cluster_name not in self.tasks:
|
||||
self.tasks[cluster_name] = {}
|
||||
tasks = []
|
||||
@ -268,7 +268,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
cluster = self.clusters[cluster_name]
|
||||
else:
|
||||
raise Exception("{0} is not a cluster".format(cluster_name))
|
||||
task_definition = self.fetch_task_definition(task_definition_str)
|
||||
task_definition = self.describe_task_definition(task_definition_str)
|
||||
if cluster_name not in self.tasks:
|
||||
self.tasks[cluster_name] = {}
|
||||
tasks = []
|
||||
@ -346,7 +346,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
cluster = self.clusters[cluster_name]
|
||||
else:
|
||||
raise Exception("{0} is not a cluster".format(cluster_name))
|
||||
task_definition = self.fetch_task_definition(task_definition_str)
|
||||
task_definition = self.describe_task_definition(task_definition_str)
|
||||
desired_count = desired_count if desired_count is not None else 0
|
||||
service = Service(cluster, service_name, task_definition, desired_count)
|
||||
cluster_service_pair = '{0}:{1}'.format(cluster_name, service_name)
|
||||
@ -375,7 +375,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
cluster_service_pair = '{0}:{1}'.format(cluster_name, service_name)
|
||||
if cluster_service_pair in self.services:
|
||||
if task_definition_str is not None:
|
||||
self.fetch_task_definition(task_definition_str)
|
||||
task_definition = self.describe_task_definition(task_definition_str)
|
||||
self.services[cluster_service_pair].task_definition = task_definition_str
|
||||
if desired_count is not None:
|
||||
self.services[cluster_service_pair].desired_count = desired_count
|
||||
|
@ -105,6 +105,14 @@ class EC2ContainerServiceResponse(BaseResponse):
|
||||
'failures': []
|
||||
})
|
||||
|
||||
def describe_task_definition(self):
|
||||
task_definition_str = self._get_param('taskDefinition')
|
||||
data = self.ecs_backend.describe_task_definition(task_definition_str)
|
||||
return json.dumps({
|
||||
'taskDefinition': data.response_object,
|
||||
'failures': []
|
||||
})
|
||||
|
||||
def start_task(self):
|
||||
cluster_str = self._get_param('cluster')
|
||||
overrides = self._get_param('overrides')
|
||||
|
@ -832,6 +832,31 @@ def test_describe_tasks():
|
||||
set([response['tasks'][0]['taskArn'], response['tasks'][1]['taskArn']]).should.equal(set(tasks_arns))
|
||||
|
||||
|
||||
@mock_ecs
|
||||
def describe_task_definition():
|
||||
client = boto3.client('ecs', region_name='us-east-1')
|
||||
container_definition = {
|
||||
'name': 'hello_world',
|
||||
'image': 'docker/hello-world:latest',
|
||||
'cpu': 1024,
|
||||
'memory': 400,
|
||||
'essential': True,
|
||||
'environment': [{
|
||||
'name': 'AWS_ACCESS_KEY_ID',
|
||||
'value': 'SOME_ACCESS_KEY'
|
||||
}],
|
||||
'logConfiguration': {'logDriver': 'json-file'}
|
||||
}
|
||||
task_definition = client.register_task_definition(
|
||||
family='test_ecs_task',
|
||||
containerDefinitions=[container_definition]
|
||||
)
|
||||
family = task_definition['family']
|
||||
task = client.describe_task_definition(taskDefinition=family)
|
||||
task['containerDefinitions'][0].should.equal(container_definition)
|
||||
task['taskDefinitionArn'].should.equal('arn:aws:ecs:us-east-1:012345678910:task-definition/test_ecs_task2:1')
|
||||
task['volumes'].should.equal([])
|
||||
|
||||
@mock_ec2
|
||||
@mock_ecs
|
||||
def test_stop_task():
|
||||
|
Loading…
Reference in New Issue
Block a user