]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
task/workunit: general tidy
authorJohn Spray <jspray@redhat.com>
Fri, 18 Jul 2014 16:15:20 +0000 (17:15 +0100)
committerJohn Spray <jspray@redhat.com>
Fri, 25 Jul 2014 12:33:31 +0000 (13:33 +0100)
* PEP8-ize whitespace
* specialize a catch-all except:
* don't alias 'misc' to 'teuthology'

Signed-off-by: John Spray <john.spray@redhat.com>
teuthology/task/workunit.py

index 183b85601102b39c38873d715505e8e8ffd3e219..b84d5d4498bfd7cd0ae9e730e19df32d5afe402f 100644 (file)
@@ -5,15 +5,15 @@ import logging
 import pipes
 import os
 
-from teuthology import misc as teuthology
+from teuthology import misc
+from teuthology.orchestra.run import CommandFailedError
 from teuthology.parallel import parallel
 from ..orchestra import run
 
 log = logging.getLogger(__name__)
 
-
 CLIENT_PREFIX = 'client.'
-        
+
 
 def task(ctx, config):
     """
@@ -66,7 +66,7 @@ def task(ctx, config):
         'configuration must contain a dictionary of clients'
 
     overrides = ctx.config.get('overrides', {})
-    teuthology.deep_merge(config, overrides.get('workunit', {}))
+    misc.deep_merge(config, overrides.get('workunit', {}))
 
     refspec = config.get('branch')
     if refspec is None:
@@ -123,7 +123,7 @@ def _delete_dir(ctx, role, created_mountpoint):
     :param ctx: Context
     :param role: "role.#" where # is used for the role id.
     """
-    testdir = teuthology.get_testdir(ctx)
+    testdir = misc.get_testdir(ctx)
     id_ = role[len(CLIENT_PREFIX):]
     (remote,) = ctx.cluster.only(role).remotes.iterkeys()
     mnt = os.path.join(testdir, 'mnt.{id}'.format(id=id_))
@@ -167,7 +167,7 @@ def _make_scratch_dir(ctx, role, subdir):
     log.debug("getting remote for {id} role {role_}".format(id=id_, role_=role))
     (remote,) = ctx.cluster.only(role).remotes.iterkeys()
     dir_owner = remote.user
-    mnt = os.path.join(teuthology.get_testdir(ctx), 'mnt.{id}'.format(id=id_))
+    mnt = os.path.join(misc.get_testdir(ctx), 'mnt.{id}'.format(id=id_))
     # if neither kclient nor ceph-fuse are required for a workunit,
     # mnt may not exist. Stat and create the directory if it doesn't.
     try:
@@ -176,17 +176,17 @@ def _make_scratch_dir(ctx, role, subdir):
                 'stat',
                 '--',
                 mnt,
-                ],
-            )
+            ],
+        )
         log.info('Did not need to create dir {dir}'.format(dir=mnt))
-    except Exception:
+    except CommandFailedError:
         remote.run(
             args=[
                 'mkdir',
                 '--',
                 mnt,
-                ],
-            )
+            ],
+        )
         log.info('Created dir {dir}'.format(dir=mnt))
         created_mountpoint = True
 
@@ -203,8 +203,8 @@ def _make_scratch_dir(ctx, role, subdir):
                 'mkdir',
                 '--',
                 subdir,
-                ],
-            )
+            ],
+        )
     else:
         remote.run(
             args=[
@@ -222,8 +222,8 @@ def _make_scratch_dir(ctx, role, subdir):
                 '--owner={user}'.format(user=dir_owner),
                 '--',
                 subdir,
-                ],
-            )
+            ],
+        )
 
     return created_mountpoint
 
@@ -235,7 +235,7 @@ def _spawn_on_all_clients(ctx, refspec, tests, env, subdir, timeout=None):
 
     See run_tests() for parameter documentation.
     """
-    client_generator = teuthology.all_roles_of_type(ctx.cluster, 'client')
+    client_generator = misc.all_roles_of_type(ctx.cluster, 'client')
     client_remotes = list()
 
     created_mountpoint = {}
@@ -251,7 +251,7 @@ def _spawn_on_all_clients(ctx, refspec, tests, env, subdir, timeout=None):
                         timeout=timeout)
 
     # cleanup the generated client directories
-    client_generator = teuthology.all_roles_of_type(ctx.cluster, 'client')
+    client_generator = misc.all_roles_of_type(ctx.cluster, 'client')
     for client in client_generator:
         _delete_dir(ctx, 'client.{id}'.format(id=client), created_mountpoint[client])
 
@@ -274,7 +274,7 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
                     hours, or 'd' for days. If '0' or anything that evaluates
                     to False is passed, the 'timeout' command is not used.
     """
-    testdir = teuthology.get_testdir(ctx)
+    testdir = misc.get_testdir(ctx)
     assert isinstance(role, basestring)
     assert role.startswith(CLIENT_PREFIX)
     id_ = role[len(CLIENT_PREFIX):]
@@ -308,12 +308,12 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
             run.Raw('&&'),
             'find', '-executable', '-type', 'f', '-printf', r'%P\0'.format(srcdir=srcdir),
             run.Raw('>{tdir}/workunits.list'.format(tdir=testdir)),
-            ],
-        )
+        ],
+    )
 
-    workunits = sorted(teuthology.get_file(
-                            remote,
-                            '{tdir}/workunits.list'.format(tdir=testdir)).split('\0'))
+    workunits = sorted(misc.get_file(
+        remote,
+        '{tdir}/workunits.list'.format(tdir=testdir)).split('\0'))
     assert workunits
 
     try:
@@ -335,7 +335,7 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
                     run.Raw('CEPH_REF={ref}'.format(ref=refspec)),
                     run.Raw('TESTDIR="{tdir}"'.format(tdir=testdir)),
                     run.Raw('CEPH_ID="{id}"'.format(id=id_)),
-                    ]
+                ]
                 if env is not None:
                     for var, val in env.iteritems():
                         quoted_val = pipes.quote(val)
@@ -351,21 +351,21 @@ def _run_tests(ctx, refspec, role, tests, env, subdir=None, timeout=None):
                     '{srcdir}/{workunit}'.format(
                         srcdir=srcdir,
                         workunit=workunit,
-                        ),
-                    ])
+                    ),
+                ])
                 remote.run(
                     logger=log.getChild(role),
                     args=args,
-                    )
+                )
                 remote.run(
                     logger=log.getChild(role),
                     args=['sudo', 'rm', '-rf', '--', scratch_tmp],
-                    )
+                )
     finally:
-        log.info('Stopping %s on %s...', spec, role)
+        log.info('Stopping %s on %s...', tests, role)
         remote.run(
             logger=log.getChild(role),
             args=[
                 'rm', '-rf', '--', '{tdir}/workunits.list'.format(tdir=testdir), srcdir,
-                ],
-            )
+            ],
+        )