2014-08-27 15:17:06 +00:00
|
|
|
from __future__ import unicode_literals
|
2013-07-27 20:24:38 +00:00
|
|
|
import boto
|
2016-01-08 21:56:10 +00:00
|
|
|
import boto3
|
2015-12-14 03:41:17 +00:00
|
|
|
import boto.ec2.autoscale
|
2013-07-27 20:24:38 +00:00
|
|
|
from boto.ec2.autoscale.launchconfig import LaunchConfiguration
|
|
|
|
from boto.ec2.autoscale.group import AutoScalingGroup
|
2015-10-06 18:02:38 +00:00
|
|
|
from boto.ec2.autoscale import Tag
|
2015-12-14 03:41:17 +00:00
|
|
|
import boto.ec2.elb
|
2013-08-03 21:09:36 +00:00
|
|
|
import sure # noqa
|
2013-07-27 20:24:38 +00:00
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
from moto import mock_autoscaling, mock_ec2_deprecated, mock_elb_deprecated, mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
from tests.helpers import requires_boto_gte
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
|
|
|
@mock_elb_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_create_autoscaling_group():
|
2015-12-14 03:41:17 +00:00
|
|
|
elb_conn = boto.ec2.elb.connect_to_region('us-east-1')
|
2017-02-24 02:37:43 +00:00
|
|
|
elb_conn.create_load_balancer(
|
|
|
|
'test_lb', zones=[], listeners=[(80, 8080, 'http')])
|
2015-12-14 03:41:17 +00:00
|
|
|
|
|
|
|
conn = boto.ec2.autoscale.connect_to_region('us-east-1')
|
2013-07-27 20:24:38 +00:00
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
2013-08-03 21:09:36 +00:00
|
|
|
default_cooldown=60,
|
2013-07-27 20:24:38 +00:00
|
|
|
desired_capacity=2,
|
2013-08-03 21:09:36 +00:00
|
|
|
health_check_period=100,
|
|
|
|
health_check_type="EC2",
|
2013-07-27 20:24:38 +00:00
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
2013-08-03 21:09:36 +00:00
|
|
|
load_balancers=["test_lb"],
|
|
|
|
placement_group="test_placement",
|
2013-07-27 20:24:38 +00:00
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
2013-08-03 21:09:36 +00:00
|
|
|
termination_policies=["OldestInstance", "NewestInstance"],
|
2015-10-06 18:02:38 +00:00
|
|
|
tags=[Tag(
|
|
|
|
resource_id='tester_group',
|
|
|
|
key='test_key',
|
|
|
|
value='test_value',
|
|
|
|
propagate_at_launch=True
|
2017-02-24 02:37:43 +00:00
|
|
|
)
|
2015-10-06 18:02:38 +00:00
|
|
|
],
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.name.should.equal('tester_group')
|
2017-02-24 02:37:43 +00:00
|
|
|
set(group.availability_zones).should.equal(
|
|
|
|
set(['us-east-1c', 'us-east-1b']))
|
2013-07-27 20:24:38 +00:00
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
group.max_size.should.equal(2)
|
|
|
|
group.min_size.should.equal(2)
|
2014-07-13 18:47:35 +00:00
|
|
|
group.instances.should.have.length_of(2)
|
2013-07-27 20:24:38 +00:00
|
|
|
group.vpc_zone_identifier.should.equal('subnet-1234abcd')
|
|
|
|
group.launch_config_name.should.equal('tester')
|
2013-08-03 21:09:36 +00:00
|
|
|
group.default_cooldown.should.equal(60)
|
|
|
|
group.health_check_period.should.equal(100)
|
|
|
|
group.health_check_type.should.equal("EC2")
|
|
|
|
list(group.load_balancers).should.equal(["test_lb"])
|
|
|
|
group.placement_group.should.equal("test_placement")
|
2017-02-24 02:37:43 +00:00
|
|
|
list(group.termination_policies).should.equal(
|
|
|
|
["OldestInstance", "NewestInstance"])
|
2015-10-06 18:02:38 +00:00
|
|
|
len(list(group.tags)).should.equal(1)
|
|
|
|
tag = list(group.tags)[0]
|
|
|
|
tag.resource_id.should.equal('tester_group')
|
|
|
|
tag.key.should.equal('test_key')
|
|
|
|
tag.value.should.equal('test_value')
|
|
|
|
tag.propagate_at_launch.should.equal(True)
|
2013-07-27 20:24:38 +00:00
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_create_autoscaling_groups_defaults():
|
|
|
|
""" Test with the minimum inputs and check that all of the proper defaults
|
|
|
|
are assigned for the other attributes """
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.name.should.equal('tester_group')
|
|
|
|
group.max_size.should.equal(2)
|
|
|
|
group.min_size.should.equal(2)
|
|
|
|
group.launch_config_name.should.equal('tester')
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
list(group.availability_zones).should.equal([])
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
group.vpc_zone_identifier.should.equal('')
|
2013-08-03 21:09:36 +00:00
|
|
|
group.default_cooldown.should.equal(300)
|
2016-01-08 21:56:10 +00:00
|
|
|
group.health_check_period.should.equal(300)
|
2013-08-03 21:09:36 +00:00
|
|
|
group.health_check_type.should.equal("EC2")
|
|
|
|
list(group.load_balancers).should.equal([])
|
|
|
|
group.placement_group.should.equal(None)
|
|
|
|
list(group.termination_policies).should.equal([])
|
2015-10-06 16:21:26 +00:00
|
|
|
list(group.tags).should.equal([])
|
2013-07-27 20:24:38 +00:00
|
|
|
|
|
|
|
|
2017-05-11 01:58:42 +00:00
|
|
|
@mock_autoscaling
|
|
|
|
def test_list_many_autoscaling_groups():
|
|
|
|
conn = boto3.client('autoscaling', region_name='us-east-1')
|
|
|
|
conn.create_launch_configuration(LaunchConfigurationName='TestLC')
|
|
|
|
|
|
|
|
for i in range(51):
|
|
|
|
conn.create_auto_scaling_group(AutoScalingGroupName='TestGroup%d' % i,
|
|
|
|
MinSize=1,
|
|
|
|
MaxSize=2,
|
|
|
|
LaunchConfigurationName='TestLC')
|
|
|
|
|
|
|
|
response = conn.describe_auto_scaling_groups()
|
|
|
|
groups = response["AutoScalingGroups"]
|
|
|
|
marker = response["NextToken"]
|
|
|
|
groups.should.have.length_of(50)
|
|
|
|
marker.should.equal(groups[-1]['AutoScalingGroupName'])
|
|
|
|
|
|
|
|
response2 = conn.describe_auto_scaling_groups(NextToken=marker)
|
|
|
|
|
|
|
|
groups.extend(response2["AutoScalingGroups"])
|
|
|
|
groups.should.have.length_of(51)
|
|
|
|
assert 'NextToken' not in response2.keys()
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_autoscaling_group_describe_filter():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
group.name = 'tester_group2'
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
group.name = 'tester_group3'
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
conn.get_all_groups(
|
|
|
|
names=['tester_group', 'tester_group2']).should.have.length_of(2)
|
2013-07-27 20:24:38 +00:00
|
|
|
conn.get_all_groups().should.have.length_of(3)
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_autoscaling_update():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
|
|
|
desired_capacity=2,
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.vpc_zone_identifier.should.equal('subnet-1234abcd')
|
|
|
|
|
|
|
|
group.vpc_zone_identifier = 'subnet-5678efgh'
|
|
|
|
group.update()
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.vpc_zone_identifier.should.equal('subnet-5678efgh')
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2016-06-18 01:51:28 +00:00
|
|
|
def test_autoscaling_tags_update():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
|
|
|
instance_type='t2.medium',
|
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
|
|
|
desired_capacity=2,
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
|
|
|
tags=[Tag(
|
|
|
|
resource_id='tester_group',
|
|
|
|
key='test_key',
|
|
|
|
value='test_value',
|
|
|
|
propagate_at_launch=True
|
|
|
|
)],
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
conn.create_or_update_tags(tags=[Tag(
|
2017-02-24 02:37:43 +00:00
|
|
|
resource_id='tester_group',
|
|
|
|
key='test_key',
|
|
|
|
value='new_test_value',
|
|
|
|
propagate_at_launch=True
|
|
|
|
), Tag(
|
|
|
|
resource_id='tester_group',
|
|
|
|
key='test_key2',
|
|
|
|
value='test_value2',
|
|
|
|
propagate_at_launch=True
|
|
|
|
)])
|
2016-06-18 01:51:28 +00:00
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.tags.should.have.length_of(2)
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_autoscaling_group_delete():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
conn.get_all_groups().should.have.length_of(1)
|
|
|
|
|
|
|
|
conn.delete_auto_scaling_group('tester_group')
|
|
|
|
conn.get_all_groups().should.have.length_of(0)
|
|
|
|
|
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_ec2_deprecated
|
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_autoscaling_group_describe_instances():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(2)
|
|
|
|
instances[0].launch_config_name.should.equal('tester')
|
|
|
|
autoscale_instance_ids = [instance.instance_id for instance in instances]
|
|
|
|
|
|
|
|
ec2_conn = boto.connect_ec2()
|
|
|
|
reservations = ec2_conn.get_all_instances()
|
|
|
|
instances = reservations[0].instances
|
|
|
|
instances.should.have.length_of(2)
|
|
|
|
instance_ids = [instance.id for instance in instances]
|
|
|
|
set(autoscale_instance_ids).should.equal(set(instance_ids))
|
2015-08-04 01:52:43 +00:00
|
|
|
instances[0].instance_type.should.equal("t2.medium")
|
2013-07-27 20:24:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@requires_boto_gte("2.8")
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_set_desired_capacity_up():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
|
|
|
desired_capacity=2,
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(2)
|
|
|
|
|
|
|
|
conn.set_desired_capacity("tester_group", 3)
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(3)
|
|
|
|
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(3)
|
|
|
|
|
|
|
|
|
|
|
|
@requires_boto_gte("2.8")
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_set_desired_capacity_down():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
|
|
|
desired_capacity=2,
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(2)
|
|
|
|
|
|
|
|
conn.set_desired_capacity("tester_group", 1)
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(1)
|
|
|
|
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(1)
|
|
|
|
|
|
|
|
|
|
|
|
@requires_boto_gte("2.8")
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
2013-07-27 20:24:38 +00:00
|
|
|
def test_set_desired_capacity_the_same():
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
2015-08-04 01:52:43 +00:00
|
|
|
instance_type='t2.medium',
|
2013-07-27 20:24:38 +00:00
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
availability_zones=['us-east-1c', 'us-east-1b'],
|
|
|
|
desired_capacity=2,
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
vpc_zone_identifier='subnet-1234abcd',
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(2)
|
|
|
|
|
|
|
|
conn.set_desired_capacity("tester_group", 2)
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
|
|
|
|
instances = list(conn.get_all_autoscaling_instances())
|
|
|
|
instances.should.have.length_of(2)
|
2015-12-07 20:55:41 +00:00
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
|
2017-02-16 03:35:45 +00:00
|
|
|
@mock_autoscaling_deprecated
|
|
|
|
@mock_elb_deprecated
|
2015-12-07 20:55:41 +00:00
|
|
|
def test_autoscaling_group_with_elb():
|
|
|
|
elb_conn = boto.connect_elb()
|
|
|
|
zones = ['us-east-1a', 'us-east-1b']
|
|
|
|
ports = [(80, 8080, 'http'), (443, 8443, 'tcp')]
|
|
|
|
lb = elb_conn.create_load_balancer('my-lb', zones, ports)
|
|
|
|
instances_health = elb_conn.describe_instance_health('my-lb')
|
|
|
|
instances_health.should.be.empty
|
|
|
|
|
|
|
|
conn = boto.connect_autoscale()
|
|
|
|
config = LaunchConfiguration(
|
|
|
|
name='tester',
|
|
|
|
image_id='ami-abcd1234',
|
|
|
|
instance_type='t2.medium',
|
|
|
|
)
|
|
|
|
conn.create_launch_configuration(config)
|
|
|
|
group = AutoScalingGroup(
|
|
|
|
name='tester_group',
|
|
|
|
max_size=2,
|
|
|
|
min_size=2,
|
|
|
|
launch_config=config,
|
|
|
|
load_balancers=["my-lb"],
|
|
|
|
)
|
|
|
|
conn.create_auto_scaling_group(group)
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
elb = elb_conn.get_all_load_balancers()[0]
|
|
|
|
group.desired_capacity.should.equal(2)
|
|
|
|
elb.instances.should.have.length_of(2)
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
autoscale_instance_ids = set(
|
|
|
|
instance.instance_id for instance in group.instances)
|
2015-12-07 20:55:41 +00:00
|
|
|
elb_instace_ids = set(instance.id for instance in elb.instances)
|
|
|
|
autoscale_instance_ids.should.equal(elb_instace_ids)
|
|
|
|
|
|
|
|
conn.set_desired_capacity("tester_group", 3)
|
|
|
|
group = conn.get_all_groups()[0]
|
|
|
|
elb = elb_conn.get_all_load_balancers()[0]
|
|
|
|
group.desired_capacity.should.equal(3)
|
|
|
|
elb.instances.should.have.length_of(3)
|
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
autoscale_instance_ids = set(
|
|
|
|
instance.instance_id for instance in group.instances)
|
2015-12-07 20:55:41 +00:00
|
|
|
elb_instace_ids = set(instance.id for instance in elb.instances)
|
|
|
|
autoscale_instance_ids.should.equal(elb_instace_ids)
|
|
|
|
|
|
|
|
conn.delete_auto_scaling_group('tester_group')
|
|
|
|
conn.get_all_groups().should.have.length_of(0)
|
|
|
|
elb = elb_conn.get_all_load_balancers()[0]
|
|
|
|
elb.instances.should.have.length_of(0)
|
|
|
|
|
2016-01-08 21:56:10 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
Boto3
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
@mock_autoscaling
|
2016-05-15 19:17:59 +00:00
|
|
|
def test_create_autoscaling_group_boto3():
|
2017-02-24 02:37:43 +00:00
|
|
|
client = boto3.client('autoscaling', region_name='us-east-1')
|
|
|
|
_ = client.create_launch_configuration(
|
|
|
|
LaunchConfigurationName='test_launch_configuration'
|
|
|
|
)
|
|
|
|
response = client.create_auto_scaling_group(
|
|
|
|
AutoScalingGroupName='test_asg',
|
|
|
|
LaunchConfigurationName='test_launch_configuration',
|
|
|
|
MinSize=0,
|
|
|
|
MaxSize=20,
|
|
|
|
DesiredCapacity=5
|
|
|
|
)
|
|
|
|
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
2016-01-08 21:56:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_autoscaling
|
2016-05-15 19:17:59 +00:00
|
|
|
def test_describe_autoscaling_groups_boto3():
|
2017-02-24 02:37:43 +00:00
|
|
|
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=20,
|
|
|
|
DesiredCapacity=5
|
|
|
|
)
|
|
|
|
response = client.describe_auto_scaling_groups(
|
|
|
|
AutoScalingGroupNames=["test_asg"]
|
|
|
|
)
|
|
|
|
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
|
|
|
response['AutoScalingGroups'][0][
|
|
|
|
'AutoScalingGroupName'].should.equal('test_asg')
|
2016-05-02 02:34:16 +00:00
|
|
|
|
2016-06-18 01:51:28 +00:00
|
|
|
|
2016-05-02 02:34:16 +00:00
|
|
|
@mock_autoscaling
|
|
|
|
def test_update_autoscaling_group_boto3():
|
|
|
|
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=20,
|
|
|
|
DesiredCapacity=5
|
|
|
|
)
|
|
|
|
|
|
|
|
response = client.update_auto_scaling_group(
|
|
|
|
AutoScalingGroupName='test_asg',
|
|
|
|
MinSize=1,
|
|
|
|
)
|
2016-05-05 02:10:11 +00:00
|
|
|
|
|
|
|
response = client.describe_auto_scaling_groups(
|
|
|
|
AutoScalingGroupNames=["test_asg"]
|
|
|
|
)
|
|
|
|
response['AutoScalingGroups'][0]['MinSize'].should.equal(1)
|
2016-06-18 01:51:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@mock_autoscaling
|
|
|
|
def test_autoscaling_taqs_update_boto3():
|
|
|
|
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=20,
|
|
|
|
DesiredCapacity=5,
|
|
|
|
Tags=[{
|
|
|
|
"ResourceId": 'test_asg',
|
|
|
|
"Key": 'test_key',
|
|
|
|
"Value": 'test_value',
|
|
|
|
"PropagateAtLaunch": True
|
|
|
|
}]
|
|
|
|
)
|
|
|
|
|
|
|
|
client.create_or_update_tags(Tags=[{
|
2017-02-24 02:37:43 +00:00
|
|
|
"ResourceId": 'test_asg',
|
|
|
|
"Key": 'test_key',
|
|
|
|
"Value": 'updated_test_value',
|
|
|
|
"PropagateAtLaunch": True
|
|
|
|
}, {
|
|
|
|
"ResourceId": 'test_asg',
|
|
|
|
"Key": 'test_key2',
|
|
|
|
"Value": 'test_value2',
|
|
|
|
"PropagateAtLaunch": True
|
|
|
|
}])
|
2016-06-18 01:51:28 +00:00
|
|
|
|
|
|
|
response = client.describe_auto_scaling_groups(
|
|
|
|
AutoScalingGroupNames=["test_asg"]
|
|
|
|
)
|
|
|
|
response['AutoScalingGroups'][0]['Tags'].should.have.length_of(2)
|
2017-01-12 01:40:57 +00:00
|
|
|
|
2017-02-24 02:37:43 +00:00
|
|
|
|
2017-01-12 01:40:57 +00:00
|
|
|
@mock_autoscaling
|
|
|
|
def test_autoscaling_describe_policies_boto3():
|
|
|
|
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=20,
|
|
|
|
DesiredCapacity=5,
|
|
|
|
Tags=[{
|
|
|
|
"ResourceId": 'test_asg',
|
|
|
|
"Key": 'test_key',
|
|
|
|
"Value": 'test_value',
|
|
|
|
"PropagateAtLaunch": True
|
|
|
|
}]
|
|
|
|
)
|
|
|
|
|
|
|
|
client.put_scaling_policy(
|
|
|
|
AutoScalingGroupName='test_asg',
|
|
|
|
PolicyName='test_policy_down',
|
|
|
|
PolicyType='SimpleScaling',
|
|
|
|
AdjustmentType='PercentChangeInCapacity',
|
|
|
|
ScalingAdjustment=-10,
|
|
|
|
Cooldown=60,
|
|
|
|
MinAdjustmentMagnitude=1)
|
|
|
|
client.put_scaling_policy(
|
|
|
|
AutoScalingGroupName='test_asg',
|
|
|
|
PolicyName='test_policy_up',
|
|
|
|
PolicyType='SimpleScaling',
|
|
|
|
AdjustmentType='PercentChangeInCapacity',
|
|
|
|
ScalingAdjustment=10,
|
|
|
|
Cooldown=60,
|
|
|
|
MinAdjustmentMagnitude=1)
|
|
|
|
|
|
|
|
response = client.describe_policies()
|
|
|
|
response['ScalingPolicies'].should.have.length_of(2)
|
|
|
|
|
|
|
|
response = client.describe_policies(AutoScalingGroupName='test_asg')
|
|
|
|
response['ScalingPolicies'].should.have.length_of(2)
|
|
|
|
|
|
|
|
response = client.describe_policies(PolicyTypes=['StepScaling'])
|
|
|
|
response['ScalingPolicies'].should.have.length_of(0)
|
|
|
|
|
|
|
|
response = client.describe_policies(
|
|
|
|
AutoScalingGroupName='test_asg',
|
|
|
|
PolicyNames=['test_policy_down'],
|
|
|
|
PolicyTypes=['SimpleScaling']
|
|
|
|
)
|
|
|
|
response['ScalingPolicies'].should.have.length_of(1)
|
2017-02-24 02:37:43 +00:00
|
|
|
response['ScalingPolicies'][0][
|
|
|
|
'PolicyName'].should.equal('test_policy_down')
|