Browse Source

add senlin cluster_name for lb/pool/listener name for creation

We are passing senlin cluster_name to lb/pool/listener for name,
That way we have proper name relationship between all 3 components.
specially for troubleshooting when we have many loadbalancers.

Example:
$ openstack cluster list -c name -c status
+-----------+--------+
| name      | status |
+-----------+--------+
| mycluster | ACTIVE |
+-----------+--------+
$ openstack loadbalancer list -c name -c vip_address
+---------------------+-------------+
| name                | vip_address |
+---------------------+-------------+
| senlin-lb-mycluster | 10.69.1.173 |
+---------------------+-------------+
$ openstack loadbalancer pool list -c name -c provisioning_status
+-----------------------+---------------------+
| name                  | provisioning_status |
+-----------------------+---------------------+
| senlin-pool-mycluster | ACTIVE              |
+-----------------------+---------------------+


Change-Id: Ibc0c6e7adc6cbdf87c1d1c5ec42f6954d6995253
changes/12/783912/21
Satish Patel 3 months ago
parent
commit
7404f76ae3
5 changed files with 73 additions and 26 deletions
  1. +11
    -4
      senlin/drivers/os/lbaas.py
  2. +4
    -1
      senlin/policies/lb_policy.py
  3. +2
    -1
      senlin/tests/drivers/os_test/lbaas.py
  4. +52
    -19
      senlin/tests/unit/drivers/test_lbaas.py
  5. +4
    -1
      senlin/tests/unit/policies/test_lb_policy.py

+ 11
- 4
senlin/drivers/os/lbaas.py View File

