From 9c7eddc90c7397bb22036b95d12995c12b458e18 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 23 Apr 2014 18:58:21 -0400 Subject: [PATCH] Don't manipulate LoadBalancer template in-place When autoscaling reloads a LoadBalancer, it adjusts the configuration by manipulating the LoadBalancer's json_snippet in-place, which is a very bad policy. Instead, make a copy of the LoadBalancer resource's template, and use that that to perform an update. Change-Id: I0141c3ebc41462f797eb19182a949da0bb4b76a9 --- heat/engine/resources/autoscaling.py | 11 +++++------ heat/tests/test_loadbalancer.py | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 3ecc7aff9..09b8eeae5 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. +import copy import functools import json import math @@ -393,18 +394,16 @@ class InstanceGroup(stack_resource.StackResource): if inst.FnGetRefId() not in exclude] for lb in self.properties[self.LOAD_BALANCER_NAMES]: lb_resource = self.stack[lb] + lb_defn = copy.deepcopy(lb_resource.t) if 'Instances' in lb_resource.properties_schema: - lb_resource.json_snippet['Properties']['Instances'] = ( - id_list) + lb_defn['Properties']['Instances'] = id_list elif 'members' in lb_resource.properties_schema: - lb_resource.json_snippet['Properties']['members'] = ( - id_list) + lb_defn['Properties']['members'] = id_list else: raise exception.Error( _("Unsupported resource '%s' in LoadBalancerNames") % (lb,)) - resolved_snippet = self.stack.resolve_static_data( - lb_resource.json_snippet) + resolved_snippet = self.stack.resolve_static_data(lb_defn) scheduler.TaskRunner(lb_resource.update, resolved_snippet)() def FnGetRefId(self): diff --git a/heat/tests/test_loadbalancer.py b/heat/tests/test_loadbalancer.py index 4ba181ae4..65d64a7ae 100644 --- a/heat/tests/test_loadbalancer.py +++ b/heat/tests/test_loadbalancer.py @@ -11,6 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. +import copy import re import mock @@ -190,7 +191,7 @@ class LoadBalancerTest(HeatTestCase): s) id_list.append(inst.FnGetRefId()) - rsrc.handle_update(rsrc.json_snippet, {}, {'Instances': id_list}) + rsrc.handle_update(copy.deepcopy(rsrc.t), {}, {'Instances': id_list}) self.assertEqual('4.5.6.7', rsrc.FnGetAtt('DNSName')) self.assertEqual('', rsrc.FnGetAtt('SourceSecurityGroup.GroupName'))