From: Andrew Schoen Date: Thu, 20 Nov 2014 20:53:14 +0000 (-0600) Subject: port the argument parsing for teuthology.run to docopt X-Git-Tag: 1.1.0~1067^2~22^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fa35faa6abd4e45af0da93d86029936a121a5a51;p=teuthology.git port the argument parsing for teuthology.run to docopt Signed-off-by: Andrew Schoen --- diff --git a/scripts/run.py b/scripts/run.py index f748f47d7..cf857ec8b 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -1,83 +1,35 @@ -import argparse +""" +usage: teuthology --help + teuthology --version + teuthology [options] ... -import teuthology.misc -import teuthology.run +Run ceph integration tests +positional arguments: + 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) diff --git a/scripts/test/test_run.py b/scripts/test/test_run.py index 36d42c37d..f13345172 100644 --- a/scripts/test/test_run.py +++ b/scripts/test/test_run.py @@ -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[""] == ["path/to/config.yml"] + + def test_multiple_configs(self): + args = docopt.docopt(doc, [ + "config1.yml", + "config2.yml", + ]) + assert args[""] == ["config1.yml", "config2.yml"] + # make sure defaults are working + assert args["--os-type"] == "ubuntu"