]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
ShamanProject: translate tags to sha1s 970/head
authorZack Cerza <zack@redhat.com>
Wed, 19 Oct 2016 21:17:19 +0000 (15:17 -0600)
committerZack Cerza <zack@redhat.com>
Fri, 28 Oct 2016 20:13:07 +0000 (14:13 -0600)
Since Shaman doesn't want to have to know about tags, let's do the
translation from tag->sha1 ourselves using 'git ls-remote'.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/packaging.py
teuthology/test/test_packaging.py

index 80b8d9d003fb18628d82594540900d8575cdba31..1e2a67eb449a6c1f93de1e4f1ec442ddf4faf935 100644 (file)
@@ -8,9 +8,11 @@ import urlparse
 from collections import OrderedDict
 from cStringIO import StringIO
 
+from . import repo_utils
+
 from .config import config
 from .contextutil import safe_while
-from .exceptions import VersionNotFoundError
+from .exceptions import VersionNotFoundError, CommitNotFoundError
 from .orchestra.opsys import OS, DEFAULT_OS_VERSION
 
 log = logging.getLogger(__name__)
@@ -467,6 +469,7 @@ class GitbuilderProject(object):
         # when we're initializing with a remote we most likely have
         # a task config, not the entire teuthology job config
         self.flavor = self.job_config.get("flavor", "basic")
+        self.tag = self.job_config.get("tag")
 
     def _init_from_config(self):
         """
@@ -793,7 +796,9 @@ class ShamanProject(GitbuilderProject):
         req_obj['flavor'] = flavor
         req_obj['distros'] = '%s/%s' % (self.distro, self.arch)
         ref_name, ref_val = self._choose_reference().items()[0]
-        if ref_name == 'sha1':
+        if ref_name == 'tag':
+            req_obj['sha1'] = self._sha1 = self._tag_to_sha1()
+        elif ref_name == 'sha1':
             req_obj['sha1'] = ref_val
         else:
             req_obj['ref'] = ref_val
@@ -804,6 +809,25 @@ class ShamanProject(GitbuilderProject):
         ) + '?%s' % req_str
         return uri
 
+    def _tag_to_sha1(self):
+        """
+        Shaman doesn't know about tags. Use git ls-remote to query the remote
+        repo in order to map tags to their sha1 value.
+        """
+        git_url = repo_utils.build_git_url(self.project)
+        # Ceph (and other projects) uses annotated tags for releases. This has
+        # the side-effect of making git ls-remote return the sha1 for the
+        # annotated tag object and not the last "real" commit in that tag. By
+        # contrast, when a person (or a build system) issues a
+        # "git checkout <tag>" command, HEAD will be the last "real" commit and
+        # not the tag.
+        # Below we have to append "^{}" to the tag value to work around this in
+        # order to query for the sha1 that the build system uses.
+        result = repo_utils.ls_remote(git_url, "%s^{}" % self.tag)
+        if result is None:
+            raise CommitNotFoundError(self.tag, git_url)
+        return result
+
     def assert_result(self):
         if len(self._result.json()) == 0:
             raise VersionNotFoundError(self._result.url)
index 9c466a750065a7e61e004b6ed127964f7afa76ed..cabecc0239abbbf18a0dd275e504e39feb99cbab 100644 (file)
@@ -685,10 +685,14 @@ class TestShamanProject(TestBuilderProject):
             )
 
     def test_init_from_config_tag_overrides_branch_ref(self, caplog):
-        obj = super(TestShamanProject, self)\
-            .test_init_from_config_tag_overrides_branch_ref(caplog)
-        search_uri = obj._search_uri
-        assert 'v10.0.1' in search_uri
+        with patch(
+            'teuthology.packaging.repo_utils.ls_remote',
+        ) as m_ls_remote:
+            m_ls_remote.return_value = 'sha1_from_my_tag'
+            obj = super(TestShamanProject, self)\
+                .test_init_from_config_tag_overrides_branch_ref(caplog)
+            search_uri = obj._search_uri
+        assert 'sha1=sha1_from_my_tag' in search_uri
         assert 'jewel' not in search_uri
 
     def test_init_from_config_branch_overrides_sha1(self, caplog):