]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-detect-init: FreeBSD introduction of bsdrc 11906/head
authorWillem Jan Withagen <wjw@digiware.nl>
Tue, 8 Nov 2016 14:24:08 +0000 (15:24 +0100)
committerKefu Chai <kchai@redhat.com>
Mon, 14 Nov 2016 06:34:47 +0000 (14:34 +0800)
ceph-detect-init/ceph_detect_init/freebsd/__init__.py
    New file

ceph_detect_init/__init__.py: Only test FreeBSD after it is not Linux

    If we do it the other way around it will not work during testing on FreeBSD
    because it will always have platform.system() == FreeBSD
    So first test for Linux, and only then check to see if it is FreeBSD.

ceph-detect-init/tests/test_all.py: add tests for FreeBSD
ceph-detect-init/run-tox.sh: ReEnable to run test for FreeBSD

Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/ceph-detect-init/ceph_detect_init/__init__.py
src/ceph-detect-init/ceph_detect_init/freebsd/__init__.py [new file with mode: 0644]
src/ceph-detect-init/run-tox.sh
src/ceph-detect-init/tests/test_all.py

index 561900d2f33f93d570a27b6ecd475f527f36cb29..b749ea08b5224090cdc1867e952b0db51b19f962 100644 (file)
@@ -21,6 +21,7 @@ from ceph_detect_init import fedora
 from ceph_detect_init import rhel
 from ceph_detect_init import suse
 from ceph_detect_init import gentoo
+from ceph_detect_init import freebsd
 import logging
 import platform
 
@@ -65,6 +66,7 @@ def _get_distro(distro, use_rhceph=False):
         'gentoo': gentoo,
         'funtoo': gentoo,
         'exherbo': gentoo,
+        'freebsd': freebsd,
     }
 
     if distro == 'redhat' and use_rhceph:
@@ -90,11 +92,22 @@ def _normalized_distro_name(distro):
 
 def platform_information():
     """detect platform information from remote host."""
-    linux_distro = platform.linux_distribution(
-        supported_dists=platform._supported_dists + ('alpine',))
-    logging.debug('platform_information: linux_distribution = ' +
-                  str(linux_distro))
-    distro, release, codename = linux_distro
+    if platform.system() == 'Linux':
+        linux_distro = platform.linux_distribution(
+            supported_dists=platform._supported_dists + ('alpine',))
+        logging.debug('platform_information: linux_distribution = ' +
+                      str(linux_distro))
+        distro, release, codename = linux_distro
+    elif platform.system() == 'FreeBSD':
+        distro = 'freebsd'
+        release = platform.release()
+        codename = platform.version().split(' ')[3].split(':')[0]
+        logging.debug(
+            'platform_information: release = {}, version = {}'.format(
+                platform.release(), platform.version()))
+    else:
+        raise exc.UnsupportedPlatform(platform.system(), '', '')
+
     # this could be an empty string in Debian
     if not codename and 'debian' in distro.lower():
         debian_codenames = {
diff --git a/src/ceph-detect-init/ceph_detect_init/freebsd/__init__.py b/src/ceph-detect-init/ceph_detect_init/freebsd/__init__.py
new file mode 100644 (file)
index 0000000..5244e19
--- /dev/null
@@ -0,0 +1,11 @@
+distro = None
+release = None
+codename = None
+
+
+def choose_init():
+    """Select a init system
+
+     Returns the name of a init system (upstart, sysvinit ...).
+     """
+    return 'bsdrc'
index 0c135c5aedb30cccdc79012b99882c1913600c4b..9736dc400598b23f184e58db6efc527b2aadf9a0 100755 (executable)
 # GNU Library Public License for more details.
 #
 
-if [ x"`uname`"x = xFreeBSDx ]; then
-    echo FreeBSD init system has not been integrated.
-    exit 0
-fi
-
 # run from the ceph-detect-init directory or from its parent
 : ${CEPH_DETECT_INIT_VIRTUALENV:=/tmp/ceph-detect-init-virtualenv}
 test -d ceph-detect-init && cd ceph-detect-init
index d0d4e06c2eb199085b67770c64e2a76fb565c4c7..d83f7b5fdfea2dea106bb929b41b8e6f3fc5edef 100644 (file)
@@ -32,6 +32,7 @@ from ceph_detect_init import main
 from ceph_detect_init import rhel
 from ceph_detect_init import suse
 from ceph_detect_init import gentoo
+from ceph_detect_init import freebsd
 
 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                     level=logging.DEBUG)
