]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-detect-init: Gentoo support.
authorRobin H. Johnson <robin.johnson@dreamhost.com>
Sun, 27 Mar 2016 09:31:29 +0000 (02:31 -0700)
committerRobin H. Johnson <robin.johnson@dreamhost.com>
Tue, 5 Apr 2016 21:38:00 +0000 (21:38 +0000)
Gentoo now supported by ceph-detect-init for usage with ceph-disk.
Differs slightly from the existing distros, because it offers user
choice between multiple init systems (only openrc & systemd supported
for now).

It also doesn't have ANY value for the LSB codename field, so tweak the
exception handling slightly to not trigger UnsupportedPlatform.

Also includes support for some Gentoo offshoots with Ceph packages:
Funtoo, Exherbo.

Signed-off-by: Robin H. Johnson <robin.johnson@dreamhost.com>
src/ceph-detect-init/ceph_detect_init/__init__.py
src/ceph-detect-init/ceph_detect_init/gentoo/__init__.py [new file with mode: 0644]
src/ceph-detect-init/tests/test_all.py

index a2bcc7cf277c908dfdbd8dc2c0a80a2e5aae6fcc..46f6a1d9262a1124c3f8abb81af819d691fe7a41 100644 (file)
@@ -19,13 +19,16 @@ from ceph_detect_init import exc
 from ceph_detect_init import fedora
 from ceph_detect_init import rhel
 from ceph_detect_init import suse
+from ceph_detect_init import gentoo
 import logging
 import platform
 
 
 def get(use_rhceph=False):
     distro_name, release, codename = platform_information()
-    if not codename or not _get_distro(distro_name):
+    # Not all distributions have a concept that maps to codenames
+    # (or even releases really)
+    if not codename and not _get_distro(distro_name):
         raise exc.UnsupportedPlatform(
             distro=distro_name,
             codename=codename,
@@ -57,6 +60,9 @@ def _get_distro(distro, use_rhceph=False):
         'redhat': centos,
         'fedora': fedora,
         'suse': suse,
+        'gentoo': gentoo,
+        'funtoo': gentoo,
+        'exherbo': gentoo,
     }
 
     if distro == 'redhat' and use_rhceph:
@@ -75,6 +81,8 @@ def _normalized_distro_name(distro):
         return 'suse'
     elif distro.startswith('centos'):
         return 'centos'
+    elif distro.startswith(('gentoo', 'funtoo', 'exherbo')):
+        return 'gentoo'
     return distro
 
 
diff --git a/src/ceph-detect-init/ceph_detect_init/gentoo/__init__.py b/src/ceph-detect-init/ceph_detect_init/gentoo/__init__.py
new file mode 100644 (file)
index 0000000..e5e0fcb
--- /dev/null
@@ -0,0 +1,37 @@
+import os
+distro = None
+release = None
+codename = None
+
+
+# From ceph-disk, but there is no way to access it since it's not in a module
+def is_systemd():
+    """
+    Detect whether systemd is running;
+    WARNING: not mutually exclusive with openrc
+    """
+    with open('/proc/1/comm', 'rb') as i:
+        for line in i:
+            if 'systemd' in line:
+                return True
+    return False
+
+
+def is_openrc():
+    """
+    Detect whether openrc is running.
+    """
+    OPENRC_CGROUP = '/sys/fs/cgroup/openrc'
+    return os.path.isdir(OPENRC_CGROUP)
+
+
+def choose_init():
+    """Select a init system
+
+    Returns the name of a init system (upstart, sysvinit ...).
+    """
+    if is_openrc():
+        return 'openrc'
+    if is_systemd():
+        return 'systemd'
+    return 'unknown'
index 22cff5bca93607ecc32fdbda09e73de9a0f50eff..c6e9e30d8e01b30f2d13a0a80b30d32e2f887722 100644 (file)
@@ -30,6 +30,7 @@ from ceph_detect_init import fedora
 from ceph_detect_init import main
 from ceph_detect_init import rhel
 from ceph_detect_init import suse
+from ceph_detect_init import gentoo
 
 logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                     level=logging.DEBUG)
@@ -95,6 +96,44 @@ class TestCephDetectInit(testtools.TestCase):
                         '13.2'):
             self.assertEqual('systemd', suse.choose_init())
 
+    def test_gentoo_is_openrc(self):
+        with mock.patch('os.path.isdir', return_value=True):
+            self.assertEqual(gentoo.is_openrc(), True)
+        with mock.patch('os.path.isdir', return_value=False):
+            self.assertEqual(gentoo.is_openrc(), False)
+
+    def test_gentoo_is_systemd(self):
+        f = mock.mock_open(read_data='systemd')
+        with mock.patch('__main__.file', f, create=True) as m:
+            self.assertEqual(gentoo.is_systemd(), True)
+            m.assert_called_once_with('/proc/1/comm')
+        f = mock.mock_open(read_data='init')
+        with mock.patch('__main__.file', f, create=True) as m:
+            self.assertEqual(gentoo.is_systemd(), False)
+            m.assert_called_once_with('/proc/1/comm')
+        f = mock.mock_open(read_data='upstart')
+        with mock.patch('__main__.file', f, create=True) as m:
+            self.assertEqual(gentoo.is_systemd(), False)
+            m.assert_called_once_with('/proc/1/comm')
+
+    def test_gentoo(self):
+        with mock.patch.multiple('ceph_detect_init.gentoo',
+                is_systemd=(lambda: True),
+                is_openrc=(lambda: True)):
+            self.assertEqual('openrc', gentoo.choose_init())
+        with mock.patch.multiple('ceph_detect_init.gentoo',
+                is_systemd=(lambda: True),
+                is_openrc=(lambda: False)):
+            self.assertEqual('systemd', gentoo.choose_init())
+        with mock.patch.multiple('ceph_detect_init.gentoo',
+                is_systemd=(lambda: False),
+                is_openrc=(lambda: True)):
+            self.assertEqual('openrc', gentoo.choose_init())
+        with mock.patch.multiple('ceph_detect_init.gentoo',
+                is_systemd=(lambda: False),
+                is_openrc=(lambda: False)):
+            self.assertEqual('unknown', gentoo.choose_init())
+
     def test_get(self):
         g = ceph_detect_init.get
         with mock.patch('platform.linux_distribution',
@@ -127,6 +166,7 @@ class TestCephDetectInit(testtools.TestCase):
         self.assertEqual(fedora, g('fedora'))
         self.assertEqual(suse, g('suse'))
         self.assertEqual(rhel, g('redhat', use_rhceph=True))
+        self.assertEqual(gentoo, g('gentoo'))
 
     def test_normalized_distro_name(self):
         n = ceph_detect_init._normalized_distro_name
@@ -148,6 +188,12 @@ class TestCephDetectInit(testtools.TestCase):
         self.assertEqual('debian', n('debian'))
         self.assertEqual('ubuntu', n('Ubuntu'))
         self.assertEqual('ubuntu', n('ubuntu'))
+        self.assertEqual('gentoo', n('Gentoo'))
+        self.assertEqual('gentoo', n('gentoo'))
+        self.assertEqual('gentoo', n('Funtoo'))
+        self.assertEqual('gentoo', n('funtoo'))
+        self.assertEqual('gentoo', n('Exherbo'))
+        self.assertEqual('gentoo', n('exherbo'))
 
     def test_platform_information(self):
         with mock.patch('platform.linux_distribution',