PR#4358: Fix min_avail calculation
Merges #4358 https://pagure.io/koji/pull-request/4358 Fixes: #4359 https://pagure.io/koji/issue/4359 Fix min_avail calculation
This commit is contained in:
commit
4729cf8687
2 changed files with 19 additions and 2 deletions
|
|
@ -377,7 +377,7 @@ class TaskScheduler(object):
|
|||
refusals = self.get_refusals()
|
||||
for task in self.free_tasks:
|
||||
task['_hosts'] = []
|
||||
min_avail = min(0, task['weight'] - self.capacity_overcommit)
|
||||
min_avail = max(0, task['weight'] - self.capacity_overcommit)
|
||||
h_refused = refusals.get(task['task_id'], {})
|
||||
for host in self.hosts_by_bin.get(task['_bin'], []):
|
||||
if (host['ready'] and
|
||||
|
|
@ -402,7 +402,7 @@ class TaskScheduler(object):
|
|||
|
||||
# tasks are already in priority order
|
||||
for task in self.free_tasks:
|
||||
min_avail = task['weight'] - self.capacity_overcommit
|
||||
min_avail = max(0, task['weight'] - self.capacity_overcommit)
|
||||
task['_hosts'].sort(key=lambda h: h['_rank'])
|
||||
logger.debug('Task %i choices: %s', task['task_id'],
|
||||
[(h['name'], "%(_rank).2f" % h) for h in task['_hosts']])
|
||||
|
|
|
|||
|
|
@ -222,6 +222,23 @@ class TestDoSchedule(BaseTest):
|
|||
self.assertEqual(t_assigned, list(range(5)))
|
||||
self.assertEqual(h_used, list(range(5)))
|
||||
|
||||
def test_stop_at_capacity(self):
|
||||
# just one host
|
||||
host = self.mkhost(id=1, capacity=5.0)
|
||||
self.sched._get_hosts.return_value = [host]
|
||||
self.sched.get_hosts()
|
||||
# and more tasks than will fit
|
||||
self.sched.free_tasks = [self.mktask(task_id=n, weight=1.0) for n in range(10)]
|
||||
|
||||
self.sched.do_schedule()
|
||||
|
||||
# 5 tasks with weight=1.0 should fill up capacity
|
||||
# (overcommit only applies for a single task going over)
|
||||
self.assertEqual(len(self.assigns), 5)
|
||||
t_assigned = [t['task_id'] for t, h in self.assigns]
|
||||
t_assigned.sort()
|
||||
self.assertEqual(t_assigned, list(range(5)))
|
||||
|
||||
def test_active_tasks(self):
|
||||
self.context.opts['CapacityOvercommit'] = 1.0
|
||||
hosts = [self.mkhost(id=n, capacity=2.0) for n in range(5)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue