From c44c27404f8e47dd400357f1866a18fff57515f3 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 5 Nov 2012 14:37:36 +0100 Subject: [PATCH] Avoid modifying the Properties of a Load Balancer Properties are defined by the template, and should not be modified. In this case it was just as a convenience, since the value does not actually need to be persisted beyond even the current call. Change-Id: I6ca07989d246ec618b2ca5f051f8e614e24c81ae Signed-off-by: Zane Bitter --- heat/engine/resources/loadbalancer.py | 10 ++++------ heat/tests/test_loadbalancer.py | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/heat/engine/resources/loadbalancer.py b/heat/engine/resources/loadbalancer.py index ac8ed220..4e955cef 100644 --- a/heat/engine/resources/loadbalancer.py +++ b/heat/engine/resources/loadbalancer.py @@ -223,7 +223,7 @@ class LoadBalancer(stack.Stack): return '0.0.0.0' - def _haproxy_config(self, templ): + def _haproxy_config(self, templ, instances): # initial simplifications: # - only one Listener # - only http (no tcp or ssl) @@ -275,7 +275,7 @@ class LoadBalancer(stack.Stack): servers = [] n = 1 - for i in self.properties['Instances']: + for i in instances: ip = self._instance_to_ipaddress(i) logger.debug('haproxy server:%s' % ip) servers.append('%sserver server%d %s:%s %s' % (spaces, n, @@ -291,7 +291,7 @@ class LoadBalancer(stack.Stack): if self.properties['Instances']: md = templ['Resources']['LB_instance']['Metadata'] files = md['AWS::CloudFormation::Init']['config']['files'] - cfg = self._haproxy_config(templ) + cfg = self._haproxy_config(templ, self.properties['Instances']) files['/etc/haproxy/haproxy.cfg']['content'] = cfg self.create_with_template(templ) @@ -316,10 +316,8 @@ class LoadBalancer(stack.Stack): save it to the db. rely on the cfn-hup to reconfigure HAProxy ''' - self.calculate_properties() - self.properties['Instances'] = inst_list templ = json.loads(lb_template) - cfg = self._haproxy_config(templ) + cfg = self._haproxy_config(templ, inst_list) md = self.nested()['LB_instance'].metadata files = md['AWS::CloudFormation::Init']['config']['files'] diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index 78b8f86f..4c2c22aa 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -117,7 +117,8 @@ class LoadBalancerTest(unittest.TestCase): self.assertEqual('LoadBalancer', resource.FnGetRefId()) templ = json.loads(lb.lb_template) - ha_cfg = resource._haproxy_config(templ) + ha_cfg = resource._haproxy_config(templ, + resource.properties['Instances']) self.assertRegexpMatches(ha_cfg, 'bind \*:80') self.assertRegexpMatches(ha_cfg, 'server server1 1\.2\.3\.4:80 ' 'check inter 30s fall 5 rise 3') -- 2.45.2