Skip to content

Commit

Permalink
Adds Support for filtering on schedulingStrategy in ECS#list_services (
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Decot authored and terrycain committed May 2, 2019
1 parent 1cb2085 commit 8cb4db1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 5 additions & 2 deletions moto/ecs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,15 @@ def create_service(self, cluster_str, service_name, task_definition_str, desired

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):
Expand Down
3 changes: 2 additions & 1 deletion moto/ecs/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def create_service(self):

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
# ,
Expand Down
17 changes: 13 additions & 4 deletions tests/test_ecs/test_ecs_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 8cb4db1

Please sign in to comment.