]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
GitbuilderProject: fetch sha1 from gitbuilder if not in the config 613/head
authorAndrew Schoen <aschoen@redhat.com>
Thu, 3 Sep 2015 15:12:12 +0000 (10:12 -0500)
committerAndrew Schoen <aschoen@redhat.com>
Thu, 3 Sep 2015 15:34:55 +0000 (10:34 -0500)
If the sha1 is not provided in the job config, it needs to be fetched
from gitbuilder.

See: http://tracker.ceph.com/issues/12934

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
teuthology/packaging.py
teuthology/test/test_packaging.py

index b06bd28fa3035df3e07f2fa875d1d9f7c2d5a4cb..f8ef92c7b5a1f14703b40e9329a55bb0f5f37c71 100644 (file)
@@ -437,7 +437,6 @@ class GitbuilderProject(object):
         # avoiding circular imports
         from teuthology.suite import get_install_task_flavor
         self.flavor = get_install_task_flavor(self.job_config)
-        self.sha1 = self.job_config.get("sha1")
 
         if remote and ctx:
             self._init_from_remote()
@@ -477,6 +476,21 @@ class GitbuilderProject(object):
             "debian",
         ) else "rpm"
 
+    @property
+    def sha1(self):
+        """
+        Performs a call to gitbuilder to retrieve the sha1 if not provided in
+        the job_config. The returned value is cached so that this call only
+        happens once.
+
+        :returns: The sha1 of the project as a string.
+        """
+        if not hasattr(self, "_sha1"):
+            self._sha1 = self.job_config.get('sha1')
+            if not self._sha1:
+                self._sha1 = self._get_package_sha1()
+        return self._sha1
+
     @property
     def version(self):
         """
@@ -691,3 +705,23 @@ class GitbuilderProject(object):
                     version = version.split('-')[0]
             log.info("Found version: {0}".format(version))
         return version
+
+    def _get_package_sha1(self):
+        """
+        Look for, and parse, a file called 'sha1' in base_url.
+        """
+        url = "{0}/sha1".format(self.base_url)
+        log.info("Looking for package sha1: {0}".format(url))
+        resp = requests.get(url)
+        sha1 = None
+        if not resp.ok:
+            # TODO: maybe we should have this retry a few times?
+            log.error(
+                'Package sha1 was not there (got HTTP code %s)...',
+                resp.status_code,
+            )
+        else:
+            sha1 = resp.text.strip()
+            log.info("Found sha1: {0}".format(sha1))
+
+        return sha1
index 2fc9e4e418ba9bcd71d230ec09237037fb109d60..780dbafcaa0fdbfcd9eadbd1db0b15d4538035f5 100644 (file)
@@ -364,6 +364,39 @@ class TestGitbuilderProject(object):
         gp = packaging.GitbuilderProject("ceph", {}, ctx=ctx, remote=rem)
         assert not gp.version
 
+    @patch("teuthology.packaging.config")
+    @patch("teuthology.packaging._get_config_value_for_remote")
+    @patch("requests.get")
+    def test_get_package_sha1_fetched_found(self, m_get, m_get_config_value,
+                                            m_config):
+        m_config.baseurl_template = 'http://{host}/{proj}-{pkg_type}-{dist}-{arch}-{flavor}/{uri}'
+        m_config.gitbuilder_host = "gitbuilder.ceph.com"
+        m_get_config_value.return_value = None
+        resp = Mock()
+        resp.ok = True
+        resp.text = "the_sha1"
+        m_get.return_value = resp
+        rem = self._get_remote()
+        ctx = dict(foo="bar")
+        gp = packaging.GitbuilderProject("ceph", {}, ctx=ctx, remote=rem)
+        assert gp.sha1 == "the_sha1"
+
+    @patch("teuthology.packaging.config")
+    @patch("teuthology.packaging._get_config_value_for_remote")
+    @patch("requests.get")
+    def test_get_package_sha1_fetched_not_found(self, m_get, m_get_config_value,
+                                           m_config):
+        m_config.baseurl_template = 'http://{host}/{proj}-{pkg_type}-{dist}-{arch}-{flavor}/{uri}'
+        m_config.gitbuilder_host = "gitbuilder.ceph.com"
+        m_get_config_value.return_value = None
+        resp = Mock()
+        resp.ok = False
+        m_get.return_value = resp
+        rem = self._get_remote()
+        ctx = dict(foo="bar")
+        gp = packaging.GitbuilderProject("ceph", {}, ctx=ctx, remote=rem)
+        assert not gp.sha1
+
     GITBUILDER_DISTRO_MATRIX = [
         ('rhel', '7.0', None, 'centos7'),
         ('centos', '6.5', None, 'centos6'),