@@ -42,6 +43,9 @@ class TestCephDetectInit(testtools.TestCase):
     def test_alpine(self):
         self.assertEqual('openrc', alpine.choose_init())
 
+    def test_freebsd(self):
+        self.assertEqual('bsdrc', freebsd.choose_init())
+
     def test_centos(self):
         with mock.patch('ceph_detect_init.centos.release',
                         '7.0'):
@@ -145,17 +149,21 @@ class TestCephDetectInit(testtools.TestCase):
             self.assertEqual('unknown', gentoo.choose_init())
 
     def test_get(self):
-        g = ceph_detect_init.get
-        with mock.patch('platform.linux_distribution',
-                        lambda **kwargs: (('unknown', '', ''))):
+        with mock.patch.multiple(
+                'platform',
+                system=lambda: 'Linux',
+                linux_distribution=lambda **kwargs: (('unknown', '', ''))):
+            g = ceph_detect_init.get
             self.assertRaises(exc.UnsupportedPlatform, g)
             try:
                 g()
             except exc.UnsupportedPlatform as e:
                 self.assertIn('Platform is not supported', str(e))
 
-        with mock.patch('platform.linux_distribution',
-                        lambda **kwargs: (('debian', '6.0', ''))):
+        with mock.patch.multiple(
+                'platform',
+                system=lambda: 'Linux',
+                linux_distribution=lambda **kwargs: (('debian', '6.0', ''))):
             distro = ceph_detect_init.get()
             self.assertEqual(debian, distro)
             self.assertEqual('debian', distro.name)
@@ -166,6 +174,24 @@ class TestCephDetectInit(testtools.TestCase):
             self.assertEqual('squeeze', distro.codename)
             self.assertEqual('sysvinit', distro.init)
 
+        with mock.patch.multiple('platform',
+                                 system=lambda: 'FreeBSD',
+                                 release=lambda: '12.0-CURRENT',
+                                 version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
+            distro = ceph_detect_init.get()
+            self.assertEqual(freebsd, distro)
+            self.assertEqual('freebsd', distro.name)
+            self.assertEqual('freebsd', distro.normalized_name)
+            self.assertEqual('freebsd', distro.distro)
+            self.assertFalse(distro.is_el)
+            self.assertEqual('12.0-CURRENT', distro.release)
+            self.assertEqual('r306554M', distro.codename)
+            self.assertEqual('bsdrc', distro.init)
+
+        with mock.patch('platform.system',
+                        lambda: 'cephix'):
+            self.assertRaises(exc.UnsupportedPlatform, ceph_detect_init.get)
+
     def test_get_distro(self):
         g = ceph_detect_init._get_distro
         self.assertEqual(None, g(None))
@@ -205,7 +231,8 @@ class TestCephDetectInit(testtools.TestCase):
         self.assertEqual('gentoo', n('Exherbo'))
         self.assertEqual('gentoo', n('exherbo'))
 
-    def test_platform_information(self):
+    @mock.patch('platform.system', lambda: 'Linux')
+    def test_platform_information_linux(self):
         with mock.patch('platform.linux_distribution',
                         lambda **kwargs: (('debian', '6.0', ''))):
             self.assertEqual(('debian', '6.0', 'squeeze'),
@@ -231,12 +258,22 @@ class TestCephDetectInit(testtools.TestCase):
             self.assertEqual(('debian', 'sid/jessie', 'sid'),
                              ceph_detect_init.platform_information())
 
+    @mock.patch('platform.system', lambda: 'FreeBSD')
+    def test_platform_information_freebsd(self):
+        with mock.patch.multiple('platform',
+                                 release=lambda: '12.0-CURRENT',
+                                 version=lambda: 'FreeBSD 12.0 #1 r306554M:'):
+            self.assertEqual(('freebsd', '12.0-CURRENT', 'r306554M'),
+                             ceph_detect_init.platform_information())
+
     def test_run(self):
         argv = ['--use-rhceph', '--verbose']
         self.assertEqual(0, main.run(argv))
 
-        with mock.patch('platform.linux_distribution',
-                        lambda **kwargs: (('unknown', '', ''))):
+        with mock.patch.multiple(
+                'platform',
+                system=lambda: 'Linux',
+                linux_distribution=lambda **kwargs: (('unknown', '', ''))):
             self.assertRaises(exc.UnsupportedPlatform, main.run, argv)
             self.assertEqual(0, main.run(argv + ['--default=sysvinit']))