]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
Reworked the release detection to normalize the value of distro.release as an integer...
authorTom Walsh <tom.walsh@expresshosting.net>
Fri, 8 Aug 2014 02:37:32 +0000 (21:37 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Fri, 8 Aug 2014 23:34:31 +0000 (19:34 -0400)
Signed-off-by: Tom Walsh <tom.walsh@expresshosting.net>
ceph_deploy/hosts/centos/install.py
ceph_deploy/tests/unit/hosts/test_centos.py

index 277cfaaff7270f32d858f4d0781c43fc20c351d3..26706c8d54e121836e57efd9af58ced28d28b021 100644 (file)
@@ -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
index 378ae66cba6d56c7e2c6d06c176cedd92ed048a5..312fc4fd83b240e91c53abeb895c391133c9ca4c 100644 (file)
@@ -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'