diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-06-10 12:30:02 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-06-10 12:30:02 -0400 |
commit | 162ce6a5635574e8dba0be3e06d313a18b46adc6 (patch) | |
tree | bdbd06e2ddee5c539ff826488a082d6d5f574a62 /tests/unittests | |
parent | 0f3736ab501ceebaa3c9f5c7543b6218637cb6c7 (diff) | |
parent | 8db399f9149a81de5d65f0759792766ecd509ab3 (diff) | |
download | vyos-cloud-init-162ce6a5635574e8dba0be3e06d313a18b46adc6.tar.gz vyos-cloud-init-162ce6a5635574e8dba0be3e06d313a18b46adc6.zip |
check for systemd using sd_booted() semantics
The existing code determines if systemd is in use by looking at the
distribution name and version. This is prone to error because:
- RHEL derivatives other than CentOS (e.g., Scientific Linux) will fail
this test
- Distributions that are not derived from RHEL also use systemd
This patch makes cloud-init use the same logic that is used in systemd's
sd_booted() method
http://www.freedesktop.org/software/systemd/man/sd_booted.html
LP: #1461201
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/helpers.py | 10 | ||||
-rw-r--r-- | tests/unittests/test_distros/test_generic.py | 23 |
2 files changed, 29 insertions, 4 deletions
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): |