From 8b6facf1339de4e763ef5316a2f4123f283de9c8 Mon Sep 17 00:00:00 2001 From: Hugo Lopes Tavares Date: Fri, 24 Jan 2014 10:56:08 -0500 Subject: [PATCH 1/2] Add support to launch configuration AssociatePublicIpAddress parameter --- moto/autoscaling/models.py | 6 ++-- moto/autoscaling/responses.py | 2 ++ .../test_launch_configurations.py | 29 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/moto/autoscaling/models.py b/moto/autoscaling/models.py index a9447974b..6d5fe6ace 100644 --- a/moto/autoscaling/models.py +++ b/moto/autoscaling/models.py @@ -29,7 +29,7 @@ class FakeScalingPolicy(object): class FakeLaunchConfiguration(object): def __init__(self, name, image_id, key_name, security_groups, user_data, instance_type, instance_monitoring, instance_profile_name, - spot_price, ebs_optimized): + spot_price, ebs_optimized, associate_public_ip_address): self.name = name self.image_id = image_id self.key_name = key_name @@ -40,6 +40,7 @@ class FakeLaunchConfiguration(object): self.instance_profile_name = instance_profile_name self.spot_price = spot_price self.ebs_optimized = ebs_optimized + self.associate_public_ip_address = associate_public_ip_address @property def instance_monitoring_enabled(self): @@ -129,7 +130,7 @@ class AutoScalingBackend(BaseBackend): def create_launch_configuration(self, name, image_id, key_name, security_groups, user_data, instance_type, instance_monitoring, instance_profile_name, - spot_price, ebs_optimized): + spot_price, ebs_optimized, associate_public_ip_address): launch_configuration = FakeLaunchConfiguration( name=name, image_id=image_id, @@ -141,6 +142,7 @@ class AutoScalingBackend(BaseBackend): instance_profile_name=instance_profile_name, spot_price=spot_price, ebs_optimized=ebs_optimized, + associate_public_ip_address=associate_public_ip_address, ) self.launch_configurations[name] = launch_configuration return launch_configuration diff --git a/moto/autoscaling/responses.py b/moto/autoscaling/responses.py index 55cdf9b6e..a881919e7 100644 --- a/moto/autoscaling/responses.py +++ b/moto/autoscaling/responses.py @@ -34,6 +34,7 @@ class AutoScalingResponse(BaseResponse): instance_profile_name=self._get_param('IamInstanceProfile'), spot_price=self._get_param('SpotPrice'), ebs_optimized=self._get_param('EbsOptimized'), + associate_public_ip_address=self._get_param("AssociatePublicIpAddress"), ) template = Template(CREATE_LAUNCH_CONFIGURATION_TEMPLATE) return template.render() @@ -152,6 +153,7 @@ DESCRIBE_LAUNCH_CONFIGURATIONS_TEMPLATE = """ {% for launch_configuration in launch_configurations %} + {{ launch_configuration.associate_public_ip_address }} {% for security_group in launch_configuration.security_groups %} {{ security_group }} diff --git a/tests/test_autoscaling/test_launch_configurations.py b/tests/test_autoscaling/test_launch_configurations.py index ece3ecfcc..6af07ddcf 100644 --- a/tests/test_autoscaling/test_launch_configurations.py +++ b/tests/test_autoscaling/test_launch_configurations.py @@ -50,6 +50,35 @@ def test_create_launch_configuration_for_2_12(): launch_config.ebs_optimized.should.equal(True) +@requires_boto_gte("2.23") +@mock_autoscaling +def test_create_launch_configuration_using_ip_association(): + conn = boto.connect_autoscale() + config = LaunchConfiguration( + name='tester', + image_id='ami-abcd1234', + associate_public_ip_address=True, + ) + conn.create_launch_configuration(config) + + launch_config = conn.get_all_launch_configurations()[0] + launch_config.associate_public_ip_address.should.equal(True) + + +@requires_boto_gte("2.23") +@mock_autoscaling +def test_create_launch_configuration_using_ip_association_should_default_to_false(): + conn = boto.connect_autoscale() + config = LaunchConfiguration( + name='tester', + image_id='ami-abcd1234', ) + conn.create_launch_configuration(config) + + launch_config = conn.get_all_launch_configurations()[0] + launch_config.associate_public_ip_address.should.equal(False) + + + @mock_autoscaling def test_create_launch_configuration_defaults(): """ Test with the minimum inputs and check that all of the proper defaults From 94abf90920eae2bc096ad50aa9611e7012be3b32 Mon Sep 17 00:00:00 2001 From: Hugo Lopes Tavares Date: Mon, 10 Feb 2014 14:08:56 -0500 Subject: [PATCH 2/2] [tests] Update boto version for the AssociatePublicIpAddress boto fix. Refs #82 --- tests/test_autoscaling/test_launch_configurations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_autoscaling/test_launch_configurations.py b/tests/test_autoscaling/test_launch_configurations.py index 6af07ddcf..fcbc2f6da 100644 --- a/tests/test_autoscaling/test_launch_configurations.py +++ b/tests/test_autoscaling/test_launch_configurations.py @@ -50,7 +50,7 @@ def test_create_launch_configuration_for_2_12(): launch_config.ebs_optimized.should.equal(True) -@requires_boto_gte("2.23") +@requires_boto_gte("2.25.0") @mock_autoscaling def test_create_launch_configuration_using_ip_association(): conn = boto.connect_autoscale() @@ -65,7 +65,7 @@ def test_create_launch_configuration_using_ip_association(): launch_config.associate_public_ip_address.should.equal(True) -@requires_boto_gte("2.23") +@requires_boto_gte("2.25.0") @mock_autoscaling def test_create_launch_configuration_using_ip_association_should_default_to_false(): conn = boto.connect_autoscale()