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
This commit is contained in:
Zane Bitter 2014-04-23 18:58:21 -04:00
parent ad4bb143dd
commit 9c7eddc90c
2 changed files with 7 additions and 7 deletions

View File

@ -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):

View File

@ -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'))