]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_detect_init: Add support for ALT Linux 27028/head
authorAndrey Bychkov <mrdrew@altlinux.org>
Mon, 18 Mar 2019 09:47:48 +0000 (12:47 +0300)
committerAndrey Bychkov <mrdrew@altlinux.org>
Mon, 18 Mar 2019 09:47:48 +0000 (12:47 +0300)
Signed-off-by: Andrey Bychkov <mrdrew@altlinux.org>
src/ceph-detect-init/ceph_detect_init/__init__.py
src/ceph-detect-init/ceph_detect_init/alt/__init__.py [new file with mode: 0644]
src/ceph-detect-init/tests/test_all.py

index b8ac387d03fdb2583e35f80b6ede89d804d2ad00..f65978992b5e3bc4c0cdc8d13c3f9747a28d98c3 100644 (file)
@@ -14,6 +14,7 @@
 # GNU Library Public License for more details.
 #
 from ceph_detect_init import alpine
+from ceph_detect_init import alt
 from ceph_detect_init import arch
 from ceph_detect_init import centos
 from ceph_detect_init import debian
@@ -61,6 +62,7 @@ def _get_distro(distro, use_rhceph=False):
     distro = _normalized_distro_name(distro)
     distributions = {
         'alpine': alpine,
+        'alt': alt,
         'arch': arch,
         'debian': debian,
         'ubuntu': debian,
@@ -104,6 +106,8 @@ def _normalized_distro_name(distro):
         return 'gentoo'
     elif distro.startswith('virtuozzo'):
         return 'virtuozzo'
+    elif distro.startswith(('alt', 'altlinux', 'basealt', 'alt linux')):
+        return 'alt'
     return distro
 
 
diff --git a/src/ceph-detect-init/ceph_detect_init/alt/__init__.py b/src/ceph-detect-init/ceph_detect_init/alt/__init__.py
new file mode 100644 (file)
index 0000000..59add20
--- /dev/null
@@ -0,0 +1,18 @@
+import os
+
+distro = None
+release = None
+codename = None
+
+
+def choose_init():
+    """Select a init system
+
+    Returns the name of a init system (upstart, sysvinit ...).
+    """
+    # yes, this is heuristics
+    if os.path.isdir('/run/systemd/system'):
+        return 'systemd'
+
+    if os.path.isfile('/sbin/init') and not os.path.islink('/sbin/init'):
+        return 'sysvinit'
index dfdf16b2c0c4991fd9881c1541dab8befa10704c..934bb4054d7074cda9e9ffbb052bba17e9aafc61 100644 (file)
@@ -24,6 +24,7 @@ import testtools
 
 import ceph_detect_init
 from ceph_detect_init import alpine
+from ceph_detect_init import alt
 from ceph_detect_init import arch
 from ceph_detect_init import centos
 from ceph_detect_init import debian
@@ -46,6 +47,19 @@ class TestCephDetectInit(testtools.TestCase):
     def test_alpine(self):
         self.assertEqual('openrc', alpine.choose_init())
 
+    def test_alt(self):
+        with mock.patch.multiple('os.path',
+                                 isdir=lambda x: x == '/run/systemd/system'):
+            self.assertEqual('systemd', alt.choose_init())
+
+        with mock.patch.multiple('os.path',
+                                 isdir=lambda x: False,
+                                 isfile=lambda x: x == '/sbin/init',
+                                 islink=lambda x: x != '/sbin/init'):
+            with mock.patch.multiple('subprocess',
+                                     call=lambda *args, **kwargs: 1):
+                self.assertEqual('sysvinit', alt.choose_init())
+
     def test_arch(self):
         self.assertEqual('systemd', arch.choose_init())
 
@@ -222,6 +236,7 @@ class TestCephDetectInit(testtools.TestCase):
         self.assertEqual(rhel, g('redhat', use_rhceph=True))
         self.assertEqual(gentoo, g('gentoo'))
         self.assertEqual(centos, g('virtuozzo'))
+        self.assertEqual(alt, g('alt'))
 
     def test_normalized_distro_name(self):
         n = ceph_detect_init._normalized_distro_name
@@ -252,6 +267,10 @@ class TestCephDetectInit(testtools.TestCase):
         self.assertEqual('gentoo', n('Exherbo'))
         self.assertEqual('gentoo', n('exherbo'))
         self.assertEqual('virtuozzo', n('Virtuozzo Linux'))
+        self.assertEqual('alt', n('ALTLinux'))
+        self.assertEqual('alt', n('ALT'))
+        self.assertEqual('alt', n('BaseALT'))
+        self.assertEqual('alt', n('ALT Linux'))
 
     @mock.patch('os.path.isfile', lambda path: False)
     @mock.patch('platform.system', lambda: 'Linux')