Merge "Make autoscale not dependent on loadbalancer impl."
This commit is contained in:
commit
23768d8080
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
'''
|
||||
|
@ -334,6 +335,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()
|
||||
|
||||
|
@ -351,21 +368,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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -165,7 +164,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'))
|
||||
|
@ -176,8 +175,7 @@ class LoadBalancerTest(HeatTestCase):
|
|||
except exception.InvalidTemplateAttribute:
|
||||
pass
|
||||
|
||||
self.assertRaises(resource.UpdateReplace,
|
||||
rsrc.handle_update, {}, {}, {})
|
||||
self.assertEqual(None, rsrc.handle_update({}, {}, {}))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
|
Loading…
Reference in New Issue