From f0db3fe73429599345a58485ae7e5f2c4d641a24 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Thu, 28 Feb 2019 16:37:10 +0100 Subject: [PATCH] openstack: take defaults from environment This patch introduces TEUTH_ based environment variables which can be used to avoid bulky commands while overiding default values for some of the teuthology arguments. Removes mandatory of --ceph option for teuthology-suite, and defaults to 'master'. Signed-off-by: Kyr Shatskyy --- scripts/openstack.py | 9 +++++++-- scripts/suite.py | 18 +++++++++++++----- teuthology/suite/__init__.py | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/scripts/openstack.py b/scripts/openstack.py index e9f9aa4315..31de2b8469 100644 --- a/scripts/openstack.py +++ b/scripts/openstack.py @@ -1,5 +1,6 @@ import argparse import sys +import os import teuthology.openstack @@ -43,7 +44,7 @@ def get_suite_parser(): parser.add_argument( '-c', '--ceph', help='The ceph branch to run against', - default='master', + default=os.getenv('TEUTH_CEPH_BRANCH', 'master'), ) parser.add_argument( '-k', '--kernel', @@ -63,6 +64,7 @@ def get_suite_parser(): parser.add_argument( '--suite-branch', help='Use this suite branch instead of the ceph branch', + default=os.getenv('TEUTH_SUITE_BRANCH', 'master'), ) parser.add_argument( '-e', '--email', @@ -173,10 +175,12 @@ def get_suite_parser(): parser.add_argument( '--ceph-repo', help=("Query this repository for Ceph branch and SHA1"), + default=os.getenv('TEUTH_CEPH_REPO', 'https://github.com/ceph/ceph'), ) parser.add_argument( '--suite-repo', help=("Use tasks and suite definition in this repository"), + default=os.getenv('TEUTH_SUITE_REPO', 'https://github.com/ceph/ceph'), ) return parser @@ -206,11 +210,12 @@ def get_openstack_parser(): parser.add_argument( '--teuthology-git-url', help="git clone url for teuthology", + default=os.getenv('TEUTH_REPO', 'https://github.com/ceph/teuthology'), ) parser.add_argument( '--teuthology-branch', help="use this teuthology branch instead of master", - default='master', + default=os.getenv('TEUTH_BRANCH', 'master'), ) parser.add_argument( '--upload', diff --git a/scripts/suite.py b/scripts/suite.py index 2e8596f668..ceb745355f 100644 --- a/scripts/suite.py +++ b/scripts/suite.py @@ -2,12 +2,13 @@ import docopt import sys import teuthology.suite +from teuthology.suite import override_arg_defaults as defaults from teuthology.config import config doc = """ usage: teuthology-suite --help - teuthology-suite [-v | -vv ] --machine-type --ceph --suite [options] [...] - teuthology-suite [-v | -vv ] --machine-type --ceph --rerun [options] [...] + teuthology-suite [-v | -vv ] --machine-type --suite [options] [...] + teuthology-suite [-v | -vv ] --machine-type --rerun [options] [...] 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 @@ -31,6 +32,7 @@ Standard arguments: The suite to schedule --wait Block until the suite is finished -c , --ceph The ceph branch to run against + [default: {default_ceph_branch}] -S , --sha1 The ceph sha1 to run against (overrides -c) If both -S and -c are supplied, -S wins, and there is no validation that sha1 is contained @@ -49,7 +51,7 @@ Standard arguments: [default: basic] -t , --teuthology-branch The teuthology branch to run against. - [default: master] + [default: {default_teuthology_branch}] -m , --machine-type Machine type [default: {default_machine_type}] -d , --distro @@ -66,6 +68,7 @@ Standard arguments: [default: qa] --suite-branch Use this suite branch instead of the ceph branch + [default: {default_suite_branch}] --suite-dir Use this alternative directory as-is when assembling jobs from yaml fragments. This causes to be ignored for scheduling @@ -136,8 +139,13 @@ Scheduler arguments: """.format( default_machine_type=config.default_machine_type, default_results_timeout=config.results_timeout, - default_ceph_repo=config.get_ceph_git_url(), - default_suite_repo=config.get_ceph_qa_suite_git_url(), + default_ceph_repo=defaults('--ceph-repo', + config.get_ceph_git_url()), + default_suite_repo=defaults('--suite-repo', + config.get_ceph_qa_suite_git_url()), + default_ceph_branch=defaults('--ceph-branch', 'master'), + default_suite_branch=defaults('--suite-branch', 'master'), + default_teuthology_branch=defaults('--teuthology-branch', 'master'), ) diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index d11b70029a..ce1980de3d 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -19,6 +19,25 @@ from .util import schedule_fail log = logging.getLogger(__name__) +def override_arg_defaults(name, default, env=os.environ): + env_arg = { + '--ceph-repo' : 'TEUTH_CEPH_REPO', + '--suite-repo' : 'TEUTH_SUITE_REPO', + '--ceph-branch' : 'TEUTH_CEPH_BRANCH', + '--suite-branch' : 'TEUTH_SUITE_BRANCH', + '--teuthology-branch' : 'TEUTH_BRANCH', + } + if name in env_arg and env_arg[name] in env.keys(): + variable = env_arg[name] + value = env[variable] + log.debug("Default value for '{arg}' is overridden " + "from environment with: {val}" + .format(arg=name, val=value)) + return value + else: + return default + + def process_args(args): conf = YamlConfig() rename_args = { -- 2.39.5