moto/tests/test_ecs/test_ecs_capacity_provider.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

212 lines
6.9 KiB
Python
Raw Normal View History

import boto3
2024-01-07 12:03:33 +00:00
from moto import mock_aws
2022-08-13 09:49:43 +00:00
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
2024-01-07 12:03:33 +00:00
@mock_aws
def test_create_capacity_provider():
client = boto3.client("ecs", region_name="us-west-1")
resp = client.create_capacity_provider(
name="my_provider",
autoScalingGroupProvider={
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"status": "ENABLED",
"targetCapacity": 5,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
},
)
provider = resp["capacityProvider"]
assert "capacityProviderArn" in provider
assert provider["name"] == "my_provider"
assert provider["status"] == "ACTIVE"
assert provider["autoScalingGroupProvider"] == {
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"instanceWarmupPeriod": 300,
"status": "ENABLED",
"targetCapacity": 5,
"minimumScalingStepSize": 1,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
}
2024-01-07 12:03:33 +00:00
@mock_aws
def test_create_capacity_provider_with_tags():
client = boto3.client("ecs", region_name="us-west-1")
resp = client.create_capacity_provider(
name="my_provider",
autoScalingGroupProvider={"autoScalingGroupArn": "asg:arn"},
tags=[{"key": "k1", "value": "v1"}],
)
provider = resp["capacityProvider"]
assert "capacityProviderArn" in provider
assert provider["name"] == "my_provider"
assert provider["tags"] == [{"key": "k1", "value": "v1"}]
2023-01-29 23:47:50 +00:00
client.tag_resource(
resourceArn=provider["capacityProviderArn"], tags=[{"key": "k2", "value": "v2"}]
)
resp = client.list_tags_for_resource(resourceArn=provider["capacityProviderArn"])
assert len(resp["tags"]) == 2
assert {"key": "k1", "value": "v1"} in resp["tags"]
assert {"key": "k2", "value": "v2"} in resp["tags"]
2023-01-29 23:47:50 +00:00
client.untag_resource(resourceArn=provider["capacityProviderArn"], tagKeys=["k1"])
resp = client.list_tags_for_resource(resourceArn=provider["capacityProviderArn"])
assert resp["tags"] == [{"key": "k2", "value": "v2"}]
2023-01-29 23:47:50 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
def test_describe_capacity_provider__using_name():
client = boto3.client("ecs", region_name="us-west-1")
client.create_capacity_provider(
name="my_provider",
autoScalingGroupProvider={
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"status": "ENABLED",
"targetCapacity": 5,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
},
)
resp = client.describe_capacity_providers(capacityProviders=["my_provider"])
assert len(resp["capacityProviders"]) == 1
provider = resp["capacityProviders"][0]
assert "capacityProviderArn" in provider
assert provider["name"] == "my_provider"
assert provider["status"] == "ACTIVE"
assert provider["autoScalingGroupProvider"] == {
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"instanceWarmupPeriod": 300,
"status": "ENABLED",
"targetCapacity": 5,
"minimumScalingStepSize": 1,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
}
2024-01-07 12:03:33 +00:00
@mock_aws
def test_describe_capacity_provider__using_arn():
client = boto3.client("ecs", region_name="us-west-1")
provider_arn = client.create_capacity_provider(
name="my_provider",
autoScalingGroupProvider={
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"status": "ENABLED",
"targetCapacity": 5,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
},
)["capacityProvider"]["capacityProviderArn"]
resp = client.describe_capacity_providers(capacityProviders=[provider_arn])
assert len(resp["capacityProviders"]) == 1
provider = resp["capacityProviders"][0]
assert provider["name"] == "my_provider"
2024-01-07 12:03:33 +00:00
@mock_aws
def test_describe_capacity_provider__missing():
client = boto3.client("ecs", region_name="us-west-1")
client.create_capacity_provider(
name="my_provider",
autoScalingGroupProvider={
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
"status": "ENABLED",
"targetCapacity": 5,
"maximumScalingStepSize": 2,
},
"managedTerminationProtection": "DISABLED",
},
)
resp = client.describe_capacity_providers(
capacityProviders=["my_provider", "another_provider"]
)
assert len(resp["capacityProviders"]) == 1
assert resp["failures"] == [
{
"arn": f"arn:aws:ecs:us-west-1:{ACCOUNT_ID}:capacity_provider/another_provider",
"reason": "MISSING",
}
]
2024-01-07 12:03:33 +00:00
@mock_aws
def test_delete_capacity_provider():
client = boto3.client("ecs", region_name="us-west-1")
client.create_capacity_provider(
name="my_provider", autoScalingGroupProvider={"autoScalingGroupArn": "asg:arn"}
)
resp = client.delete_capacity_provider(capacityProvider="my_provider")
assert resp["capacityProvider"]["name"] == "my_provider"
# We can't find either provider
resp = client.describe_capacity_providers(
capacityProviders=["my_provider", "another_provider"]
)
assert resp["capacityProviders"] == []
assert len(resp["failures"]) == 2
assert {
"arn": f"arn:aws:ecs:us-west-1:{ACCOUNT_ID}:capacity_provider/another_provider",
"reason": "MISSING",
} in resp["failures"]
assert {
"arn": f"arn:aws:ecs:us-west-1:{ACCOUNT_ID}:capacity_provider/my_provider",
"reason": "MISSING",
} in resp["failures"]
2023-01-29 23:47:50 +00:00
2024-01-07 12:03:33 +00:00
@mock_aws
2023-01-29 23:47:50 +00:00
def test_update_capacity_provider():
client = boto3.client("ecs", region_name="us-west-1")
client.create_capacity_provider(
name="my_provider", autoScalingGroupProvider={"autoScalingGroupArn": "asg:arn"}
)
resp = client.update_capacity_provider(
name="my_provider",
2023-08-21 20:33:16 +00:00
autoScalingGroupProvider={
"managedScaling": {"status": "ENABLED", "instanceWarmupPeriod": 0}
},
2023-01-29 23:47:50 +00:00
)
assert resp["capacityProvider"]["name"] == "my_provider"
2023-01-29 23:47:50 +00:00
# We can't find either provider
provider = client.describe_capacity_providers(capacityProviders=["my_provider"])[
"capacityProviders"
][0]
assert provider["autoScalingGroupProvider"] == {
"autoScalingGroupArn": "asg:arn",
"managedScaling": {
2023-08-21 20:33:16 +00:00
"instanceWarmupPeriod": 0,
"maximumScalingStepSize": 10000,
"minimumScalingStepSize": 1,
"status": "ENABLED",
"targetCapacity": 100,
},
"managedTerminationProtection": "DISABLED",
}