From 677b5039fc345b9addb2b64955a43f7514bbd4b7 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Sun, 24 May 2020 08:01:41 +0200 Subject: [PATCH] teuthology-suite: automate -t argument default value This change is required to determine which teuthology branch should be used for scheduling a run for the given ceph branch. Drop the code using --ceph-branch and when --teuthology-branch is not supplied, since this mechanism is not used and not supported anymore. Signed-off-by: Kyr Shatskyy --- scripts/suite.py | 9 +++- teuthology/suite/__init__.py | 1 - teuthology/suite/run.py | 68 +++++++++++++++++++++--------- teuthology/suite/test/test_init.py | 6 +++ teuthology/suite/test/test_run_.py | 3 ++ 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/scripts/suite.py b/scripts/suite.py index da01427386..5805ec9a2b 100644 --- a/scripts/suite.py +++ b/scripts/suite.py @@ -54,7 +54,13 @@ Standard arguments: [default: basic] -t , --teuthology-branch The teuthology branch to run against. - [default: {default_teuthology_branch}] + Default value is determined in the next order. + There is TEUTH_BRANCH environment variable set. + There is `qa/.teuthology_branch` present in + the suite repo and contains non-empty string. + There is `teuthology_branch` present in one of + the user or system `teuthology.yaml` configuration + files respectively, otherwise use `master`. -m , --machine-type Machine type [default: {default_machine_type}] -d , --distro @@ -165,7 +171,6 @@ Scheduler arguments: default_suite_repo=defaults('--suite-repo', config.get_ceph_qa_suite_git_url()), default_ceph_branch=defaults('--ceph-branch', 'master'), - default_teuthology_branch=defaults('--teuthology-branch', 'master'), ) diff --git a/teuthology/suite/__init__.py b/teuthology/suite/__init__.py index 46578fc9ce..cfac622c4f 100644 --- a/teuthology/suite/__init__.py +++ b/teuthology/suite/__init__.py @@ -25,7 +25,6 @@ def override_arg_defaults(name, default, env=os.environ): '--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] diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index f8da6cac64..d0eda66167 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -51,12 +51,6 @@ class Run(object): # caches package versions to minimize requests to gbs self.package_versions = dict() - if self.args.suite_dir: - self.suite_repo_path = self.args.suite_dir - else: - self.suite_repo_path = util.fetch_repos( - self.base_config.suite_branch, test_name=self.name) - # Interpret any relative paths as being relative to ceph-qa-suite # (absolute paths are unchanged by this) self.base_yaml_paths = [os.path.join(self.suite_repo_path, b) for b in @@ -94,9 +88,15 @@ class Run(object): # We don't store ceph_version because we don't use it yet outside of # logging. self.choose_ceph_version(ceph_hash) - teuthology_branch = self.choose_teuthology_branch() suite_branch = self.choose_suite_branch() suite_hash = self.choose_suite_hash(suite_branch) + if self.args.suite_dir: + self.suite_repo_path = self.args.suite_dir + else: + self.suite_repo_path = util.fetch_repos( + suite_branch, test_name=self.name) + teuthology_branch = self.choose_teuthology_branch() + if self.args.distro_version: self.args.distro_version, _ = \ @@ -196,20 +196,48 @@ class Run(object): log.info('skipping ceph package verification') def choose_teuthology_branch(self): + """Select teuthology branch, check if it is present in repo and + return the branch name value. + + The branch name value is determined in the following order: + + Use ``--teuthology-branch`` argument value if supplied. + + Use ``TEUTH_BRANCH`` environment variable value if declared. + + If file ``qa/.teuthology_branch`` can be found in the suite repo + supplied with ``--suite-repo`` or ``--suite-dir`` and contains + non-empty string then use it as the branch name. + + Use ``teuthology_branch`` value if it is set in the one + of the teuthology config files ``$HOME/teuthology.yaml`` + or ``/etc/teuthology.yaml`` correspondingly. + + Use ``master``. + + Generate exception if the branch is not present in the repo. + """ teuthology_branch = self.args.teuthology_branch - if teuthology_branch and teuthology_branch != 'master': - if not util.git_branch_exists('teuthology', teuthology_branch): - exc = BranchNotFoundError(teuthology_branch, 'teuthology.git') - util.schedule_fail(message=str(exc), name=self.name) - elif not teuthology_branch: - # Decide what branch of teuthology to use - if util.git_branch_exists('teuthology', self.args.ceph_branch): - teuthology_branch = self.args.ceph_branch - else: - log.info( - "branch {0} not in teuthology.git; will use master for" - " teuthology".format(self.args.ceph_branch)) - teuthology_branch = 'master' + if not teuthology_branch: + teuthology_branch = os.environ.get('TEUTH_BRANCH', None) + if not teuthology_branch: + branch_file_path = self.suite_repo_path + '/qa/.teuthology_branch' + log.debug('Check file %s exists', branch_file_path) + if os.path.exists(branch_file_path): + log.debug('Found teuthology branch config file %s', + branch_file_path) + with open(branch_file_path) as f: + teuthology_branch = f.read().strip() + if teuthology_branch: + log.debug( + 'The teuthology branch is overridden with %s', + teuthology_branch) + else: + log.warning( + 'The teuthology branch config is empty, skipping') + if not teuthology_branch: + teuthology_branch = config.get('teuthology_branch', 'master') + teuthology_hash = util.git_ls_remote( 'teuthology', teuthology_branch diff --git a/teuthology/suite/test/test_init.py b/teuthology/suite/test/test_init.py index 9defdddc1a..49f88fdcb8 100644 --- a/teuthology/suite/test/test_init.py +++ b/teuthology/suite/test/test_init.py @@ -156,6 +156,9 @@ class TestSuiteMain(object): def fake_bool(*args, **kwargs): return True + def fake_false(*args, **kwargs): + return False + with patch.multiple( 'teuthology.suite.run.util', fetch_repos=DEFAULT, @@ -166,6 +169,9 @@ class TestSuiteMain(object): with patch.multiple( 'teuthology.suite.run.Run', prepare_and_schedule=prepare_and_schedule, + ), patch.multiple( + 'teuthology.suite.run.os.path', + exists=fake_false, ): main([ '--ceph', 'master', diff --git a/teuthology/suite/test/test_run_.py b/teuthology/suite/test/test_run_.py index 5b44761f8e..bee67a6de3 100644 --- a/teuthology/suite/test/test_run_.py +++ b/teuthology/suite/test/test_run_.py @@ -145,8 +145,10 @@ class TestRun(object): @patch('teuthology.suite.run.util.git_branch_exists') @patch('teuthology.suite.run.util.package_version_for_hash') @patch('teuthology.suite.run.util.git_ls_remote') + @patch('teuthology.suite.run.os.path.exists') def test_regression( self, + m_qa_teuthology_branch_exists, m_git_ls_remote, m_package_version_for_hash, m_git_branch_exists, @@ -157,6 +159,7 @@ class TestRun(object): m_package_version_for_hash.return_value = 'ceph_hash' m_git_branch_exists.return_value = True m_git_ls_remote.return_value = "suite_branch" + m_qa_teuthology_branch_exists.return_value = False self.args_dict = { 'base_yaml_paths': [], 'ceph_branch': 'master', -- 2.39.5