revise lb-policy (1)
this patch revises lb-policy to use runtime data instead of querying from DB. Change-Id: I861c0a1bbd8bc36e70a26c67051aba22f2ad9840
This commit is contained in:
parent
4cc92256f9
commit
5188eeaa49
|
@ -28,7 +28,6 @@ from senlin.common.i18n import _
|
|||
from senlin.common import scaleutils
|
||||
from senlin.common import schema
|
||||
from senlin.engine import cluster_policy
|
||||
from senlin.engine import node as nm
|
||||
from senlin.objects import cluster as co
|
||||
from senlin.objects import node as no
|
||||
from senlin.policies import base
|
||||
|
@ -316,9 +315,6 @@ class LoadBalancingPolicy(base.Policy):
|
|||
if res is False:
|
||||
return False, data
|
||||
|
||||
nodes = nm.Node.load_all(oslo_context.get_current(),
|
||||
cluster_id=cluster.id)
|
||||
|
||||
lb_driver = self.lbaas(cluster.user, cluster.project)
|
||||
lb_driver.lb_status_timeout = self.lb_status_timeout
|
||||
|
||||
|
@ -333,7 +329,7 @@ class LoadBalancingPolicy(base.Policy):
|
|||
port = self.pool_spec.get(self.POOL_PROTOCOL_PORT)
|
||||
subnet = self.pool_spec.get(self.POOL_SUBNET)
|
||||
|
||||
for node in nodes:
|
||||
for node in cluster.nodes:
|
||||
member_id = lb_driver.member_add(node, data['loadbalancer'],
|
||||
data['pool'], port, subnet)
|
||||
if member_id is None:
|
||||
|
@ -345,7 +341,8 @@ class LoadBalancingPolicy(base.Policy):
|
|||
return False, 'Failed in adding node into lb pool'
|
||||
|
||||
node.data.update({'lb_member': member_id})
|
||||
node.store(oslo_context.get_current())
|
||||
values = {'data': node.data}
|
||||
no.Node.update(oslo_context.get_current(), node.id, values)
|
||||
|
||||
cluster_data_lb = cluster.data.get('loadbalancers', {})
|
||||
cluster_data_lb[self.id] = {'vip_address': data.pop('vip_address')}
|
||||
|
@ -379,12 +376,11 @@ class LoadBalancingPolicy(base.Policy):
|
|||
if res is False:
|
||||
return False, reason
|
||||
|
||||
nodes = nm.Node.load_all(oslo_context.get_current(),
|
||||
cluster_id=cluster.id, project_safe=False)
|
||||
for node in nodes:
|
||||
for node in cluster.nodes:
|
||||
if 'lb_member' in node.data:
|
||||
node.data.pop('lb_member')
|
||||
node.store(oslo_context.get_current())
|
||||
values = {'data': node.data}
|
||||
no.Node.update(oslo_context.get_current(), node.id, values)
|
||||
|
||||
lb_data = cluster.data.get('loadbalancers', {})
|
||||
if lb_data and isinstance(lb_data, dict):
|
||||
|
|
|
@ -19,7 +19,6 @@ from senlin.common import exception as exc
|
|||
from senlin.common import scaleutils
|
||||
from senlin.drivers import base as driver_base
|
||||
from senlin.engine import cluster_policy
|
||||
from senlin.engine import node as node_mod
|
||||
from senlin.objects import cluster as co
|
||||
from senlin.objects import node as no
|
||||
from senlin.policies import base as policy_base
|
||||
|
@ -176,14 +175,14 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
"be found.", six.text_type(ex))
|
||||
|
||||
@mock.patch.object(lb_policy.LoadBalancingPolicy, '_build_policy_data')
|
||||
@mock.patch.object(node_mod.Node, 'load_all')
|
||||
@mock.patch.object(policy_base.Policy, 'attach')
|
||||
def test_attach_succeeded(self, m_attach, m_load, m_build):
|
||||
@mock.patch.object(no.Node, 'update')
|
||||
def test_attach_succeeded(self, m_update, m_attach, m_build):
|
||||
cluster = mock.Mock(id='CLUSTER_ID', data={})
|
||||
node1 = mock.Mock()
|
||||
node2 = mock.Mock()
|
||||
node1 = mock.Mock(id='fake1', data={})
|
||||
node2 = mock.Mock(id='fake2', data={})
|
||||
cluster.nodes = [node1, node2]
|
||||
m_attach.return_value = (True, None)
|
||||
m_load.return_value = [node1, node2]
|
||||
m_build.return_value = 'policy_data'
|
||||
data = {
|
||||
'loadbalancer': 'LB_ID',
|
||||
|
@ -204,16 +203,18 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
self.lb_driver.lb_create.assert_called_once_with(policy.vip_spec,
|
||||
policy.pool_spec,
|
||||
policy.hm_spec)
|
||||
m_load.assert_called_once_with(mock.ANY, cluster_id=cluster.id)
|
||||
member_add_calls = [
|
||||
mock.call(node1, 'LB_ID', 'POOL_ID', 80, 'internal-subnet'),
|
||||
mock.call(node2, 'LB_ID', 'POOL_ID', 80, 'internal-subnet')
|
||||
]
|
||||
self.lb_driver.member_add.assert_has_calls(member_add_calls)
|
||||
node1.data.update.assert_called_once_with({'lb_member': 'MEMBER1_ID'})
|
||||
node2.data.update.assert_called_once_with({'lb_member': 'MEMBER2_ID'})
|
||||
node1.store.assert_called_once_with(mock.ANY)
|
||||
node2.store.assert_called_once_with(mock.ANY)
|
||||
node_update_calls = [
|
||||
mock.call(mock.ANY, node1.id,
|
||||
{'data': {'lb_member': 'MEMBER1_ID'}}),
|
||||
mock.call(mock.ANY, node2.id,
|
||||
{'data': {'lb_member': 'MEMBER2_ID'}})
|
||||
]
|
||||
m_update.assert_has_calls(node_update_calls)
|
||||
expected = {
|
||||
policy.id: {'vip_address': '192.168.1.100'}
|
||||
}
|
||||
|
@ -230,9 +231,8 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
self.assertFalse(res)
|
||||
self.assertEqual('data', data)
|
||||
|
||||
@mock.patch.object(node_mod.Node, 'load_all')
|
||||
@mock.patch.object(policy_base.Policy, 'attach')
|
||||
def test_attach_failed_lb_creation_error(self, m_attach, m_load):
|
||||
def test_attach_failed_lb_creation_error(self, m_attach):
|
||||
cluster = mock.Mock()
|
||||
m_attach.return_value = (True, None)
|
||||
|
||||
|
@ -244,12 +244,11 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
res = policy.attach(cluster)
|
||||
self.assertEqual((False, 'error'), res)
|
||||
|
||||
@mock.patch.object(node_mod.Node, 'load_all')
|
||||
@mock.patch.object(policy_base.Policy, 'attach')
|
||||
def test_attach_failed_member_add(self, mock_attach, mock_load):
|
||||
def test_attach_failed_member_add(self, mock_attach):
|
||||
cluster = mock.Mock()
|
||||
cluster.nodes = [mock.Mock(id='fake1'), mock.Mock(id='fake2')]
|
||||
mock_attach.return_value = (True, None)
|
||||
mock_load.return_value = ['node1', 'node2']
|
||||
lb_data = {
|
||||
'loadbalancer': 'LB_ID',
|
||||
'vip_address': '192.168.1.100',
|
||||
|
@ -530,6 +529,8 @@ class TestLoadBalancingPolicyOperations(base.SenlinTestCase):
|
|||
|
||||
}
|
||||
})
|
||||
node = mock.Mock(id='fake', data={})
|
||||
cluster.nodes = [node]
|
||||
|
||||
res, data = policy.detach(cluster)
|
||||
|
||||
|
|
Loading…
Reference in New Issue