Merge "Add 'default_pool' property to lbaasv2 listener"

This commit is contained in:
Jenkins 2017-03-23 08:20:13 +00:00 committed by Gerrit Code Review
commit 3975fdd44a
3 changed files with 69 additions and 7 deletions

View File

@ -38,11 +38,11 @@ class Listener(neutron.NeutronResource):
entity = 'listener'
PROPERTIES = (
PROTOCOL_PORT, PROTOCOL, LOADBALANCER, NAME,
PROTOCOL_PORT, PROTOCOL, LOADBALANCER, DEFAULT_POOL, NAME,
ADMIN_STATE_UP, DESCRIPTION, DEFAULT_TLS_CONTAINER_REF,
SNI_CONTAINER_REFS, CONNECTION_LIMIT, TENANT_ID
) = (
'protocol_port', 'protocol', 'loadbalancer', 'name',
'protocol_port', 'protocol', 'loadbalancer', 'default_pool', 'name',
'admin_state_up', 'description', 'default_tls_container_ref',
'sni_container_refs', 'connection_limit', 'tenant_id'
)
@ -80,11 +80,20 @@ class Listener(neutron.NeutronResource):
properties.Schema.STRING,
_('ID or name of the load balancer with which listener '
'is associated.'),
required=True,
constraints=[
constraints.CustomConstraint('neutron.lbaas.loadbalancer')
]
),
DEFAULT_POOL: properties.Schema(
properties.Schema.STRING,
_('ID or name of the default pool for the listener. Requires '
'shared_pools service extension.'),
update_allowed=True,
constraints=[
constraints.CustomConstraint('neutron.lbaas.pool')
],
support_status=support.SupportStatus(version='9.0.0')
),
NAME: properties.Schema(
properties.Schema.STRING,
_('Name of this listener.'),
@ -140,6 +149,10 @@ class Listener(neutron.NeutronResource):
)
}
def __init__(self, name, definition, stack):
super(Listener, self).__init__(name, definition, stack)
self._lb_id = None
def translation_rules(self, props):
return [
translation.TranslationRule(
@ -150,6 +163,14 @@ class Listener(neutron.NeutronResource):
finder='find_resourceid_by_name_or_id',
entity='loadbalancer'
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.DEFAULT_POOL],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='pool'
),
]
def validate(self):
@ -157,6 +178,11 @@ class Listener(neutron.NeutronResource):
if res:
return res
if (self.properties[self.LOADBALANCER] is None
and self.properties[self.DEFAULT_POOL] is None):
raise exception.PropertyUnspecifiedError(self.LOADBALANCER,
self.DEFAULT_POOL)
if self.properties[self.PROTOCOL] == self.TERMINATED_HTTPS:
if self.properties[self.DEFAULT_TLS_CONTAINER_REF] is None:
msg = (_('Property %(ref)s required when protocol is '
@ -164,16 +190,30 @@ class Listener(neutron.NeutronResource):
'term': self.TERMINATED_HTTPS})
raise exception.StackValidationFailed(message=msg)
@property
def lb_id(self):
if self._lb_id:
return self._lb_id
self._lb_id = self.properties[self.LOADBALANCER]
if self._lb_id is None:
pool_id = self.properties[self.DEFAULT_POOL]
pool = self.client().show_pool(pool_id)['pool']
self._lb_id = pool['loadbalancers'][0]['id']
return self._lb_id
def _check_lb_status(self):
lb_id = self.properties[self.LOADBALANCER]
return self.client_plugin().check_lb_status(lb_id)
return self.client_plugin().check_lb_status(self.lb_id)
def handle_create(self):
properties = self.prepare_properties(
self.properties,
self.physical_resource_name())
properties['loadbalancer_id'] = properties.pop(self.LOADBALANCER)
if self.LOADBALANCER in properties:
properties['loadbalancer_id'] = properties.pop(self.LOADBALANCER)
if self.DEFAULT_POOL in properties:
properties['default_pool_id'] = properties.pop(self.DEFAULT_POOL)
return properties
def check_create_complete(self, properties):
@ -191,12 +231,16 @@ class Listener(neutron.NeutronResource):
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
self._update_called = False
self.properties = json_snippet.properties(self.properties_schema,
self.context)
return prop_diff
def check_update_complete(self, prop_diff):
if not prop_diff:
return True
if self.DEFAULT_POOL in prop_diff:
prop_diff['default_pool_id'] = prop_diff.pop(self.DEFAULT_POOL)
if not self._update_called:
try:
self.client().update_listener(self.resource_id,

View File

@ -82,6 +82,7 @@ resources:
protocol_port: 80
protocol: TCP
loadbalancer: 123
default_pool: my_pool
name: my_listener
description: my listener
admin_state_up: True

View File

@ -75,6 +75,7 @@ class ListenerTest(common.HeatTestCase):
'protocol_port': 80,
'protocol': 'TCP',
'loadbalancer_id': '123',
'default_pool_id': 'my_pool',
'name': 'my_listener',
'description': 'my listener',
'admin_state_up': True,
@ -94,6 +95,21 @@ class ListenerTest(common.HeatTestCase):
self.assertFalse(self.listener.check_create_complete(props))
self.assertTrue(self.listener.check_create_complete(props))
@mock.patch('heat.engine.clients.os.neutron.'
'NeutronClientPlugin.has_extension', return_value=True)
def test_create_missing_properties(self, ext_func):
for prop in ('protocol', 'protocol_port', 'loadbalancer'):
tmpl = yaml.load(inline_templates.LISTENER_TEMPLATE)
del tmpl['resources']['listener']['properties'][prop]
del tmpl['resources']['listener']['properties']['default_pool']
self._create_stack(tmpl=yaml.dump(tmpl))
if prop == 'loadbalancer':
self.assertRaises(exception.PropertyUnspecifiedError,
self.listener.validate)
else:
self.assertRaises(exception.StackValidationFailed,
self.listener.validate)
def test_show_resource(self):
self._create_stack()
self.listener.resource_id_set('1234')
@ -120,7 +136,8 @@ class ListenerTest(common.HeatTestCase):
'name': 'your_listener',
}
prop_diff = self.listener.handle_update(None, None, prop_diff)
prop_diff = self.listener.handle_update(self.listener.t,
None, prop_diff)
self.assertFalse(self.listener.check_update_complete(prop_diff))
self.assertFalse(self.listener._update_called)