]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
port the argument parsing for teuthology.run to docopt
authorAndrew Schoen <aschoen@redhat.com>
Thu, 20 Nov 2014 20:53:14 +0000 (14:53 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Sat, 6 Dec 2014 19:46:47 +0000 (13:46 -0600)
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
scripts/run.py
scripts/test/test_run.py

index f748f47d73f45b3d9fce0e804cfe0943ed38e627..cf857ec8b6b97dec4873b8f27c6871ec79c861ae 100644 (file)
@@ -1,83 +1,35 @@
-import argparse
+"""
+usage: teuthology --help
+       teuthology --version
+       teuthology [options] <config>...
 
-import teuthology.misc
-import teuthology.run
+Run ceph integration tests
 
+positional arguments:
+  <config> one or more config files to read
 
-def main():
-    teuthology.run.main(parse_args())
+optional arguments:
+  -h, --help                     show this help message and exit
+  -v, --verbose                  be more verbose
+  --version                      the current installed version of teuthology
+  -a DIR, --archive DIR          path to archive results in
+  --description DESCRIPTION      job description
+  --owner OWNER                  job owner
+  --lock                         lock machines for the duration of the run
+  --machine-type MACHINE_TYPE    Type of machine to lock/run tests on.
+  --os-type OS_TYPE              Distro/OS of machine to run test on [default: ubuntu].
+  --os-version OS_VERSION        Distro/OS version of machine to run test on.
+  --block                        block until locking machines succeeds (use with
+                                 --lock)
+  --name NAME                    name for this teuthology run
+  --suite-path SUITE_PATH        Location of ceph-qa-suite on disk. If not specified,
+                                 it will be fetched
+"""
+import docopt
 
+import teuthology.run
 
-def parse_args():
-    parser = argparse.ArgumentParser(description='Run ceph integration tests')
-    parser.add_argument(
-        '-v', '--verbose',
-        action='store_true', default=None,
-        help='be more verbose',
-    )
-    parser.add_argument(
-        '--version',
-        action='version',
-        version='%s' % teuthology.__version__,
-        help='the current installed version of teuthology',
-        )
-    parser.add_argument(
-        'config',
-        metavar='CONFFILE',
-        nargs='+',
-        type=teuthology.misc.config_file,
-        action=teuthology.misc.MergeConfig,
-        default={},
-        help='config file to read',
-    )
-    parser.add_argument(
-        '-a', '--archive',
-        metavar='DIR',
-        help='path to archive results in',
-    )
-    parser.add_argument(
-        '--description',
-        help='job description',
-    )
-    parser.add_argument(
-        '--owner',
-        help='job owner',
-    )
-    parser.add_argument(
-        '--lock',
-        action='store_true',
-        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(
-        '--os-type',
-        default='ubuntu',
-        help='Distro/OS of machine to run test on.',
-    )
-    parser.add_argument(
-        '--os-version',
-        default=None,
-        help='Distro/OS version of machine to run test on.',
-    )
-    parser.add_argument(
-        '--block',
-        action='store_true',
-        default=False,
-        help='block until locking machines succeeds (use with --lock)',
-    )
-    parser.add_argument(
-        '--name',
-        metavar='NAME',
-        help='name for this teuthology run',
-    )
-    parser.add_argument(
-        '--suite-path',
-        help='Location of ceph-qa-suite on disk. If not specified, it will be fetched',  # noqa
-    )
 
-    return parser.parse_args()
+def main():
+    args = docopt.docopt(__doc__, version=teuthology.__version__)
+    teuthology.run.main(args)
index 36d42c37d8072b2115e58e9cc7ce8bec548d36d3..f13345172b010fb82e5294cb253d3aaf5c0c1b12 100644 (file)
@@ -1,5 +1,47 @@
+import docopt
+
 from script import Script
+from scripts import run
+
+doc = run.__doc__
 
 
 class TestRun(Script):
     script_name = 'teuthology'
+
+    def test_all_args(self):
+        args = docopt.docopt(doc, [
+            "--verbose",
+            "--archive", "some/archive/dir",
+            "--description", "the_description",
+            "--owner", "the_owner",
+            "--lock",
+            "--machine-type", "machine_type",
+            "--os-type", "os_type",
+            "--os-version", "os_version",
+            "--block",
+            "--name", "the_name",
+            "--suite-path", "some/suite/dir",
+            "path/to/config.yml",
+        ])
+        assert args["--verbose"]
+        assert args["--archive"] == "some/archive/dir"
+        assert args["--description"] == "the_description"
+        assert args["--owner"] == "the_owner"
+        assert args["--lock"]
+        assert args["--machine-type"] == "machine_type"
+        assert args["--os-type"] == "os_type"
+        assert args["--os-version"] == "os_version"
+        assert args["--block"]
+        assert args["--name"] == "the_name"
+        assert args["--suite-path"] == "some/suite/dir"
+        assert args["<config>"] == ["path/to/config.yml"]
+
+    def test_multiple_configs(self):
+        args = docopt.docopt(doc, [
+            "config1.yml",
+            "config2.yml",
+        ])
+        assert args["<config>"] == ["config1.yml", "config2.yml"]
+        # make sure defaults are working
+        assert args["--os-type"] == "ubuntu"