@ -89,7 +89,8 @@ class LoadBalancerDriver(base.DriverBase):
return False
def lb_create(self, vip, pool, hm=None, az=None, flavor_id=None):
def lb_create(self, vip, pool, cluster_name, hm=None, az=None,
flavor_id=None):
"""Create a LBaaS instance
:param vip: A dict containing the properties for the VIP;
@ -117,9 +118,11 @@ class LoadBalancerDriver(base.DriverBase):
LOG.exception(msg)
return False, msg
try:
lb_name = 'senlin-lb-%s' % cluster_name
lb = self.oc().loadbalancer_create(
subnet_id, network_id, vip.get('address', None),
vip['admin_state_up'], availability_zone=az,
vip['admin_state_up'], name=lb_name,
availability_zone=az,
flavor_id=flavor_id)
except exception.InternalError as ex:
msg = ('Failed in creating loadbalancer: %s.'
@ -138,11 +141,13 @@ class LoadBalancerDriver(base.DriverBase):
# Create listener
try:
listener_name = 'senlin-listener-%s' % cluster_name
listener = self.oc().listener_create(lb.id, vip['protocol'],
vip['protocol_port'],
vip.get('connection_limit',
None),
vip['admin_state_up'])
vip['admin_state_up'],
name=listener_name)
except exception.InternalError as ex:
msg = 'Failed in creating lb listener: %s.' % str(ex)
LOG.exception(msg)
@ -157,10 +162,12 @@ class LoadBalancerDriver(base.DriverBase):
# Create pool
try:
pool_name = 'senlin-pool-%s' % cluster_name
pool = self.oc().pool_create(pool['lb_method'], listener.id,
pool['protocol'],
pool['session_persistence'],
pool['admin_state_up'])
pool['admin_state_up'],
name=pool_name)
except exception.InternalError as ex:
msg = 'Failed in creating lb pool: %s.' % str(ex)
LOG.exception(msg)


+ 4
- 1
senlin/policies/lb_policy.py View File

@ -402,6 +402,9 @@ class LoadBalancingPolicy(base.Policy):
lb_driver = self.lbaas(cluster.user, cluster.project)
lb_driver.lb_status_timeout = self.lb_status_timeout
# Set default name variable senlin cluster name
cluster_name = cluster.name
# TODO(Anyone): Check if existing nodes has conflicts regarding the
# subnets. Each VM addresses detail has a key named to the network
# which can be used for validation.
@ -416,7 +419,7 @@ class LoadBalancingPolicy(base.Policy):
else:
res, data = lb_driver.lb_create(self.vip_spec, self.pool_spec,
self.hm_spec, self.az_spec,
self.flavor_id_spec)
self.flavor_id_spec, cluster_name)
if res is False:
return False, data


+ 2
- 1
senlin/tests/drivers/os_test/lbaas.py View File

@ -25,7 +25,8 @@ class LoadBalancerDriver(base.DriverBase):
self.member_id = "9a7aff27-fd41-4ec1-ba4c-3eb92c629313"
def lb_create(self, vip, pool, hm=None, az=None, flavor_id=None):
def lb_create(self, vip, pool, cluster_name, hm=None, az=None,
flavor_id=None):
return True, self.lb_result
def lb_delete(self, **kwargs):


+ 52
- 19
senlin/tests/unit/drivers/test_lbaas.py View File

@ -147,6 +147,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
subnet_obj.id = 'SUBNET_ID'
subnet_obj.network_id = 'NETWORK_ID'
hm_obj.id = 'HEALTHMONITOR_ID'
cluster_name = 'test_cluster'
self.oc.loadbalancer_create.return_value = lb_obj
self.oc.listener_create.return_value = listener_obj
@ -156,23 +157,30 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.lb_driver._wait_for_lb_ready = mock.Mock()
self.lb_driver._wait_for_lb_ready.return_value = True
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm,
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm,
self.availability_zone,
self.flavor_id)
self.assertTrue(status)
lb_name = 'senlin-lb-%s' % cluster_name
self.oc.loadbalancer_create.assert_called_once_with(
'SUBNET_ID', None, self.vip['address'], self.vip['admin_state_up'],
availability_zone=self.availability_zone, flavor_id=self.flavor_id)
name=lb_name, availability_zone=self.availability_zone,
flavor_id=self.flavor_id)
self.assertEqual('LB_ID', res['loadbalancer'])
self.assertEqual('192.168.1.100', res['vip_address'])
listener_name = 'senlin-listener-%s' % cluster_name
self.oc.listener_create.assert_called_once_with(
'LB_ID', self.vip['protocol'], self.vip['protocol_port'],
self.vip['connection_limit'], self.vip['admin_state_up'])
self.vip['connection_limit'], self.vip['admin_state_up'],
name=listener_name)
self.assertEqual('LISTENER_ID', res['listener'])
pool_name = 'senlin-pool-%s' % cluster_name
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['session_persistence'], self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'],
name=pool_name)
self.assertEqual('POOL_ID', res['pool'])
self.oc.healthmonitor_create.assert_called_once_with(
self.hm['type'], self.hm['delay'], self.hm['timeout'],
@ -206,6 +214,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
network_obj.name = 'network'
network_obj.id = 'NETWORK_ID'
hm_obj.id = 'HEALTHMONITOR_ID'
cluster_name = 'test_cluster'
self.oc.loadbalancer_create.return_value = lb_obj
self.oc.listener_create.return_value = listener_obj
@ -215,23 +224,29 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.lb_driver._wait_for_lb_ready = mock.Mock()
self.lb_driver._wait_for_lb_ready.return_value = True
status, res = self.lb_driver.lb_create(vip, self.pool, self.hm,
status, res = self.lb_driver.lb_create(vip, self.pool,
cluster_name, self.hm,
self.availability_zone)
self.assertTrue(status)
lb_name = 'senlin-lb-%s' % cluster_name
self.oc.loadbalancer_create.assert_called_once_with(
None, 'NETWORK_ID', vip['address'], vip['admin_state_up'],
availability_zone=self.availability_zone,
name=lb_name, availability_zone=self.availability_zone,
flavor_id=None)
self.assertEqual('LB_ID', res['loadbalancer'])
self.assertEqual('192.168.1.100', res['vip_address'])
listener_name = 'senlin-listener-%s' % cluster_name
self.oc.listener_create.assert_called_once_with(
'LB_ID', vip['protocol'], vip['protocol_port'],
vip['connection_limit'], vip['admin_state_up'])
vip['connection_limit'], vip['admin_state_up'],
name=listener_name)
self.assertEqual('LISTENER_ID', res['listener'])
pool_name = 'senlin-pool-%s' % cluster_name
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['session_persistence'], self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'],
name=pool_name)
self.assertEqual('POOL_ID', res['pool'])
self.oc.healthmonitor_create.assert_called_once_with(
self.hm['type'], self.hm['delay'], self.hm['timeout'],
@ -251,6 +266,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
subnet_obj.name = 'subnet'
subnet_obj.id = 'SUBNET_ID'
subnet_obj.network_id = 'NETWORK_ID'
cluster_name = 'test_cluster'
self.oc.loadbalancer_create.return_value = lb_obj
self.nc.subnet_get.return_value = subnet_obj
@ -258,13 +274,15 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.lb_driver._wait_for_lb_ready.side_effect = [False]
self.lb_driver.lb_delete = mock.Mock()
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm)
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm)
self.assertFalse(status)
msg = _('Failed in creating loadbalancer (%s).') % 'LB_ID'
self.assertEqual(msg, res)
lb_name = 'senlin-lb-%s' % cluster_name
self.oc.loadbalancer_create.assert_called_once_with(
'SUBNET_ID', None, self.vip['address'], self.vip['admin_state_up'],
availability_zone=None, flavor_id=None)
availability_zone=None, name=lb_name, flavor_id=None)
self.lb_driver._wait_for_lb_ready.assert_called_once_with('LB_ID')
self.lb_driver.lb_delete.assert_called_once_with(
loadbalancer='LB_ID')
@ -296,6 +314,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
subnet_obj.name = 'subnet'
subnet_obj.id = 'SUBNET_ID'
subnet_obj.network_id = 'NETWORK_ID'
cluster_name = 'test_cluster'
self.lb_driver._wait_for_lb_ready = mock.Mock()
self.lb_driver._wait_for_lb_ready.side_effect = [True, False]
@ -304,16 +323,20 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.nc.subnet_get.return_value = subnet_obj
self.lb_driver.lb_delete = mock.Mock()
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm)
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm)
self.assertFalse(status)
msg = _('Failed in creating listener (%s).') % 'LISTENER_ID'
self.assertEqual(msg, res)
lb_name = 'senlin-lb-%s' % cluster_name
self.oc.loadbalancer_create.assert_called_once_with(
'SUBNET_ID', None, self.vip['address'], self.vip['admin_state_up'],
availability_zone=None, flavor_id=None)
availability_zone=None, name=lb_name, flavor_id=None)
listener_name = 'senlin-listener-%s' % cluster_name
self.oc.listener_create.assert_called_once_with(
'LB_ID', self.vip['protocol'], self.vip['protocol_port'],
self.vip['connection_limit'], self.vip['admin_state_up'])
self.vip['connection_limit'], self.vip['admin_state_up'],
name=listener_name)
self.lb_driver._wait_for_lb_ready.assert_called_with('LB_ID')
self.lb_driver.lb_delete.assert_called_once_with(
loadbalancer='LB_ID', listener='LISTENER_ID')
@ -340,6 +363,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
subnet_obj.name = 'subnet'
subnet_obj.id = 'SUBNET_ID'
subnet_obj.network_id = 'NETWORK_ID'
cluster_name = 'test_cluster'
self.lb_driver._wait_for_lb_ready = mock.Mock()
self.lb_driver._wait_for_lb_ready.side_effect = [True, True, False]
@ -349,19 +373,25 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.nc.subnet_get.return_value = subnet_obj
self.lb_driver.lb_delete = mock.Mock()
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm)
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm)
self.assertFalse(status)
msg = _('Failed in creating pool (%s).') % 'POOL_ID'
self.assertEqual(msg, res)
lb_name = 'senlin-lb-%s' % cluster_name
self.oc.loadbalancer_create.assert_called_once_with(
'SUBNET_ID', None, self.vip['address'], self.vip['admin_state_up'],
availability_zone=None, flavor_id=None)
availability_zone=None, name=lb_name, flavor_id=None)
listener_name = 'senlin-listener-%s' % cluster_name
self.oc.listener_create.assert_called_once_with(
'LB_ID', self.vip['protocol'], self.vip['protocol_port'],
self.vip['connection_limit'], self.vip['admin_state_up'])
self.vip['connection_limit'], self.vip['admin_state_up'],
name=listener_name)
pool_name = 'senlin-pool-%s' % cluster_name
self.oc.pool_create.assert_called_once_with(
self.pool['lb_method'], 'LISTENER_ID', self.pool['protocol'],
self.pool['session_persistence'], self.pool['admin_state_up'])
self.pool['session_persistence'], self.pool['admin_state_up'],
name=pool_name)
self.lb_driver._wait_for_lb_ready.assert_called_with('LB_ID')
self.lb_driver.lb_delete.assert_called_once_with(
loadbalancer='LB_ID', listener='LISTENER_ID', pool='POOL_ID')
@ -389,6 +419,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
subnet_obj.id = 'SUBNET_ID'
subnet_obj.network_id = 'NETWORK_ID'
hm_obj.id = 'HEALTHMONITOR_ID'
cluster_name = 'test_cluster'
self.lb_driver._wait_for_lb_ready = mock.Mock()
self.lb_driver._wait_for_lb_ready.side_effect = [True, True,
@ -400,7 +431,8 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.nc.subnet_get.return_value = subnet_obj
self.lb_driver.lb_delete = mock.Mock()
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm)
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm)
self.assertFalse(status)
msg = _('Failed in creating health monitor (%s).') % 'HEALTHMONITOR_ID'
self.assertEqual(msg, res)
@ -413,7 +445,8 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.lb_driver._wait_for_lb_ready.side_effect = [True, True, True]
self.oc.healthmonitor_create.side_effect = exception.InternalError(
code=500, message='CREATE FAILED')
status, res = self.lb_driver.lb_create(self.vip, self.pool, self.hm)
status, res = self.lb_driver.lb_create(self.vip, self.pool,
cluster_name, self.hm)
self.assertFalse(status)
msg = _('Failed in creating lb health monitor: CREATE FAILED.')
self.assertEqual(msg, res)


+ 4
- 1
senlin/tests/unit/policies/test_lb_policy.py View File

@ -385,13 +385,16 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
res, data = policy.attach(cluster)
cluster_name = cluster.name
self.assertTrue(res)
self.assertEqual('policy_data', data)
self.lb_driver.lb_create.assert_called_once_with(policy.vip_spec,
policy.pool_spec,
policy.hm_spec,
policy.az_spec,
policy.flavor_id_spec)
policy.flavor_id_spec,
cluster_name)
member_add_calls = [
mock.call(node1, 'LB_ID', 'POOL_ID', 80, 'internal-subnet'),
mock.call(node2, 'LB_ID', 'POOL_ID', 80, 'internal-subnet')


Loading…
Cancel
Save