ECS: list_services() now throws correct error when providing unknown cluster (#5865)
This commit is contained in:
parent
90e63c1cb5
commit
3a023f0fe1
@ -808,7 +808,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
|||||||
service_region, zones, "ecs"
|
service_region, zones, "ecs"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_cluster(self, name):
|
def _get_cluster(self, name: str) -> Cluster:
|
||||||
# short name or full ARN of the cluster
|
# short name or full ARN of the cluster
|
||||||
cluster_name = name.split("/")[-1]
|
cluster_name = name.split("/")[-1]
|
||||||
|
|
||||||
@ -1333,10 +1333,10 @@ class EC2ContainerServiceBackend(BaseBackend):
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
def list_services(self, cluster_str, scheduling_strategy=None, launch_type=None):
|
def list_services(self, cluster_str, scheduling_strategy=None, launch_type=None):
|
||||||
cluster_name = cluster_str.split("/")[-1]
|
cluster = self._get_cluster(cluster_str)
|
||||||
service_arns = []
|
service_arns = []
|
||||||
for key, service in self.services.items():
|
for key, service in self.services.items():
|
||||||
if cluster_name + ":" not in key:
|
if cluster.name + ":" not in key:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -701,6 +701,17 @@ def test_list_services():
|
|||||||
cluster1_fargate_services["serviceArns"][0].should.equal(test_ecs_service2_arn)
|
cluster1_fargate_services["serviceArns"][0].should.equal(test_ecs_service2_arn)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ecs
|
||||||
|
@pytest.mark.parametrize("args", [{}, {"cluster": "foo"}], ids=["no args", "unknown"])
|
||||||
|
def test_list_unknown_service(args):
|
||||||
|
client = boto3.client("ecs", region_name="us-east-1")
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client.list_services(**args)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ClusterNotFoundException")
|
||||||
|
err["Message"].should.equal("Cluster not found.")
|
||||||
|
|
||||||
|
|
||||||
@mock_ecs
|
@mock_ecs
|
||||||
def test_describe_services():
|
def test_describe_services():
|
||||||
client = boto3.client("ecs", region_name="us-east-1")
|
client = boto3.client("ecs", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user