From: Tom Walsh Date: Fri, 8 Aug 2014 02:37:32 +0000 (-0500) Subject: Reworked the release detection to normalize the value of distro.release as an integer... X-Git-Tag: v1.5.11~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6a85f968b48caab8fcdc541b697d0bb5009004c0;p=ceph-deploy.git Reworked the release detection to normalize the value of distro.release as an integer and use that as the basis of determining the correct value of rpm_dist() and repository_url_part(). This should work for all versions of RH, CentOS, and SL going forward. Signed-off-by: Tom Walsh --- diff --git a/ceph_deploy/hosts/centos/install.py b/ceph_deploy/hosts/centos/install.py index 277cfaa..26706c8 100644 --- a/ceph_deploy/hosts/centos/install.py +++ b/ceph_deploy/hosts/centos/install.py @@ -3,11 +3,9 @@ from ceph_deploy.lib import remoto def rpm_dist(distro): - # start using the el7 prefix now that rhel7 exists. - if distro.normalized_name == 'redhat' and distro.release.startswith('7'): - return 'el7' - if distro.normalized_name == 'centos' and distro.release.startswith('7'): - return 'el7' + release = int(float_or_zero(distro.release)) + if distro.normalized_name in ['redhat', 'centos', 'scientific'] and release >= 6: + return 'el' + str(release) return 'el6' @@ -27,17 +25,12 @@ def repository_url_part(distro): ('Red Hat Enterprise Linux Server', '7.0', 'Maipo') """ - if distro.normalized_name == 'redhat': - if distro.release.startswith('6'): - return 'rhel6' - elif distro.release.startswith('7'): - return 'rhel7' - - if distro.normalized_name == 'centos': - if distro.release.startswith('6'): - return 'el6' - if distro.release.startswith('7'): - return 'el7' + release = int(float_or_zero(distro.release)) + if release >= 6: + if distro.normalized_name == 'redhat': + return 'rhel' + str(release) + if distro.normalized_name in ['centos', 'scientific']: + return 'el' + str(release) return 'el6' @@ -257,3 +250,10 @@ def repo_install(distro, reponame, baseurl, gpgkey, **kw): pkg_managers.yum(distro.conn, 'wget') pkg_managers.yum(distro.conn, 'ceph') + + +def float_or_zero(value): + try: + return float(value) + except: + return 0.0 diff --git a/ceph_deploy/tests/unit/hosts/test_centos.py b/ceph_deploy/tests/unit/hosts/test_centos.py index 378ae66..312fc4f 100644 --- a/ceph_deploy/tests/unit/hosts/test_centos.py +++ b/ceph_deploy/tests/unit/hosts/test_centos.py @@ -11,6 +11,7 @@ class TestCentosVersionDetection(object): def test_url_detects_rhel6(self): self.distro.normalized_name = 'redhat' + self.distro.release = "6.4" assert centos.repository_url_part(self.distro) == 'rhel6' def test_url_detects_rhel5(self): @@ -23,6 +24,36 @@ class TestCentosVersionDetection(object): self.distro.release = '7.0' assert centos.repository_url_part(self.distro) == 'rhel7' + def test_url_detects_el5(self): + self.distro.normalized_name = 'centos' + self.distro.release = '5' + assert centos.repository_url_part(self.distro) == 'el6' + + def test_url_detects_el6(self): + self.distro.normalized_name = 'centos' + self.distro.release = '6.2' + assert centos.repository_url_part(self.distro) == 'el6' + + def test_url_detects_el7(self): + self.distro.normalized_name = 'centos' + self.distro.release = '7.0' + assert centos.repository_url_part(self.distro) == 'el7' + + def test_url_detects_scientific_el5(self): + self.distro.normalized_name = 'scientific' + self.distro.release = '5' + assert centos.repository_url_part(self.distro) == 'el6' + + def test_url_detects_scientific_el6(self): + self.distro.normalized_name = 'scientific' + self.distro.release = '6.2' + assert centos.repository_url_part(self.distro) == 'el6' + + def test_url_detects_scientific_el7(self): + self.distro.normalized_name = 'scientific' + self.distro.release = '7.0' + assert centos.repository_url_part(self.distro) == 'el7' + def test_rpm_dist_fallsback_to_el6(self): self.distro.normalized_name = 'redhat' self.distro.release = '3' @@ -38,37 +69,32 @@ class TestCentosVersionDetection(object): self.distro.release = '7.0' assert centos.rpm_dist(self.distro) == 'el7' - def test_url_fallsback_to_el6_centos(self): - self.distro.normalized_name = 'centos' - self.distro.release = '' - assert centos.repository_url_part(self.distro) == 'el6' - - def test_url_detects_el5(self): + def test_rpm_dist_fallsback_to_el6_centos(self): self.distro.normalized_name = 'centos' - self.distro.release = '5.0' - assert centos.repository_url_part(self.distro) == 'el6' + self.distro.release = '4' + assert centos.rpm_dist(self.distro) == 'el6' - def test_url_detects_el6(self): + def test_rpm_dist_detects_el6_centos(self): self.distro.normalized_name = 'centos' - self.distro.release = '6.0' - assert centos.repository_url_part(self.distro) == 'el6' + self.distro.release = '6.6' + assert centos.rpm_dist(self.distro) == 'el6' - def test_url_detects_el7(self): + def test_rpm_dist_detects_el7_centos(self): self.distro.normalized_name = 'centos' self.distro.release = '7.0' - assert centos.repository_url_part(self.distro) == 'el7' + assert centos.rpm_dist(self.distro) == 'el7' - def test_rpm_dist_fallsback_to_el6_centos(self): - self.distro.normalized_name = 'centos' + def test_rpm_dist_fallsback_to_el6_scientific(self): + self.distro.normalized_name = 'scientific' self.distro.release = '5' assert centos.rpm_dist(self.distro) == 'el6' - def test_rpm_dist_detects_el6_centos(self): - self.distro.normalized_name = 'centos' + def test_rpm_dist_detects_el6_scientific(self): + self.distro.normalized_name = 'scientific' self.distro.release = '6.6' assert centos.rpm_dist(self.distro) == 'el6' - def test_rpm_dist_detects_el7(self): - self.distro.normalized_name = 'centos' + def test_rpm_dist_detects_el7_scientific(self): + self.distro.normalized_name = 'scientific' self.distro.release = '7.0' assert centos.rpm_dist(self.distro) == 'el7'