]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
teuthology-suite: automate -t argument default value 1490/head
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Sun, 24 May 2020 06:01:41 +0000 (08:01 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 1 Jun 2020 05:31:57 +0000 (07:31 +0200)
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 <kyrylo.shatskyy@suse.com>
scripts/suite.py
teuthology/suite/__init__.py
teuthology/suite/run.py
teuthology/suite/test/test_init.py
teuthology/suite/test/test_run_.py

index da01427386cb00792cd6ff62916cdb2bceb66095..5805ec9a2bd5ccbc160b72adf7d2adbaa6ac5ec8 100644 (file)
@@ -54,7 +54,13 @@ Standard arguments:
                               [default: basic]
   -t <branch>, --teuthology-branch <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 <type>, --machine-type <type>
                               Machine type [default: {default_machine_type}]
   -d <distro>, --distro <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'),
 )
 
 
index 46578fc9ce1182095995932c9e1a8db36b80aa0f..cfac622c4fa2a0c9300d8193eaa5ab4ed7ab6809 100644 (file)
@@ -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]
index f8da6cac6444661cd24c2605184c2d0f4b6df1b5..d0eda66167db3b590613ff8d706393e6a6c011a2 100644 (file)
@@ -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
index 9defdddc1ae2d60b3c7bc8c15e91072716731871..49f88fdcb87aab9a052213a238f9943946720681 100644 (file)
@@ -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',
index 5b44761f8e3189e1ecc8c019114ecc9459e1f3bf..bee67a6de3b448acb4ba7625482fd36a0b66d279 100644 (file)
@@ -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',