diff --git a/neutron/services/loadbalancer/drivers/haproxy/cfg.py b/neutron/services/loadbalancer/drivers/haproxy/cfg.py index 113a0bbcf9..052945cad5 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/cfg.py +++ b/neutron/services/loadbalancer/drivers/haproxy/cfg.py @@ -50,6 +50,7 @@ STATS_MAP = { } ACTIVE = qconstants.ACTIVE +INACTIVE = qconstants.INACTIVE def save_config(conf_path, logical_config, socket_path=None): @@ -137,7 +138,7 @@ def _build_backend(config): # add the 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 ' 'weight %(weight)s') % member) + server_addon if _has_http_cookie_persistence(config): diff --git a/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py b/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py index cb1c14dc71..ee703a9011 100644 --- a/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py +++ b/neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py @@ -132,7 +132,8 @@ class LoadBalancerCallbacks(object): ) retval['members'] = [ 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'] = [ self.plugin._make_health_monitor_dict(hm.healthmonitor) diff --git a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py index 5e9d1b3b22..9552707fc9 100644 --- a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py +++ b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_cfg.py @@ -110,6 +110,12 @@ class TestHaproxyCfg(base.BaseTestCase): 'id': 'member1_id', 'address': '10.0.0.3', 'protocol_port': 80, + 'weight': 1}, + {'status': 'INACTIVE', + 'admin_state_up': True, + 'id': 'member2_id', + 'address': '10.0.0.4', + 'protocol_port': 80, 'weight': 1}], 'healthmonitors': [{'admin_state_up': True, 'delay': 3, @@ -124,7 +130,9 @@ class TestHaproxyCfg(base.BaseTestCase): '\ttimeout check 2s', '\tcookie SRV insert indirect nocache', '\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) self.assertEqual(expected_opts, list(opts)) diff --git a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_plugin_driver.py b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_plugin_driver.py index 1b1dd927b4..2146250717 100644 --- a/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_plugin_driver.py +++ b/neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_plugin_driver.py @@ -227,6 +227,28 @@ class TestLoadBalancerCallbacks(TestLoadBalancerPluginBase): 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): core = self.plugin_instance._core_plugin