]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Port to docopt
authorZack Cerza <zack@redhat.com>
Wed, 10 Dec 2014 20:16:23 +0000 (13:16 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 12 Dec 2014 18:34:22 +0000 (11:34 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
scripts/nuke.py
teuthology/nuke.py

index aa9f91d86102567d7fa7c9f5e1a1aa724af6ba32..0c2d4550675fbdee6ba39a744943e7132a12884f 100644 (file)
@@ -1,81 +1,37 @@
-import argparse
-from argparse import RawTextHelpFormatter
-import textwrap
+import docopt
 
-import teuthology.misc
 import teuthology.nuke
 
+doc = """
+usage: teuthology-nuke --help
+       teuthology-nuke [-v] [--owner OWNER] [-n NAME] [-u] [-i] [-r] [-s]
+                            [-t CONFIG...] [-a DIR] [-p PID]
+       teuthology-nuke [-v] [-u] [-i] [-r] [-s] --owner OWNER --stale
 
-def main():
-    teuthology.nuke.main(parse_args())
+Reset test machines
+
+optional arguments:
+  -h, --help            show this help message and exit
+  -v, --verbose         be more verbose
+  -t CONFIG [CONFIG ...], --targets CONFIG [CONFIG ...]
+                        yaml config containing machines to nuke
+  -a DIR, --archive DIR
+                        archive path for a job to kill and nuke
+  --owner OWNER         job owner
+  -p PID, --pid PID     pid of the process to be killed
+  -r, --reboot-all      reboot all machines
+  -s, --synch-clocks    synchronize clocks on all machines
+  -u, --unlock          Unlock each successfully nuked machine, and output
+                        targets thatcould not be nuked.
+  -n NAME, --name NAME  Name of run to cleanup
+  -i, --noipmi          Skip ipmi checking
 
+Examples:
+teuthology-nuke -t target.yaml --unlock --owner user@host
+teuthology-nuke -t target.yaml --pid 1234 --unlock --owner user@host
+"""
 
-def parse_args():
-    parser = argparse.ArgumentParser(
-        description='Reset test machines',
-        epilog=textwrap.dedent('''
-        Examples:
-        teuthology-nuke -t target.yaml --unlock --owner user@host
-        teuthology-nuke -t target.yaml --pid 1234 --unlock --owner user@host \n
-        '''),
-        formatter_class=RawTextHelpFormatter)
-    parser.add_argument(
-        '-v', '--verbose',
-        action='store_true', default=None,
-        help='be more verbose'
-    )
-    parser.add_argument(
-        '-t', '--targets',
-        nargs='+',
-        type=teuthology.misc.config_file,
-        action=teuthology.misc.MergeConfig,
-        default={},
-        dest='config',
-        help='yaml config containing machines to nuke',
-    )
-    parser.add_argument(
-        '-a', '--archive',
-        metavar='DIR',
-        help='archive path for a job to kill and nuke',
-    )
-    parser.add_argument(
-        '--owner',
-        help='job owner',
-    )
-    parser.add_argument(
-        '-p',
-        '--pid',
-        type=int,
-        default=False,
-        help='pid of the process to be killed',
-    )
-    parser.add_argument(
-        '-r', '--reboot-all',
-        action='store_true',
-        default=False,
-        help='reboot all machines',
-    )
-    parser.add_argument(
-        '-s', '--synch-clocks',
-        action='store_true',
-        default=False,
-        help='synchronize clocks on all machines',
-    )
-    parser.add_argument(
-        '-u', '--unlock',
-        action='store_true',
-        default=False,
-        help='Unlock each successfully nuked machine, and output targets that'
-        'could not be nuked.'
-    )
-    parser.add_argument(
-        '-n', '--name',
-        metavar='NAME',
-        help='Name of run to cleanup'
-    )
-    parser.add_argument(
-        '-i', '--noipmi',
-        action='store_true', default=False,
-        help='Skip ipmi checking'
-    )
-    return parser.parse_args()
+
+def main():
+    args = docopt.docopt(doc)
+    teuthology.nuke.main(args)
index 0459a1796b2092bd665cf6ca545fe7d5a3d4f1c5..9d8284ce387450065613c11cbd0985aa8e06f2e6 100644 (file)
@@ -10,9 +10,11 @@ import teuthology
 from . import orchestra
 import orchestra.remote
 from .orchestra import run
+from .config import FakeNamespace
 from .lock import list_locks
 from .lock import unlock_one
 from .misc import config_file
+from .misc import merge_configs
 from .misc import get_testdir
 from .misc import get_user
 from .misc import read_config
@@ -336,7 +338,8 @@ def synch_clocks(remotes):
         proc.wait()
 
 
-def main(ctx):
+def main(args):
+    ctx = FakeNamespace(args)
     if ctx.verbose:
         teuthology.log.setLevel(logging.DEBUG)
 
@@ -356,6 +359,9 @@ def main(ctx):
             if not ctx.owner:
                 ctx.owner = open(ctx.archive + '/owner').read().rstrip('\n')
 
+    if ctx.targets:
+        ctx.config = merge_configs(ctx.targets)
+
     read_config(ctx)
 
     log.info(