From: Andrew Plunk Date: Wed, 5 Jun 2013 19:54:41 +0000 (-0500) Subject: Make autoscale not dependent on loadbalancer impl. X-Git-Tag: 2014.1~511^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4bc1bcb608379cc396113a03f2ae37ce78f9049c;p=openstack-build%2Fheat-build.git Make autoscale not dependent on loadbalancer impl. 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 --- diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 7020aefe..ec596e59 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -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) diff --git a/heat/engine/resources/loadbalancer.py b/heat/engine/resources/loadbalancer.py index 4e8fd180..1c23c8fc 100644 --- a/heat/engine/resources/loadbalancer.py +++ b/heat/engine/resources/loadbalancer.py @@ -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) diff --git a/heat/tests/test_autoscaling.py b/heat/tests/test_autoscaling.py index f0036453..a4923e63 100644 --- a/heat/tests/test_autoscaling.py +++ b/heat/tests/test_autoscaling.py @@ -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 diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index 453e3109..84b2eb0b 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -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()