LBaaS: include inactive members when retrieving logical config

Closes-Bug: #1229082
Change-Id: I16f452b51a98d912ba8bdf374b4d1e9285d757dc
This commit is contained in:
Oleg Bondarev 2013-09-23 16:14:00 +04:00
parent 1540cd3727
commit 7f6874e33e
4 changed files with 35 additions and 3 deletions

View File

@ -50,6 +50,7 @@ STATS_MAP = {
} }
ACTIVE = qconstants.ACTIVE ACTIVE = qconstants.ACTIVE
INACTIVE = qconstants.INACTIVE
def save_config(conf_path, logical_config, socket_path=None): def save_config(conf_path, logical_config, socket_path=None):
@ -137,7 +138,7 @@ def _build_backend(config):
# add the members # add the members
for member in config['members']: for member in config['members']:
if member['status'] == ACTIVE and member['admin_state_up']: if member['status'] in (ACTIVE, INACTIVE) and member['admin_state_up']:
server = (('server %(id)s %(address)s:%(protocol_port)s ' server = (('server %(id)s %(address)s:%(protocol_port)s '
'weight %(weight)s') % member) + server_addon 'weight %(weight)s') % member) + server_addon
if _has_http_cookie_persistence(config): if _has_http_cookie_persistence(config):

View File

@ -132,7 +132,8 @@ class LoadBalancerCallbacks(object):
) )
retval['members'] = [ retval['members'] = [
self.plugin._make_member_dict(m) self.plugin._make_member_dict(m)
for m in pool.members if m.status == constants.ACTIVE for m in pool.members if m.status in (constants.ACTIVE,
constants.INACTIVE)
] ]
retval['healthmonitors'] = [ retval['healthmonitors'] = [
self.plugin._make_health_monitor_dict(hm.healthmonitor) self.plugin._make_health_monitor_dict(hm.healthmonitor)

View File

@ -110,6 +110,12 @@ class TestHaproxyCfg(base.BaseTestCase):
'id': 'member1_id', 'id': 'member1_id',
'address': '10.0.0.3', 'address': '10.0.0.3',
'protocol_port': 80, 'protocol_port': 80,
'weight': 1},
{'status': 'INACTIVE',
'admin_state_up': True,
'id': 'member2_id',
'address': '10.0.0.4',
'protocol_port': 80,
'weight': 1}], 'weight': 1}],
'healthmonitors': [{'admin_state_up': True, 'healthmonitors': [{'admin_state_up': True,
'delay': 3, 'delay': 3,
@ -124,7 +130,9 @@ class TestHaproxyCfg(base.BaseTestCase):
'\ttimeout check 2s', '\ttimeout check 2s',
'\tcookie SRV insert indirect nocache', '\tcookie SRV insert indirect nocache',
'\tserver member1_id 10.0.0.3:80 weight 1 ' '\tserver member1_id 10.0.0.3:80 weight 1 '
'check inter 3s fall 4 cookie 0'] 'check inter 3s fall 4 cookie 0',
'\tserver member2_id 10.0.0.4:80 weight 1 '
'check inter 3s fall 4 cookie 1']
opts = cfg._build_backend(test_config) opts = cfg._build_backend(test_config)
self.assertEqual(expected_opts, list(opts)) self.assertEqual(expected_opts, list(opts))

View File

@ -227,6 +227,28 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase):
self.assertEqual(logical_config, expected) self.assertEqual(logical_config, expected)
def test_get_logical_device_inactive_member(self):
with self.pool() as pool:
with self.vip(pool=pool) as vip:
with self.member(pool_id=vip['vip']['pool_id']) as member:
ctx = context.get_admin_context()
self.plugin_instance.update_status(ctx, ldb.Pool,
pool['pool']['id'],
'ACTIVE')
self.plugin_instance.update_status(ctx, ldb.Vip,
vip['vip']['id'],
'ACTIVE')
self.plugin_instance.update_status(ctx, ldb.Member,
member['member']['id'],
'INACTIVE')
logical_config = self.callbacks.get_logical_device(
ctx, pool['pool']['id'], activate=False)
member['member']['status'] = constants.INACTIVE
self.assertEqual([member['member']],
logical_config['members'])
def _update_port_test_helper(self, expected, func, **kwargs): def _update_port_test_helper(self, expected, func, **kwargs):
core = self.plugin_instance._core_plugin core = self.plugin_instance._core_plugin