Browse Source

Add name instead of id of node when add to load balancer

When we use load balancer policy to attach cluster, members will
add to pool by member id. So this patch will improve it by using
name of node instead of id member (member of pool)

I hope this will make more transparency

Change-Id: I0c00d197d5eaa95b2c9102daa8470ac02fbbf15c
changes/78/734678/3
Bo Tran 1 year ago
committed by Duc Truong
parent
commit
8be0717e95
5 changed files with 16 additions and 11 deletions
  1. +3
    -2
      senlin/drivers/os/lbaas.py
  2. +3
    -2
      senlin/drivers/os/octavia_v2.py
  3. +3
    -2
      senlin/tests/drivers/os_test/octavia_v2.py
  4. +2
    -1
      senlin/tests/unit/drivers/test_lbaas.py
  5. +5
    -4
      senlin/tests/unit/drivers/test_octavia_v2.py

+ 3
- 2
senlin/drivers/os/lbaas.py View File

@ -291,6 +291,7 @@ class LoadBalancerDriver(base.DriverBase):
project_safe=False)
node_detail = prof.do_get_details(node)
addresses = node_detail.get('addresses')
node_name = node_detail.get('name')
if net_name not in addresses:
LOG.error('Node is not in subnet %(subnet)s', {'subnet': subnet})
return None
@ -318,8 +319,8 @@ class LoadBalancerDriver(base.DriverBase):
if not res:
msg = 'Loadbalancer %s is not ready.' % lb_id
raise exception.Error(msg)
member = self.oc().pool_member_create(pool_id, address, port,
subnet_obj.id)
member = self.oc().pool_member_create(
node_name, pool_id, address, port, subnet_obj.id)
except (exception.InternalError, exception.Error) as ex:
LOG.exception('Failed in creating lb pool member: %s.', ex)
return None


+ 3
- 2
senlin/drivers/os/octavia_v2.py View File

@ -119,10 +119,11 @@ class OctaviaClient(base.DriverBase):
return
@sdk.translate_exception
def pool_member_create(self, pool_id, address, protocol_port, subnet_id,
weight=None, admin_state_up=True):
def pool_member_create(self, name, pool_id, address, protocol_port,
subnet_id, weight=None, admin_state_up=True):
kwargs = {
'name': name,
'address': address,
'protocol_port': protocol_port,
'admin_state_up': admin_state_up,


+ 3
- 2
senlin/tests/drivers/os_test/octavia_v2.py View File

@ -187,9 +187,10 @@ class OctaviaClient(base.DriverBase):
def pool_delete(self, pool_id, ignore_missing=True):
return
def pool_member_create(self, pool_id, address, protocol_port, subnet_id,
weight=None, admin_state_up=True):
def pool_member_create(self, name, pool_id, address, protocol_port,
subnet_id, weight=None, admin_state_up=True):
# pool_id is ignored
self.fake_member["name"] = name
self.fake_member["address"] = address
self.fake_member["protocol_port"] = protocol_port
self.fake_member["subnet_id"] = subnet_id


+ 2
- 1
senlin/tests/unit/drivers/test_lbaas.py View File

@ -523,6 +523,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
'network2': [{'addr': 'ipaddr_net2', 'version': '4'}]
}
}
name = node_detail.get('name')
mock_pb_load.return_value.do_get_details.return_value = node_detail
self.nc.subnet_get.return_value = subnet_obj
@ -537,7 +538,7 @@ class TestOctaviaLBaaSDriver(base.SenlinTestCase):
self.nc.network_get.assert_called_once_with('NETWORK_ID')
# Make sure the ip matches with subnet ip_version
self.oc.pool_member_create.assert_called_once_with(
pool_id, 'ipaddr2_net1', port, 'SUBNET_ID')
name, pool_id, 'ipaddr2_net1', port, 'SUBNET_ID')
self.lb_driver._wait_for_lb_ready.assert_has_calls(
[mock.call('LB_ID'), mock.call('LB_ID')])


+ 5
- 4
senlin/tests/unit/drivers/test_octavia_v2.py View File

@ -167,6 +167,7 @@ class TestOctaviaV2Driver(base.SenlinTestCase):
pool_id, ignore_missing=True)
def test_pool_member_create(self):
name = 'web-server-1'
pool_id = 'ID1'
address = '192.168.1.100'
protocol_port = 80
@ -182,9 +183,9 @@ class TestOctaviaV2Driver(base.SenlinTestCase):
self.conn.load_balancer.create_member.return_value = member_obj
self.assertEqual(member_obj, self.oc.pool_member_create(
pool_id, address, protocol_port, subnet_id, **kwargs))
name, pool_id, address, protocol_port, subnet_id, **kwargs))
self.conn.load_balancer.create_member.assert_called_once_with(
pool_id, address=address, protocol_port=protocol_port,
pool_id, name=name, address=address, protocol_port=protocol_port,
subnet_id=subnet_id, **kwargs)
# Use default input parameters
@ -192,9 +193,9 @@ class TestOctaviaV2Driver(base.SenlinTestCase):
'admin_state_up': True
}
self.assertEqual(member_obj, self.oc.pool_member_create(
pool_id, address, protocol_port, subnet_id))
name, pool_id, address, protocol_port, subnet_id))
self.conn.load_balancer.create_member.assert_called_with(
pool_id, address=address, protocol_port=protocol_port,
pool_id, name=name, address=address, protocol_port=protocol_port,
subnet_id=subnet_id, **kwargs)
def test_pool_member_delete(self):


Loading…
Cancel
Save