diff --git a/moto/autoscaling/responses.py b/moto/autoscaling/responses.py index 70fda4526..e58ef810a 100644 --- a/moto/autoscaling/responses.py +++ b/moto/autoscaling/responses.py @@ -10,6 +10,10 @@ class AutoScalingResponse(BaseResponse): def autoscaling_backend(self): return autoscaling_backends[self.region] + @property + def boto3_request(self): + return 'Boto3' in self.headers.get('User-Agent', []) + def create_launch_configuration(self): instance_monitoring_string = self._get_param('InstanceMonitoring.Enabled') if instance_monitoring_string == 'true': @@ -68,6 +72,11 @@ class AutoScalingResponse(BaseResponse): def describe_auto_scaling_groups(self): names = self._get_multi_param("AutoScalingGroupNames.member") groups = self.autoscaling_backend.describe_autoscaling_groups(names) + if self.boto3_request: + for group in groups: + if group.health_check_period is None: + group.health_check_period = 300 + self.autoscaling_backend.autoscaling_groups[group.name] = group template = self.response_template(DESCRIBE_AUTOSCALING_GROUPS_TEMPLATE) return template.render(groups=groups) diff --git a/tests/test_autoscaling/test_autoscaling_boto3.py b/tests/test_autoscaling/test_autoscaling_boto3.py new file mode 100644 index 000000000..c114a9285 --- /dev/null +++ b/tests/test_autoscaling/test_autoscaling_boto3.py @@ -0,0 +1,41 @@ +from __future__ import unicode_literals +import boto3 +import sure # noqa + +from moto import mock_autoscaling + + +@mock_autoscaling +def test_create_autoscaling_group(): + client = boto3.client('autoscaling') + _ = 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') + _ = 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') diff --git a/tests/test_autoscaling/test_launch_configurations_boto3.py b/tests/test_autoscaling/test_launch_configurations_boto3.py new file mode 100644 index 000000000..b16e5324f --- /dev/null +++ b/tests/test_autoscaling/test_launch_configurations_boto3.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals +import boto3 + +import sure # noqa + +from moto import mock_autoscaling + + +@mock_autoscaling +def test_create_launch_configuration(): + client = boto3.client('autoscaling') + response = client.create_launch_configuration( + LaunchConfigurationName='tester', + ImageId='ami-abcd1234', + InstanceType='t1.micro', + KeyName='the_keys', + SecurityGroups=["default", "default2"], + UserData="This is some user_data", + InstanceMonitoring={'Enabled': True}, + IamInstanceProfile='arn:aws:iam::123456789012:instance-profile/testing', + SpotPrice='0.1' + ) + response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)