]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
Modified the rpm_dist() and repository_url_part()
authorTom Walsh <tom.walsh@expresshosting.net>
Fri, 8 Aug 2014 21:27:22 +0000 (16:27 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Fri, 8 Aug 2014 23:34:40 +0000 (19:34 -0400)
So they can use the newly defined distro.normalized_release object to determine
the correct OS version and return the information based on that. This should
work for all releases from RHEL, CentOS, and Scientific Linux 6 and greater.

Changed the test_centos.py file to use pytest fixtures to test multiple input
types for the various OSes we are testing for.

Signed-off-by: Tom Walsh <tom.walsh@expresshosting.net>
ceph_deploy/hosts/centos/install.py
ceph_deploy/tests/unit/hosts/test_centos.py

index 9c9dffe12e9cc4eca45d5820beeaa8aa4ffe2b31..148e7c48ddd61281c98451385600b56119cc8bc7 100644 (file)
@@ -4,9 +4,8 @@ import re
 
 
 def rpm_dist(distro):
-    release = normalize_release(distro.release)
-    if distro.normalized_name in ['redhat', 'centos', 'scientific'] and release >= 6:
-        return 'el' + str(release)
+    if distro.normalized_name in ['redhat', 'centos', 'scientific'] and int(distro.normalized_release.major) >= 6:
+        return 'el' + str(distro.normalized_release.major)
     return 'el6'
 
 
@@ -26,12 +25,11 @@ def repository_url_part(distro):
         ('Red Hat Enterprise Linux Server', '7.0', 'Maipo')
 
     """
-    release = normalize_release(distro.release)
-    if release >= 6:
+    if int(distro.normalized_release.major) >= 6:
         if distro.normalized_name == 'redhat':
-            return 'rhel' + str(release)
+            return 'rhel' + str(distro.normalized_release.major)
         if distro.normalized_name in ['centos', 'scientific']:
-            return 'el' + str(release)
+            return 'el' + str(distro.normalized_release.major)
 
     return 'el6'
 
index 983ce27cdfdea7d9fb64a2f989f2c21df6dfe4f3..3efd990cc69f258e9eb8c5170a820fcac75cfd69 100644 (file)
 from ceph_deploy.hosts import centos
-from mock import Mock
-
-class TestCentosVersionDetection(object):
-
-    def setup(self):
-        self.distro = Mock()
-
-    def test_url_fallsback_to_el6(self):
-        assert centos.repository_url_part(self.distro) == 'el6'
-
-    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):
-        self.distro.normalized_name = 'redhat'
-        self.distro.release = '5.0'
-        assert centos.repository_url_part(self.distro) == 'el6'
-
-    def test_url_detects_rhel7(self):
-        self.distro.normalized_name = 'redhat'
-        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'
-        assert centos.rpm_dist(self.distro) == 'el6'
-
-    def test_rpm_dist_detects_rhel6(self):
-        self.distro.normalized_name = 'redhat'
-        self.distro.release = '6.6'
-        assert centos.rpm_dist(self.distro) == 'el6'
-
-    def test_rpm_dist_detects_rhel7(self):
-        self.distro.normalized_name = 'redhat'
-        self.distro.release = '7.0'
-        assert centos.rpm_dist(self.distro) == 'el7'
-
-    def test_rpm_dist_fallsback_to_el6_centos(self):
-        self.distro.normalized_name = 'centos'
-        self.distro.release = '4'
-        assert centos.rpm_dist(self.distro) == 'el6'
-
-    def test_rpm_dist_detects_el6_centos(self):
-        self.distro.normalized_name = 'centos'
-        self.distro.release = '6.6'
-        assert centos.rpm_dist(self.distro) == 'el6'
-
-    def test_rpm_dist_detects_el7_centos(self):
-        self.distro.normalized_name = 'centos'
-        self.distro.release = '7.0'
-        assert centos.rpm_dist(self.distro) == 'el7'
-
-    def test_rpm_dist_detects_centos_version_with_subversion(self):
-        self.distro.normalized_name = 'centos'
-        self.distro.release = '7.0.1406'
-        assert centos.rpm_dist(self.distro) == 'el7'
-
-    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_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_scientific(self):
-        self.distro.normalized_name = 'scientific'
-        self.distro.release = '7.0'
-        assert centos.rpm_dist(self.distro) == 'el7'
-
-    def test_normalize_release_number(self):
-        self.distro.release = '6.9'
-        assert centos.normalize_release(self.distro.release) == 6.0
-
-    def test_normalize_release_empty_string(self):
-        self.distro.release = ''
-        assert centos.normalize_release(self.distro.release) == 0.0
-
-    def test_normalize_release_complex_release(self):
-        self.distro.release = '7.0.1406'
-        assert centos.normalize_release(self.distro.release) == 7.0
\ No newline at end of file
+from ceph_deploy import hosts
+from mock import Mock, patch
+
+def pytest_generate_tests(metafunc):
+    # called once per each test function
+    funcarglist = metafunc.cls.params[metafunc.function.__name__]
+    argnames = list(funcarglist[0])
+    metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
+            for funcargs in funcarglist])
+
+class TestCentosRepositoryUrlPart(object):
+
+    params= {
+        'test_repository_url_part': [
+            dict(distro="CentOS Linux", release='4.3', codename="Foo", output='el6'),
+            dict(distro="CentOS Linux", release='6.5', codename="Final", output='el6'),
+            dict(distro="CentOS Linux", release='7.0', codename="Core", output='el7'),
+            dict(distro="CentOS Linux", release='7.0.1406', codename="Core", output='el7'),
+            dict(distro="CentOS Linux", release='10.4.000', codename="Core", output='el10'),
+            dict(distro="RedHat", release='4.3', codename="Foo", output='el6'),
+            dict(distro="RedHat", release='6.5', codename="Final", output='rhel6'),
+            dict(distro="RedHat", release='7.0', codename="Core", output='rhel7'),
+            dict(distro="RedHat", release='7.0.1406', codename="Core", output='rhel7'),
+            dict(distro="RedHat", release='10.999.12', codename="Core", output='rhel10'),
+            ],
+        'test_rpm_dist': [
+            dict(distro="CentOS Linux", release='4.3', codename="Foo", output='el6'),
+            dict(distro="CentOS Linux", release='6.5', codename="Final", output='el6'),
+            dict(distro="CentOS Linux", release='7.0', codename="Core", output='el7'),
+            dict(distro="CentOS Linux", release='7.0.1406', codename="Core", output='el7'),
+            dict(distro="CentOS Linux", release='10.10.9191', codename="Core", output='el10'),
+            dict(distro="RedHat", release='4.3', codename="Foo", output='el6'),
+            dict(distro="RedHat", release='6.5', codename="Final", output='el6'),
+            dict(distro="RedHat", release='7.0', codename="Core", output='el7'),
+            dict(distro="RedHat", release='7.0.1406', codename="Core", output='el7'),
+            dict(distro="RedHat", release='10.9.8765', codename="Core", output='el10'),
+        ]
+    }
+    
+
+    def make_fake_connection(self, platform_information=None):
+        get_connection = Mock()
+        get_connection.return_value = get_connection
+        get_connection.remote_module.platform_information = Mock(
+            return_value=platform_information)
+        return get_connection
+
+    def test_repository_url_part(self, distro, release, codename, output):
+        fake_get_connection = self.make_fake_connection((distro, release, codename))
+        with patch('ceph_deploy.hosts.get_connection', fake_get_connection):
+            self.module = hosts.get('testhost')
+        assert centos.repository_url_part(self.module) == output
+
+    def test_rpm_dist(self, distro, release, codename, output):
+        fake_get_connection = self.make_fake_connection((distro, release, codename))
+        with patch('ceph_deploy.hosts.get_connection', fake_get_connection):
+            self.module = hosts.get('testhost')
+        assert centos.rpm_dist(self.module) == output