# 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()
"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):
"""
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
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'),