]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Added support for multiple types of machines.
authorSandon Van Ness <sandon@inktank.com>
Tue, 5 Feb 2013 20:53:08 +0000 (12:53 -0800)
committerSandon Van Ness <sandon@inktank.com>
Thu, 7 Feb 2013 21:26:37 +0000 (13:26 -0800)
Added the ability to support multiple types of machines with
--machine-type added to teuthology-lock when used with --lock-many
or --machine-type with teuthology --lock (automated tests). It
defaults to 'plana' and the 'vps' type is currently unused but
should be in the future.

Signed-off-by: Sandon Van Ness <sandon@van-ness.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
teuthology/lock.py
teuthology/locker/api.py
teuthology/locker/config.py
teuthology/run.py
teuthology/task/internal.py

index e9f83127183bc7391d68320cd899ac9dba33bebc..0163c02008c6cd8ae79a92305d32bc63a4040a97 100644 (file)
@@ -24,11 +24,11 @@ def send_request(method, url, body=None, headers=None):
              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())))
@@ -180,6 +180,11 @@ Lock, unlock, or query lock status of machines.
         default=None,
         help='update description',
         )
+    parser.add_argument(
+        '--machine-type',
+        default='plana',
+        help='Type of machine to lock',
+        )
     parser.add_argument(
         '--status',
         default=None,
@@ -322,7 +327,7 @@ Lock, unlock, or query lock status of machines.
             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:
index 881e718594c5052b8c3240922b882fc9e6c6d3c6..4eac75b913fa126ca116454e4061364932d71ad0 100644 (file)
@@ -75,6 +75,7 @@ class Lock:
     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()
@@ -84,8 +85,8 @@ class Lock:
             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')
index 17453a2d954ed336e24a775945e156bf7970e6df..090e8a0b0f74a91b52675d151c6f2b94f529a871 100644 (file)
@@ -5,6 +5,7 @@ The schema can be created with::
 
     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',
index 6136b091ea7c99b56d9abc12fd61916f809be2e8..d9f3ea278f541791099c2bdeb17011d3e1cd588a 100644 (file)
@@ -55,6 +55,11 @@ def parse_args():
         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',
@@ -93,7 +98,11 @@ def main():
         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'
@@ -143,7 +152,7 @@ def main():
     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},
index 0503eb13473424c46681c55eb80aa9865cdbdb66..cbbb87c48ca28112cd0f81af4af90fdb1a8a2a8f 100644 (file)
@@ -60,7 +60,9 @@ def base(ctx, config):
 @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
@@ -72,12 +74,13 @@ def lock_machines(ctx, config):
                 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'):
@@ -88,7 +91,7 @@ def lock_machines(ctx, config):
             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()))