From fc0fb0d40e39f6aeeb5969f31f5b074ebe37f76a Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 8 Jan 2016 16:56:10 -0500 Subject: [PATCH] Fix default ASG health check period. --- moto/autoscaling/models.py | 6 ++- tests/test_autoscaling/test_autoscaling.py | 43 +++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index d67d7dd1c..7a119ecb2 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -275,7 +275,10 @@ class AutoScalingBackend(BaseBackend): max_size = make_int(max_size) min_size = make_int(min_size) default_cooldown = make_int(default_cooldown) - health_check_period = make_int(health_check_period) + if health_check_period is None: + health_check_period = 300 + else: + health_check_period = make_int(health_check_period) group = FakeAutoScalingGroup( name=name, @@ -385,4 +388,3 @@ class AutoScalingBackend(BaseBackend): autoscaling_backends = {} for region, ec2_backend in ec2_backends.items(): autoscaling_backends[region] = AutoScalingBackend(ec2_backend, elb_backends[region]) - diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index 81a331dfb..6a5f768bf 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals import boto +import boto3 import boto.ec2.autoscale from boto.ec2.autoscale.launchconfig import LaunchConfiguration from boto.ec2.autoscale.group import AutoScalingGroup @@ -103,7 +104,7 @@ def test_create_autoscaling_groups_defaults(): group.desired_capacity.should.equal(2) group.vpc_zone_identifier.should.equal('') group.default_cooldown.should.equal(300) - group.health_check_period.should.equal(None) + group.health_check_period.should.equal(300) group.health_check_type.should.equal("EC2") list(group.load_balancers).should.equal([]) group.placement_group.should.equal(None) @@ -378,3 +379,43 @@ def test_autoscaling_group_with_elb(): elb = elb_conn.get_all_load_balancers()[0] elb.instances.should.have.length_of(0) + +''' +Boto3 +''' + + +@mock_autoscaling +def test_create_autoscaling_group(): + 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) + + +@mock_autoscaling +def test_describe_autoscaling_groups(): + 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') \ No newline at end of file