]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add VPCZoneIdentifier attribute for autoscaling
authorSimon Pasquier <simon.pasquier@bull.net>
Wed, 21 Aug 2013 09:52:27 +0000 (11:52 +0200)
committerSimon Pasquier <simon.pasquier@bull.net>
Tue, 27 Aug 2013 07:34:18 +0000 (09:34 +0200)
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
heat/tests/test_autoscaling.py

index 9ca41f59398dce2b186d18f8ec4e3d8d98bfb8c1..ce8a9701b7d7c2faa5c982de1ba26c928ca50188 100644 (file)
@@ -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',
index a56bb5816bad58e2e3cad9968bd6a036fe2b2e6d..cf5b98174d00f0d51f08a121c2acff1b56db831a 100644 (file)
@@ -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')