Adds Support for filtering on schedulingStrategy in ECS#list_services (#2180)

This commit is contained in:
Kyle Decot 2019-05-02 14:00:28 -04:00 committed by Terry Cain
parent 1cb208580d
commit 8cb4db1896
3 changed files with 20 additions and 7 deletions

View File

@ -699,12 +699,15 @@ class EC2ContainerServiceBackend(BaseBackend):
return service
def list_services(self, cluster_str):
def list_services(self, cluster_str, scheduling_strategy=None):
cluster_name = cluster_str.split('/')[-1]
service_arns = []
for key, value in self.services.items():
if cluster_name + ':' in key:
service_arns.append(self.services[key].arn)
service = self.services[key]
if scheduling_strategy is None or service.scheduling_strategy == scheduling_strategy:
service_arns.append(service.arn)
return sorted(service_arns)
def describe_services(self, cluster_str, service_names_or_arns):

View File

@ -163,7 +163,8 @@ class EC2ContainerServiceResponse(BaseResponse):
def list_services(self):
cluster_str = self._get_param('cluster')
service_arns = self.ecs_backend.list_services(cluster_str)
scheduling_strategy = self._get_param('schedulingStrategy')
service_arns = self.ecs_backend.list_services(cluster_str, scheduling_strategy)
return json.dumps({
'serviceArns': service_arns
# ,

View File

@ -388,23 +388,32 @@ def test_list_services():
cluster='test_ecs_cluster',
serviceName='test_ecs_service1',
taskDefinition='test_ecs_task',
schedulingStrategy='REPLICA',
desiredCount=2
)
_ = client.create_service(
cluster='test_ecs_cluster',
serviceName='test_ecs_service2',
taskDefinition='test_ecs_task',
schedulingStrategy='DAEMON',
desiredCount=2
)
response = client.list_services(
unfiltered_response = client.list_services(
cluster='test_ecs_cluster'
)
len(response['serviceArns']).should.equal(2)
response['serviceArns'][0].should.equal(
len(unfiltered_response['serviceArns']).should.equal(2)
unfiltered_response['serviceArns'][0].should.equal(
'arn:aws:ecs:us-east-1:012345678910:service/test_ecs_service1')
response['serviceArns'][1].should.equal(
unfiltered_response['serviceArns'][1].should.equal(
'arn:aws:ecs:us-east-1:012345678910:service/test_ecs_service2')
filtered_response = client.list_services(
cluster='test_ecs_cluster',
schedulingStrategy='REPLICA'
)
len(filtered_response['serviceArns']).should.equal(1)
filtered_response['serviceArns'][0].should.equal(
'arn:aws:ecs:us-east-1:012345678910:service/test_ecs_service1')
@mock_ecs
def test_describe_services():