From c2298b6b7d97cf5c758ee92cb4e3d85d6ed77ecf Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 21 Aug 2013 11:52:27 +0200 Subject: [PATCH] Add VPCZoneIdentifier attribute for autoscaling For now, only one subnet can be specified in the launch configuration because Neutron doesn't have the ability to map subnets with availability zones. See bug #1096017 for details. Change-Id: I46ef4d17b2109c97664f7606c97b16071553ebcd Fixes: bug #1196494 --- heat/engine/resources/autoscaling.py | 18 ++++++++++++++++ heat/tests/test_autoscaling.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 9ca41f59..ce8a9701 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -200,6 +200,9 @@ class InstanceGroup(stack_resource.StackResource): instance_definition = copy.deepcopy(conf.t) instance_definition['Type'] = 'AWS::EC2::Instance' instance_definition['Properties']['Tags'] = self._tags() + if self.properties.get('VPCZoneIdentifier'): + instance_definition['Properties']['SubnetId'] = \ + self.properties['VPCZoneIdentifier'][0] # resolve references within the context of this stack. fully_parsed = self.stack.resolve_runtime_data(instance_definition) @@ -288,6 +291,7 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin): 'AllowedValues': ['EC2', 'ELB'], 'Implemented': False}, 'LoadBalancerNames': {'Type': 'List'}, + 'VPCZoneIdentifier': {'Type': 'List'}, 'Tags': {'Type': 'List', 'Schema': {'Type': 'Map', 'Schema': tags_schema}} } @@ -414,6 +418,20 @@ class AutoScalingGroup(InstanceGroup, CooldownMixin): def FnGetRefId(self): return unicode(self.name) + def validate(self): + res = super(AutoScalingGroup, self).validate() + if res: + return res + + # TODO(pasquier-s): once Neutron is able to assign subnets to + # availability zones, it will be possible to specify multiple subnets. + # For now, only one subnet can be specified. The bug #1096017 tracks + # this issue. + if self.properties.get('VPCZoneIdentifier') and \ + len(self.properties['VPCZoneIdentifier']) != 1: + raise exception.NotSupported(feature=_("Anything other than one " + "VPCZoneIdentifier")) + class LaunchConfiguration(resource.Resource): tags_schema = {'Key': {'Type': 'String', diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index a56bb581..cf5b9817 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -1409,3 +1409,34 @@ class AutoScalingTest(HeatTestCase): rsrc.delete() self.m.VerifyAll() + + def test_vpc_zone_identifier(self): + t = template_format.parse(as_template) + properties = t['Resources']['WebServerGroup']['Properties'] + properties['VPCZoneIdentifier'] = ['xxxx'] + + stack = utils.parse_stack(t, params=self.params) + + self._stub_lb_reload(1) + now = timeutils.utcnow() + self._stub_meta_expected(now, 'ExactCapacity : 1') + self._stub_create(1) + self.m.ReplayAll() + + rsrc = self.create_scaling_group(t, stack, 'WebServerGroup') + instances = rsrc.get_instances() + self.assertEqual(1, len(instances)) + self.assertEqual('xxxx', instances[0].properties['SubnetId']) + + rsrc.delete() + self.m.VerifyAll() + + def test_invalid_vpc_zone_identifier(self): + t = template_format.parse(as_template) + properties = t['Resources']['WebServerGroup']['Properties'] + properties['VPCZoneIdentifier'] = ['xxxx', 'yyyy'] + + stack = utils.parse_stack(t, params=self.params) + + self.assertRaises(exception.NotSupported, self.create_scaling_group, t, + stack, 'WebServerGroup') -- 2.45.2