From 68e6f2b77ec21b3a8d31a48481408be0bf94bf0b Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 4 Aug 2011 18:32:57 -0700 Subject: [PATCH] Make scheduled tasks leave some machines free. --- teuthology/task/internal.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/teuthology/task/internal.py b/teuthology/task/internal.py index 65953754a418a..d5592ce2ef31f 100644 --- a/teuthology/task/internal.py +++ b/teuthology/task/internal.py @@ -51,6 +51,22 @@ def lock_machines(ctx, config): assert isinstance(config, int), 'config must be an integer' while True: + # make sure there are enough machines up + machines = lock.list_locks(ctx) + assert machines is not None, 'error listing machines' + num_up = len(filter(lambda machine: machine['up'], machines)) + assert num_up >= config, 'not enough machines are up' + + # make sure there are machines for non-automated jobs to run + num_free = len(filter(lambda machine: machine['locked'] == 0, machines)) + if num_free < 6 and ctx.owner.startswith('scheduled'): + if ctx.block: + log.info('waiting for more machines to be free...') + time.sleep(10) + continue + else: + assert 0, 'not enough machines free' + newly_locked = lock.lock_many(ctx, config, ctx.owner) if len(newly_locked) == config: ctx.config['targets'] = newly_locked @@ -59,12 +75,6 @@ def lock_machines(ctx, config): elif not ctx.block: assert 0, 'not enough machines are available' - # make sure there are enough machines up - machines = lock.list_locks(ctx) - assert machines is not None, 'error listing machines' - num_up = len(filter(lambda machine: machine['up'], machines)) - assert num_up >= config, 'not enough machines are up' - log.warn('Could not lock enough machines, waiting...') time.sleep(10) try: -- 2.39.5