]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
openstack: split argparse arguments
authorLoic Dachary <ldachary@redhat.com>
Sun, 6 Dec 2015 21:50:52 +0000 (22:50 +0100)
committerKyr Shatskyy <kyrylo.shatskyy@gmail.com>
Thu, 18 Oct 2018 22:52:44 +0000 (00:52 +0200)
So that it can be re-used by scripts that need to include part of the parser.

Signed-off-by: Loic Dachary <loic@dachary.org>
scripts/openstack.py

index b467de4f508f16425971935cda11adf7d9bb2644..c758dc6b34b13b84c33cfb1a983e8c1a2b9bd6f1 100644 (file)
@@ -6,91 +6,31 @@ import teuthology.openstack
 def main(argv=sys.argv[1:]):
     sys.exit(teuthology.openstack.main(parse_args(argv), argv))
 
-def parse_args(argv):
-    parser = argparse.ArgumentParser(
-        formatter_class=argparse.RawDescriptionHelpFormatter,
-        description="""
-Run a suite of ceph integration tests. A suite is a directory containing
-facets. A facet is a directory containing config snippets. Running a suite
-means running teuthology for every configuration combination generated by
-taking one config snippet from each facet. Any config files passed on the
-command line will be used for every combination, and will override anything in
-the suite. By specifying a subdirectory in the suite argument, it is possible
-to limit the run to a specific facet. For instance -s upgrade/dumpling-x only
-runs the dumpling-x facet of the upgrade suite.
-
-Display the http and ssh access to follow the progress of the suite
-and analyze results.
-
-  firefox http://183.84.234.3:8081/
-  ssh -i teuthology-admin.pem ubuntu@183.84.234.3
-
-""")
-    parser.add_argument(
-        '-v', '--verbose',
-        action='store_true', default=None,
-        help='be more verbose',
-    )
-    parser.add_argument(
-        '--wait',
-        action='store_true', default=None,
-        help='block until the suite is finished',
-    )
-    parser.add_argument(
-        '--name',
-        help='OpenStack primary instance name',
-        default='teuthology',
-    )
+def get_key_parser():
+    parser = argparse.ArgumentParser()
     parser.add_argument(
         '--key-name',
         help='OpenStack keypair name',
-        required=True,
     )
     parser.add_argument(
         '--key-filename',
         help='path to the ssh private key',
     )
-    parser.add_argument(
-        '--simultaneous-jobs',
-        help='maximum number of jobs running in parallel',
-        type=int,
-        default=1,
-    )
-    parser.add_argument(
-        '--teardown',
-        action='store_true', default=None,
-        help='destroy the cluster, if it exists',
-    )
-    parser.add_argument(
-        '--teuthology-git-url',
-        help=("git clone url for teuthology"),
-    )
-    parser.add_argument(
-        '--teuthology-branch',
-        help="use this teuthology branch instead of master",
-        default='master',
-    )
-    parser.add_argument(
-        '--upload',
-        action='store_true', default=False,
-        help='upload archives to an rsync server',
-    )
-    parser.add_argument(
-        '--archive-upload',
-        help='rsync destination to upload archives',
-        default='ubuntu@teuthology-logs.public.ceph.com:./',
-    )
-    parser.add_argument(
-        '--archive-upload-url',
-        help='Public facing URL where archives are uploaded',
-        default='http://teuthology-logs.public.ceph.com',
-    )
+    return parser
+
+def get_suite_parser():
+    parser = argparse.ArgumentParser()
     # copy/pasted from scripts/suite.py
     parser.add_argument(
         'config_yaml',
         nargs='*',
         help='Optional extra job yaml to include',
     )
+    parser.add_argument(
+        '-v', '--verbose',
+        action='store_true', default=None,
+        help='be more verbose',
+    )
     parser.add_argument(
         '--dry-run',
         action='store_true', default=None,
@@ -191,5 +131,85 @@ and analyze results.
         '--ceph-qa-suite-git-url',
         help=("git clone url for ceph-qa-suite"),
     )
+    return parser
+
+def get_openstack_parser():
+    parser = argparse.ArgumentParser()
+    parser.add_argument(
+        '--wait',
+        action='store_true', default=None,
+        help='block until the suite is finished',
+    )
+    parser.add_argument(
+        '--name',
+        help='OpenStack primary instance name',
+        default='teuthology',
+    )
+    parser.add_argument(
+        '--simultaneous-jobs',
+        help='maximum number of jobs running in parallel',
+        type=int,
+        default=1,
+    )
+    parser.add_argument(
+        '--teardown',
+        action='store_true', default=None,
+        help='destroy the cluster, if it exists',
+    )
+    parser.add_argument(
+        '--teuthology-git-url',
+        help="git clone url for teuthology",
+    )
+    parser.add_argument(
+        '--teuthology-branch',
+        help="use this teuthology branch instead of master",
+        default='master',
+    )
+    parser.add_argument(
+        '--upload',
+        action='store_true', default=False,
+        help='upload archives to an rsync server',
+    )
+    parser.add_argument(
+        '--archive-upload',
+        help='rsync destination to upload archives',
+        default='ubuntu@teuthology-logs.public.ceph.com:./',
+    )
+    parser.add_argument(
+        '--archive-upload-url',
+        help='Public facing URL where archives are uploaded',
+        default='http://teuthology-logs.public.ceph.com',
+    )
+    return parser
 
-    return parser.parse_args(argv)
+def get_parser():
+    parser = argparse.ArgumentParser(
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        parents=[
+            get_suite_parser(),
+            get_key_parser(),
+            get_openstack_parser(),
+        ],
+        conflict_handler='resolve',
+        add_help=False,
+        description="""
+Run a suite of ceph integration tests. A suite is a directory containing
+facets. A facet is a directory containing config snippets. Running a suite
+means running teuthology for every configuration combination generated by
+taking one config snippet from each facet. Any config files passed on the
+command line will be used for every combination, and will override anything in
+the suite. By specifying a subdirectory in the suite argument, it is possible
+to limit the run to a specific facet. For instance -s upgrade/dumpling-x only
+runs the dumpling-x facet of the upgrade suite.
+
+Display the http and ssh access to follow the progress of the suite
+and analyze results.
+
+  firefox http://183.84.234.3:8081/
+  ssh -i teuthology-admin.pem ubuntu@183.84.234.3
+
+""")
+    return parser
+
+def parse_args(argv):
+    return get_parser().parse_args(argv)