Make ASG resource work when no lb is specified

Change-Id: I0a5a2b62ad1a81f0201d6cd8202bd6e11f7c569c
Closes-Bug: #1535778
This commit is contained in:
Pratik Mallya 2016-01-19 09:43:20 -06:00
parent bf20657824
commit 8107f1ebfd
2 changed files with 38 additions and 10 deletions

View File

@ -121,6 +121,7 @@ class Group(resource.Resource):
_('List of load balancers to hook the '
'server up to. If not specified, no '
'load balancing will be configured.'),
default=[],
schema=properties.Schema(
properties.Schema.MAP,
schema={
@ -292,15 +293,14 @@ class Group(resource.Resource):
server_args = lcargs[self.LAUNCH_CONFIG_ARGS_SERVER]
lb_args = lcargs.get(self.LAUNCH_CONFIG_ARGS_LOAD_BALANCERS)
lbs = copy.deepcopy(lb_args)
if lbs:
for lb in lbs:
# if the port is not specified, the lbid must be that of a
# RackConnectV3 lb pool.
if not lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_PORT]:
del lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_PORT]
continue
lbid = int(lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_ID])
lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_ID] = lbid
for lb in lbs:
# if the port is not specified, the lbid must be that of a
# RackConnectV3 lb pool.
if not lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_PORT]:
del lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_PORT]
continue
lbid = int(lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_ID])
lb[self.LAUNCH_CONFIG_ARGS_LOAD_BALANCER_ID] = lbid
personality = server_args.get(
self.LAUNCH_CONFIG_ARGS_SERVER_PERSONALITY)
if personality:

View File

@ -313,7 +313,7 @@ Resources:
'flavor': 'flavor-ref',
'image': 'image-ref',
'launch_config_type': 'launch_server',
'load_balancers': None,
'load_balancers': [],
'key_name': "my-key",
'max_entities': 25,
'group_metadata': {'group': 'metadata'},
@ -757,3 +757,31 @@ class AutoScaleGroupValidationTests(common.HeatTestCase):
mock.Mock(id='pool_exists'),
]
self.assertIsNone(asg.validate())
def test_validate_no_lb_specified(self, mock_client, mock_plugin):
asg_properties = {
"groupConfiguration": {
"name": "My Group",
"cooldown": 60,
"minEntities": 1,
"maxEntities": 25,
"metadata": {
"group": "metadata",
},
},
"launchConfiguration": {
"type": "launch_server",
"args": {
"server": {
"name": "sdfsdf",
"flavorRef": "ffdgdf",
"imageRef": "image-ref",
},
},
},
}
rsrcdef = rsrc_defn.ResourceDefinition(
"test", auto_scale.Group, properties=asg_properties)
asg = auto_scale.Group("test", rsrcdef, self.mockstack)
self.assertIsNone(asg.validate())