summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--cloudinit/distros/__init__.py8
-rw-r--r--cloudinit/distros/rhel.py8
-rw-r--r--tests/unittests/helpers.py10
-rw-r--r--tests/unittests/test_distros/test_generic.py23
5 files changed, 39 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 68b1a459..30885329 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,8 @@
- EC2: know about eu-central-1 availability-zone (LP: #1456684)
- Azure: remove password from on-disk ovf-env.xml (LP: #1443311) [Ben Howard]
- Doc: include information on user-data in OpenStack [Daniel Watkins]
+ - Systemd: check for systemd using sd_booted symantics (LP: #1461201)
+ [Lars Kellogg-Stedman]
0.7.6:
- open 0.7.6
- Enable vendordata on CloudSigma datasource (LP: #1303986)
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index e0cce670..8a947867 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -27,6 +27,7 @@ from six import StringIO
import abc
import os
import re
+import stat
from cloudinit import importer
from cloudinit import log as logging
@@ -89,6 +90,13 @@ class Distro(object):
self._write_hostname(writeable_hostname, self.hostname_conf_fn)
self._apply_hostname(writeable_hostname)
+ def uses_systemd(self):
+ try:
+ res = os.lstat('/run/systemd/system')
+ return stat.S_ISDIR(res.st_mode)
+ except:
+ return False
+
@abc.abstractmethod
def package_command(self, cmd, args=None, pkgs=None):
raise NotImplementedError()
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 30c805a6..812e7002 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -111,14 +111,6 @@ class Distro(distros.Distro):
rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg)
return dev_names
- def uses_systemd(self):
- # Fedora 18 and RHEL 7 were the first adopters in their series
- (dist, vers) = util.system_info()['dist'][:2]
- major = (int)(vers.split('.')[0])
- return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7)
- or (dist.startswith('CentOS Linux') and major >= 7)
- or (dist.startswith('Fedora') and major >= 18))
-
def apply_locale(self, locale, out_fn=None):
if self.uses_systemd():
if not out_fn:
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 61a1f6ff..7f4b8784 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -248,13 +248,15 @@ class FilesystemMockingTestCase(ResourceUsingTestCase):
def patchOS(self, new_root):
patch_funcs = {
- os.path: ['isfile', 'exists', 'islink', 'isdir'],
- os: ['listdir'],
+ os.path: [('isfile', 1), ('exists', 1),
+ ('islink', 1), ('isdir', 1)],
+ os: [('listdir', 1), ('mkdir', 1),
+ ('lstat', 1), ('symlink', 2)],
}
for (mod, funcs) in patch_funcs.items():
- for f in funcs:
+ for f, nargs in funcs:
func = getattr(mod, f)
- trap_func = retarget_many_wrapper(new_root, 1, func)
+ trap_func = retarget_many_wrapper(new_root, nargs, func)
self.patched_funcs.enter_context(
mock.patch.object(mod, f, trap_func))
diff --git a/tests/unittests/test_distros/test_generic.py b/tests/unittests/test_distros/test_generic.py
index 35153f0d..8e3bd78a 100644
--- a/tests/unittests/test_distros/test_generic.py
+++ b/tests/unittests/test_distros/test_generic.py
@@ -194,6 +194,29 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase):
{'primary': 'http://fs-primary-intel',
'security': 'http://security-mirror2-intel'})
+ def test_systemd_in_use(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ os.makedirs('/run/systemd/system')
+ self.assertTrue(d.uses_systemd())
+
+ def test_systemd_not_in_use(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ self.assertFalse(d.uses_systemd())
+
+ def test_systemd_symlink(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ os.makedirs('/run/systemd')
+ os.symlink('/', '/run/systemd/system')
+ self.assertFalse(d.uses_systemd())
# def _get_package_mirror_info(mirror_info, availability_zone=None,
# mirror_filter=util.search_for_mirror):