Implement enter_standby, exit_standby and terminate_instance_in_auto_scaling_group
This commit is contained in:
parent
755a08e137
commit
d745dfd3d2
3 changed files with 777 additions and 18 deletions
|
|
@ -1102,8 +1102,6 @@ def test_detach_one_instance_decrement():
|
|||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_detach],
|
||||
|
|
@ -1156,8 +1154,6 @@ def test_detach_one_instance():
|
|||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_detach])
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_detach],
|
||||
|
|
@ -1178,6 +1174,516 @@ def test_detach_one_instance():
|
|||
tags.should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_one_instance_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=2,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby = response["AutoScalingGroups"][0]["Instances"][0]["InstanceId"]
|
||||
instance_to_keep = response["AutoScalingGroups"][0]["Instances"][1]["InstanceId"]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby],
|
||||
ShouldDecrementDesiredCapacity=True,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(2)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(1)
|
||||
|
||||
response = client.describe_auto_scaling_instances(InstanceIds=[instance_to_standby])
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
# test to ensure tag has been retained (standby instance is still part of the ASG)
|
||||
response = ec2_client.describe_instances()
|
||||
for reservation in response["Reservations"]:
|
||||
for instance in reservation["Instances"]:
|
||||
tags = instance["Tags"]
|
||||
tags.should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_one_instance():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=2,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby = response["AutoScalingGroups"][0]["Instances"][0]["InstanceId"]
|
||||
instance_to_keep = response["AutoScalingGroups"][0]["Instances"][1]["InstanceId"]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(InstanceIds=[instance_to_standby])
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
# test to ensure tag has been retained (standby instance is still part of the ASG)
|
||||
response = ec2_client.describe_instances()
|
||||
for reservation in response["Reservations"]:
|
||||
for instance in reservation["Instances"]:
|
||||
tags = instance["Tags"]
|
||||
tags.should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_elb
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_elb_update():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=2,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
elb_client = boto3.client("elb", region_name="us-east-1")
|
||||
elb_client.create_load_balancer(
|
||||
LoadBalancerName="my-lb",
|
||||
Listeners=[{"Protocol": "tcp", "LoadBalancerPort": 80, "InstancePort": 8080}],
|
||||
AvailabilityZones=["us-east-1a", "us-east-1b"],
|
||||
)
|
||||
|
||||
response = client.attach_load_balancers(
|
||||
AutoScalingGroupName="test_asg", LoadBalancerNames=["my-lb"]
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby = response["AutoScalingGroups"][0]["Instances"][0]["InstanceId"]
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(InstanceIds=[instance_to_standby])
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = elb_client.describe_load_balancers(LoadBalancerNames=["my-lb"])
|
||||
list(response["LoadBalancerDescriptions"][0]["Instances"]).should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_terminate_instance_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=3,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby_terminate = response["AutoScalingGroups"][0]["Instances"][0][
|
||||
"InstanceId"
|
||||
]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_terminate],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(
|
||||
InstanceIds=[instance_to_standby_terminate]
|
||||
)
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = client.terminate_instance_in_auto_scaling_group(
|
||||
InstanceId=instance_to_standby_terminate, ShouldDecrementDesiredCapacity=True
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
# AWS still decrements desired capacity ASG if requested, even if the terminated instance is in standby
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(1)
|
||||
response["AutoScalingGroups"][0]["Instances"][0]["InstanceId"].should_not.equal(
|
||||
instance_to_standby_terminate
|
||||
)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(1)
|
||||
|
||||
response = ec2_client.describe_instances(
|
||||
InstanceIds=[instance_to_standby_terminate]
|
||||
)
|
||||
response["Reservations"][0]["Instances"][0]["State"]["Name"].should.equal(
|
||||
"terminated"
|
||||
)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_terminate_instance_no_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=3,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby_terminate = response["AutoScalingGroups"][0]["Instances"][0][
|
||||
"InstanceId"
|
||||
]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_terminate],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(
|
||||
InstanceIds=[instance_to_standby_terminate]
|
||||
)
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = client.terminate_instance_in_auto_scaling_group(
|
||||
InstanceId=instance_to_standby_terminate, ShouldDecrementDesiredCapacity=False
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
group = response["AutoScalingGroups"][0]
|
||||
group["Instances"].should.have.length_of(2)
|
||||
instance_to_standby_terminate.shouldnt.be.within(
|
||||
[x["InstanceId"] for x in group["Instances"]]
|
||||
)
|
||||
group["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = ec2_client.describe_instances(
|
||||
InstanceIds=[instance_to_standby_terminate]
|
||||
)
|
||||
response["Reservations"][0]["Instances"][0]["State"]["Name"].should.equal(
|
||||
"terminated"
|
||||
)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_detach_instance_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=3,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby_detach = response["AutoScalingGroups"][0]["Instances"][0][
|
||||
"InstanceId"
|
||||
]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_detach],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(
|
||||
InstanceIds=[instance_to_standby_detach]
|
||||
)
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_detach],
|
||||
ShouldDecrementDesiredCapacity=True,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
# AWS still decrements desired capacity ASG if requested, even if the detached instance was in standby
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(1)
|
||||
response["AutoScalingGroups"][0]["Instances"][0]["InstanceId"].should_not.equal(
|
||||
instance_to_standby_detach
|
||||
)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(1)
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_standby_detach])
|
||||
response["Reservations"][0]["Instances"][0]["State"]["Name"].should.equal("running")
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_detach_instance_no_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=3,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby_detach = response["AutoScalingGroups"][0]["Instances"][0][
|
||||
"InstanceId"
|
||||
]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_detach],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(
|
||||
InstanceIds=[instance_to_standby_detach]
|
||||
)
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = client.detach_instances(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_detach],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
group = response["AutoScalingGroups"][0]
|
||||
group["Instances"].should.have.length_of(2)
|
||||
instance_to_standby_detach.shouldnt.be.within(
|
||||
[x["InstanceId"] for x in group["Instances"]]
|
||||
)
|
||||
group["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = ec2_client.describe_instances(InstanceIds=[instance_to_standby_detach])
|
||||
response["Reservations"][0]["Instances"][0]["State"]["Name"].should.equal("running")
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_standby_exit_standby():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
MaxSize=3,
|
||||
DesiredCapacity=2,
|
||||
Tags=[
|
||||
{
|
||||
"ResourceId": "test_asg",
|
||||
"ResourceType": "auto-scaling-group",
|
||||
"Key": "propogated-tag-key",
|
||||
"Value": "propagate-tag-value",
|
||||
"PropagateAtLaunch": True,
|
||||
}
|
||||
],
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
instance_to_standby_exit_standby = response["AutoScalingGroups"][0]["Instances"][0][
|
||||
"InstanceId"
|
||||
]
|
||||
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
|
||||
response = client.enter_standby(
|
||||
AutoScalingGroupName="test_asg",
|
||||
InstanceIds=[instance_to_standby_exit_standby],
|
||||
ShouldDecrementDesiredCapacity=False,
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.have.length_of(3)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(2)
|
||||
|
||||
response = client.describe_auto_scaling_instances(
|
||||
InstanceIds=[instance_to_standby_exit_standby]
|
||||
)
|
||||
response["AutoScalingInstances"][0]["LifecycleState"].should.equal("Standby")
|
||||
|
||||
response = client.exit_standby(
|
||||
AutoScalingGroupName="test_asg", InstanceIds=[instance_to_standby_exit_standby],
|
||||
)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
group = response["AutoScalingGroups"][0]
|
||||
group["Instances"].should.have.length_of(3)
|
||||
instance_to_standby_exit_standby.should.be.within(
|
||||
[x["InstanceId"] for x in group["Instances"]]
|
||||
)
|
||||
group["DesiredCapacity"].should.equal(3)
|
||||
|
||||
response = ec2_client.describe_instances(
|
||||
InstanceIds=[instance_to_standby_exit_standby]
|
||||
)
|
||||
response["Reservations"][0]["Instances"][0]["State"]["Name"].should.equal("running")
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_attach_one_instance():
|
||||
|
|
@ -1411,7 +1917,7 @@ def test_set_desired_capacity_down_boto3():
|
|||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_terminate_instance_in_autoscaling_group():
|
||||
def test_terminate_instance_via_ec2_in_autoscaling_group():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
|
|
@ -1440,3 +1946,71 @@ def test_terminate_instance_in_autoscaling_group():
|
|||
for instance in response["AutoScalingGroups"][0]["Instances"]
|
||||
)
|
||||
replaced_instance_id.should_not.equal(original_instance_id)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_terminate_instance_in_auto_scaling_group_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
_ = client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
DesiredCapacity=1,
|
||||
MaxSize=2,
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
NewInstancesProtectedFromScaleIn=False,
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
original_instance_id = next(
|
||||
instance["InstanceId"]
|
||||
for instance in response["AutoScalingGroups"][0]["Instances"]
|
||||
)
|
||||
client.terminate_instance_in_auto_scaling_group(
|
||||
InstanceId=original_instance_id, ShouldDecrementDesiredCapacity=True
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
response["AutoScalingGroups"][0]["Instances"].should.equal([])
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(0)
|
||||
|
||||
|
||||
@mock_autoscaling
|
||||
@mock_ec2
|
||||
def test_terminate_instance_in_auto_scaling_group_no_decrement():
|
||||
mocked_networking = setup_networking()
|
||||
client = boto3.client("autoscaling", region_name="us-east-1")
|
||||
_ = client.create_launch_configuration(
|
||||
LaunchConfigurationName="test_launch_configuration"
|
||||
)
|
||||
_ = client.create_auto_scaling_group(
|
||||
AutoScalingGroupName="test_asg",
|
||||
LaunchConfigurationName="test_launch_configuration",
|
||||
MinSize=0,
|
||||
DesiredCapacity=1,
|
||||
MaxSize=2,
|
||||
VPCZoneIdentifier=mocked_networking["subnet1"],
|
||||
NewInstancesProtectedFromScaleIn=False,
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
original_instance_id = next(
|
||||
instance["InstanceId"]
|
||||
for instance in response["AutoScalingGroups"][0]["Instances"]
|
||||
)
|
||||
client.terminate_instance_in_auto_scaling_group(
|
||||
InstanceId=original_instance_id, ShouldDecrementDesiredCapacity=False
|
||||
)
|
||||
|
||||
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=["test_asg"])
|
||||
replaced_instance_id = next(
|
||||
instance["InstanceId"]
|
||||
for instance in response["AutoScalingGroups"][0]["Instances"]
|
||||
)
|
||||
replaced_instance_id.should_not.equal(original_instance_id)
|
||||
response["AutoScalingGroups"][0]["DesiredCapacity"].should.equal(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue