def lock_machines(job_config):
report.try_push_job_info(job_config, dict(status='running'))
fake_ctx = supervisor.create_fake_context(job_config, block=True)
- block_and_lock_machines(fake_ctx, len(job_config['roles']),
- job_config['machine_type'], reimage=False)
+ block_and_lock_machines(
+ fake_ctx,
+ len(job_config['roles']),
+ job_config['machine_type'],
+ tries=-1,
+ reimage=False,
+ )
job_config = fake_ctx.config
return job_config
return reimaged
-def block_and_lock_machines(ctx, total_requested, machine_type, reimage=True):
+def block_and_lock_machines(ctx, total_requested, machine_type, reimage=True, tries=10):
# It's OK for os_type and os_version to be None here. If we're trying
# to lock a bare metal machine, we'll take whatever is available. If
# we want a vps, defaults will be provided by misc.get_distro and
requested = total_requested
while True:
# get a candidate list of machines
- machines = query.list_locks(machine_type=machine_type, up=True,
- locked=False, count=requested + reserved)
+ machines = query.list_locks(
+ machine_type=machine_type,
+ up=True,
+ locked=False,
+ count=requested + reserved,
+ tries=tries,
+ )
if machines is None:
if ctx.block:
log.error('Error listing machines, trying again')
return status.get('is_vm', False)
-def list_locks(keyed_by_name=False, **kwargs):
+def list_locks(keyed_by_name=False, tries=10, **kwargs):
uri = os.path.join(config.lock_server, 'nodes', '')
for key, value in kwargs.items():
if kwargs[key] is False:
kwargs['machine_type'] = kwargs['machine_type'].replace(',','|')
uri += '?' + urlencode(kwargs)
with safe_while(
- sleep=1, increment=0.5, action='list_locks') as proceed:
+ sleep=1,
+ increment=0.5,
+ tries=-1,
+ action='list_locks'
+ ) as proceed:
while proceed():
try:
response = requests.get(uri)