method, url, body, resp.status)
return (False, None, resp.status)
-def lock_many(ctx, num, user=None, description=None):
+def lock_many(ctx, num, machinetype, user=None, description=None):
if user is None:
user = teuthology.get_user()
success, content, status = send_request('POST', _lock_url(ctx),
- urllib.urlencode(dict(user=user, num=num)))
+ urllib.urlencode(dict(user=user, num=num, machinetype=machinetype)))
if success:
machines = json.loads(content)
log.debug('locked {machines}'.format(machines=', '.join(machines.keys())))
default=None,
help='update description',
)
+ parser.add_argument(
+ '--machine-type',
+ default='plana',
+ help='Type of machine to lock',
+ )
parser.add_argument(
'--status',
default=None,
else:
machines_to_update.append(machine)
elif ctx.num_to_lock:
- result = lock_many(ctx, ctx.num_to_lock, user)
+ result = lock_many(ctx, ctx.num_to_lock, ctx.machine_type, user)
if not result:
ret = 1
else:
def POST(self):
user = web.input('user')['user']
num = int(web.input('num')['num'])
+ machinetype = dict(machinetype=(web.input(machinetype='plana')['machinetype']))
if num < 1:
raise web.BadRequest()
try:
# transaction will be rolled back if an exception is raised
with DB.transaction():
- results = list(DB.select('machine', what='name, sshpubkey',
- where='locked = false AND up = true',
+ results = list(DB.select('machine', machinetype, what='name, sshpubkey',
+ where='locked = false AND up = true AND type =$machinetype',
limit=num))
if len(results) < num:
raise web.HTTPError(status='503 Service Unavailable')
CREATE TABLE machine (
name varchar(255),
+ type enum('burnupi','plana','vps') NOT NULL DEFAULT 'plana',
up boolean NOT NULL,
locked boolean NOT NULL,
locked_since timestamp NOT NULL DEFAULT '0000-00-00T00:00:00',
default=False,
help='lock machines for the duration of the run',
)
+ parser.add_argument(
+ '--machine-type',
+ default=None,
+ help='Type of machine to lock/run tests on.',
+ )
parser.add_argument(
'--block',
action='store_true',
roles = len(ctx.config['roles'])
assert targets >= roles, \
'%d targets are needed for all roles but found %d listed.' % (roles, targets)
-
+
+ machine_type = ctx.machine_type
+ if machine_type is None:
+ machine_type = ctx.config.get('machine_type', 'plana')
+
if ctx.block:
assert ctx.lock, \
'the --block option is only supported with the --lock option'
if ctx.lock:
assert 'targets' not in ctx.config, \
'You cannot specify targets in a config file when using the --lock option'
- init_tasks.append({'internal.lock_machines': len(ctx.config['roles'])})
+ init_tasks.append({'internal.lock_machines': (len(ctx.config['roles']), machine_type)})
init_tasks.extend([
{'internal.save_config': None},
@contextlib.contextmanager
def lock_machines(ctx, config):
log.info('Locking machines...')
- assert isinstance(config, int), 'config must be an integer'
+ assert isinstance(config[0], int), 'config must be an integer'
+ machine_type = config[1]
+ config = config[0]
while True:
# make sure there are enough machines up
continue
else:
assert 0, 'error listing machines'
- num_up = len(filter(lambda machine: machine['up'], machines))
+ num_up = len(filter(lambda machine: machine['up'] and machine['type'] == machine_type, machines))
+ print num_up
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['up'] and machine['locked'] == 0,
+ lambda machine: machine['up'] and machine['locked'] == 0 and machine['type'] == machine_type,
machines
))
if num_free < 6 and ctx.owner.startswith('scheduled'):
else:
assert 0, 'not enough machines free'
- newly_locked = lock.lock_many(ctx, config, ctx.owner, ctx.archive)
+ newly_locked = lock.lock_many(ctx, config, machine_type, ctx.owner, ctx.archive)
if len(newly_locked) == config:
ctx.config['targets'] = newly_locked
log.info('\n '.join(['Locked targets:', ] + yaml.safe_dump(ctx.config['targets'], default_flow_style=False).splitlines()))