]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make autoscale not dependent on loadbalancer impl.
authorAndrew Plunk <andrew.plunk@rackspace.com>
Wed, 5 Jun 2013 19:54:41 +0000 (14:54 -0500)
committerAndrew Plunk <andrew.plunk@rackspace.com>
Wed, 5 Jun 2013 19:56:55 +0000 (14:56 -0500)
Autoscale was calling reload on a resource, which is not part of the
resource interface. Autoscale has been modified to use update.

Change-Id: Ifb17c9def7e560d96e26308db67b4ee3f93a2b9f

heat/engine/resources/autoscaling.py
heat/engine/resources/loadbalancer.py
heat/tests/test_autoscaling.py
heat/tests/test_loadbalancer.py

index 7020aefe01e7511e9471d1f0e729a3ef686e21b9..ec596e59cb2d98348fb644942b071947de38e0ee 100644 (file)
@@ -211,7 +211,9 @@ class InstanceGroup(resource.Resource):
                 id_list.append(inst.FnGetRefId())
 
             for lb in self.properties['LoadBalancerNames']:
-                self.stack[lb].reload(id_list)
+                self.stack[lb].json_snippet['Properties']['Instances'] = \
+                    inst_list
+                self.stack[lb].update(self.stack[lb].json_snippet)
 
     def FnGetRefId(self):
         return unicode(self.name)
index 4e8fd180f06dbfaa5ac2ef563653fe1643948f88..1c23c8fca24f0cead46ac90ccac29208f70537e8 100644 (file)
@@ -230,9 +230,8 @@ class LoadBalancer(stack_resource.StackResource):
         'HealthCheck': {'Type': 'Map',
                         'Schema': healthcheck_schema},
         'Instances': {'Type': 'List'},
-        'Listeners': {'Type': 'List',
-                      'Schema': {'Type': 'Map',
-                                 'Schema': listeners_schema}},
+        'Listeners': {'Type': 'List', 'Required': True,
+                      'Schema': {'Type': 'Map', 'Schema': listeners_schema}},
         'AppCookieStickinessPolicy': {'Type': 'String',
                                       'Implemented': False},
         'LBCookieStickinessPolicy': {'Type': 'String',
@@ -242,6 +241,8 @@ class LoadBalancer(stack_resource.StackResource):
         'Subnets': {'Type': 'List',
                     'Implemented': False}
     }
+    update_allowed_keys = ('Properties',)
+    update_allowed_properties = ('Instances',)
 
     def _instance_to_ipaddress(self, inst):
         '''
@@ -333,6 +334,22 @@ class LoadBalancer(stack_resource.StackResource):
 
         return self.create_with_template(templ, param)
 
+    def handle_update(self, json_snippet, tmpl_diff, prop_diff):
+        '''
+        re-generate the Metadata
+        save it to the db.
+        rely on the cfn-hup to reconfigure HAProxy
+        '''
+        if 'Instances' in prop_diff:
+            templ = template_format.parse(lb_template)
+            cfg = self._haproxy_config(templ, prop_diff['Instances'])
+
+            md = self.nested()['LB_instance'].metadata
+            files = md['AWS::CloudFormation::Init']['config']['files']
+            files['/etc/haproxy/haproxy.cfg']['content'] = cfg
+
+            self.nested()['LB_instance'].metadata = md
+
     def handle_delete(self):
         self.delete_nested()
 
@@ -350,21 +367,6 @@ class LoadBalancer(stack_resource.StackResource):
                 return {'Error':
                         'Interval must be larger than Timeout'}
 
-    def reload(self, inst_list):
-        '''
-        re-generate the Metadata
-        save it to the db.
-        rely on the cfn-hup to reconfigure HAProxy
-        '''
-        templ = template_format.parse(lb_template)
-        cfg = self._haproxy_config(templ, inst_list)
-
-        md = self.nested()['LB_instance'].metadata
-        files = md['AWS::CloudFormation::Init']['config']['files']
-        files['/etc/haproxy/haproxy.cfg']['content'] = cfg
-
-        self.nested()['LB_instance'].metadata = md
-
     def FnGetRefId(self):
         return unicode(self.name)
 
index f0036453deac99ee8de491b3054fb11db2a44ad6..a4923e6323595fd41978e4f182fe6f87a7a3c13c 100644 (file)
@@ -33,7 +33,11 @@ as_template = '''
 {
   "AWSTemplateFormatVersion" : "2010-09-09",
   "Description" : "AutoScaling Test",
-  "Parameters" : {},
+  "Parameters" : {
+  "KeyName": {
+    "Type": "String"
+  }
+  },
   "Resources" : {
     "WebServerGroup" : {
       "Type" : "AWS::AutoScaling::AutoScalingGroup",
@@ -64,7 +68,15 @@ as_template = '''
       }
     },
     "ElasticLoadBalancer" : {
-      "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
+        "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
+        "Properties" : {
+            "AvailabilityZones" : ["nova"],
+            "Listeners" : [ {
+                "LoadBalancerPort" : "80",
+                "InstancePort" : "80",
+                "Protocol" : "HTTP"
+            }]
+        }
     },
     "LaunchConfig" : {
       "Type" : "AWS::AutoScaling::LaunchConfiguration",
@@ -120,8 +132,11 @@ class AutoScalingTest(HeatTestCase):
         if unset:
             self.m.VerifyAll()
             self.m.UnsetStubs()
-        self.m.StubOutWithMock(loadbalancer.LoadBalancer, 'reload')
-        loadbalancer.LoadBalancer.reload(expected_list).AndReturn(None)
+        self.m.StubOutWithMock(loadbalancer.LoadBalancer, 'handle_update')
+
+        loadbalancer.LoadBalancer.handle_update(
+            mox.IgnoreArg(), mox.IgnoreArg(), {'Instances': expected_list})\
+            .AndReturn(None)
 
     def _stub_meta_expected(self, now, data, nmeta=1):
         # Stop time at now
index 453e310921ed59b6e4daee7cc4867cdaee1070c5..84b2eb0bec1813e07e79fcc9a0a938112fb6ea02 100644 (file)
@@ -21,7 +21,6 @@ from heat.common import exception
 from heat.common import config
 from heat.common import template_format
 from heat.engine import clients
-from heat.engine import resource
 from heat.engine import scheduler
 from heat.engine.resources import instance
 from heat.engine.resources import user
@@ -161,7 +160,7 @@ class LoadBalancerTest(HeatTestCase):
                                      s)
             id_list.append(inst.FnGetRefId())
 
-        rsrc.reload(id_list)
+        rsrc.handle_update(rsrc.json_snippet, {}, {'Instances': id_list})
 
         self.assertEqual('4.5.6.7', rsrc.FnGetAtt('DNSName'))
         self.assertEqual('', rsrc.FnGetAtt('SourceSecurityGroupName'))
@@ -172,8 +171,7 @@ class LoadBalancerTest(HeatTestCase):
         except exception.InvalidTemplateAttribute:
             pass
 
-        self.assertRaises(resource.UpdateReplace,
-                          rsrc.handle_update, {}, {}, {})
+        self.assertEqual(None, rsrc.handle_update({}, {}, {}))
 
         self.m.VerifyAll()