Use a workaround to make lb_policy work
'project' and 'trust' field can not be defined in RequestContext at the same time. However, 'project' field is needed for building DB session. Therefore, before we rework context related design, we temporarily use a workaround to make lb_policy work. Change-Id: Ia326e6f3eee8ad1dacfc8cc74744de3bacb2afe1
This commit is contained in:
parent
90e5715f5d
commit
983de20a5b
|
@ -204,6 +204,9 @@ class LoadBalancingPolicy(base.Policy):
|
|||
if res is False:
|
||||
return False, data
|
||||
|
||||
nodes = node_mod.Node.load_all(oslo_context.get_current(),
|
||||
cluster_id=cluster.id)
|
||||
|
||||
ctx = self._build_context(cluster)
|
||||
lb_driver = driver_base.SenlinDriver().loadbalancing(ctx)
|
||||
|
||||
|
@ -215,8 +218,6 @@ class LoadBalancingPolicy(base.Policy):
|
|||
port = self.pool_spec.get(self.POOL_PROTOCOL_PORT)
|
||||
subnet = self.pool_spec.get(self.POOL_SUBNET)
|
||||
|
||||
nodes = node_mod.Node.load_all(oslo_context.get_current(),
|
||||
cluster_id=cluster.id)
|
||||
for node in nodes:
|
||||
member_id = lb_driver.member_add(node, data['loadbalancer'],
|
||||
data['pool'], port, subnet)
|
||||
|
@ -351,6 +352,5 @@ class LoadBalancingPolicy(base.Policy):
|
|||
if cred is None:
|
||||
raise exception.TrustNotFound(trustor=cluster.user)
|
||||
params['trusts'] = [cred.cred['openstack']['trust']]
|
||||
params['project_id'] = cluster.project
|
||||
|
||||
return context.RequestContext.from_dict(params)
|
||||
|
|
|
@ -170,7 +170,6 @@ class TestLoadBalancingPolicy(base.SenlinTestCase):
|
|||
'user_domain_name': service_ctx['user_domain_name'],
|
||||
'password': service_ctx['password'],
|
||||
'trusts': [cred_info['openstack']['trust']],
|
||||
'project_id': cluster.project
|
||||
}
|
||||
mock_from_dict.assert_called_once_with(params)
|
||||
|
||||
|
@ -260,10 +259,12 @@ 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')
|
||||
@mock.patch.object(driver_base, 'SenlinDriver')
|
||||
def test_lb_policy_attach_failed_lb_creation_failed(
|
||||
self, mock_senlindriver, mock_policy_base_attach):
|
||||
self, mock_senlindriver, mock_policy_base_attach,
|
||||
mock_node_load_all):
|
||||
|
||||
sd = mock.Mock()
|
||||
lb_driver = mock.Mock()
|
||||
|
|
Loading…
Reference in New Issue