Skip to content

Commit 2c50ac4

Browse files
Merge pull request #1043 from zhaoqin-github/schedule
Do not evaluate tenant affinity when schedule agent
2 parents a958dcb + ea7eaa9 commit 2c50ac4

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

f5lbaasdriver/v2/bigip/agent_scheduler.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,19 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
265265
if group_capacity > capacity_by_group[gn]:
266266
capacity_by_group[gn] = group_capacity
267267

268+
# ---------------------------------------------------------
269+
# NOTE(qzhao): Skip to evaluate tenant affinity, because it
270+
# cost much time to load loadbalancers from neutron db.
271+
# ---------------------------------------------------------
268272
# Do we already have this tenant assigned to this
269273
# agent candidate? If we do and it has capacity
270274
# then assign this loadbalancer to this agent.
271-
assigned_lbs = plugin.db.list_loadbalancers_on_lbaas_agent(
272-
context, candidate['id'])
273-
for assigned_lb in assigned_lbs:
274-
if loadbalancer.tenant_id == assigned_lb.tenant_id:
275-
chosen_agent = candidate
276-
break
275+
# assigned_lbs = plugin.db.list_loadbalancers_on_lbaas_agent(
276+
# context, candidate['id'])
277+
# for assigned_lb in assigned_lbs:
278+
# if loadbalancer.tenant_id == assigned_lb.tenant_id:
279+
# chosen_agent = candidate
280+
# break
277281

278282
if chosen_agent:
279283
# Does the agent which had tenants assigned
@@ -417,15 +421,21 @@ def schedule(self, plugin, context, loadbalancer_id, env=None):
417421
else:
418422
if group_capacity > capacity_by_group[gn]:
419423
capacity_by_group[gn] = group_capacity
424+
425+
# ---------------------------------------------------------
426+
# NOTE(qzhao): Skip to evaluate tenant affinity, because it
427+
# cost much time to load loadbalancers from neutron db.
428+
# ---------------------------------------------------------
420429
# Do we already have this tenant assigned to this
421430
# agent candidate? If we do and it has capacity
422431
# then assign this loadbalancer to this agent.
423-
assigned_lbs = plugin.db.list_loadbalancers_on_lbaas_agent(
424-
context, candidate['id'])
425-
for assigned_lb in assigned_lbs:
426-
if loadbalancer.tenant_id == assigned_lb.tenant_id:
427-
chosen_agent = candidate
428-
break
432+
# assigned_lbs = plugin.db.list_loadbalancers_on_lbaas_agent(
433+
# context, candidate['id'])
434+
# for assigned_lb in assigned_lbs:
435+
# if loadbalancer.tenant_id == assigned_lb.tenant_id:
436+
# chosen_agent = candidate
437+
# break
438+
429439
if chosen_agent:
430440
# Does the agent which had tenants assigned
431441
# to it still have capacity?

f5lbaasdriver/v2/bigip/test/test_agent_scheduler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,15 @@ def test_schedule_already_assigned_agent():
416416
'{"environment_prefix": "Project", \
417417
"environment_group_number": 4, \
418418
"environment_capacity_score": 1.5}'}
419-
agent2_conf = {'id': 34, 'configurations':
419+
agent2_conf = {'id': 35, 'configurations':
420420
'{"environment_prefix": "Project", \
421421
"environment_group_number": 4, \
422422
"environment_capacity_score": 0.8}'}
423423
mock_plugin.db.get_lbaas_agents.return_value = [agent1_conf, agent2_conf]
424424
mock_ctx = mock.MagicMock(name='context')
425425
sched = agent_scheduler.TenantScheduler()
426426
sched.get_lbaas_agent_hosting_loadbalancer = mock.MagicMock(
427-
name='get_lbaas_agent_hosting_loadbalancer', return_value=None)
427+
name='get_lbaas_agent_hosting_loadbalancer',
428+
return_value={'agent': {'id': 35}})
428429
res = sched.schedule(mock_plugin, mock_ctx, 'test_lb_id', 'Project')
429-
assert res == agent2_conf
430+
assert res['id'] == agent2_conf['id']

0 commit comments

Comments
 (0)