Merge lp:~stub/charm-helpers/fix-systemd-detection into lp:charm-helpers

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 712
Proposed branch: lp:~stub/charm-helpers/fix-systemd-detection
Merge into: lp:charm-helpers
Diff against target: 53 lines (+18/-2)
2 files modified
charmhelpers/core/host.py (+2/-0)
tests/core/test_host.py (+16/-2)
To merge this branch: bzr merge lp:~stub/charm-helpers/fix-systemd-detection
Reviewer Review Type Date Requested Status
James Page Approve
Tim Van Steenburgh Approve
Chris MacNaughton (community) Approve
Review via email: mp+319281@code.launchpad.net

Description of the change

Per Bug #1670944, trusty charms start failing if the snapd package
is installed on the system. Fix this.

I've just hardcoded the check for trusty, rather than some convoluted
method to attempt to detect if upstart is the default init system,
because we only need this to work under trusty. xenial is fine, and
systemd doesn't exist for precise.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Note that having the snapd package installed is beyond the control of the charm, as it may be pulled in by a subordinate or layer.

Revision history for this message
Chris MacNaughton (chris.macnaughton) wrote :

Looks reasonable to me

review: Approve
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1

review: Approve
Revision history for this message
James Page (james-page) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2017-02-09 22:15:56 +0000
3+++ charmhelpers/core/host.py 2017-03-08 06:59:35 +0000
4@@ -306,6 +306,8 @@
5
6 def init_is_systemd():
7 """Return True if the host system uses systemd, False otherwise."""
8+ if lsb_release()['DISTRIB_CODENAME'] == 'trusty':
9+ return False
10 return os.path.isdir(SYSTEMD_SYSTEM)
11
12
13
14=== modified file 'tests/core/test_host.py'
15--- tests/core/test_host.py 2017-02-09 22:15:56 +0000
16+++ tests/core/test_host.py 2017-03-08 06:59:35 +0000
17@@ -81,20 +81,34 @@
18
19 class HelpersTest(TestCase):
20
21+ @patch('charmhelpers.core.host.lsb_release')
22 @patch('os.path')
23- def test_init_is_systemd_upstart(self, path):
24+ def test_init_is_systemd_upstart(self, path, lsb_release):
25 """Upstart based init is correctly detected"""
26+ lsb_release.return_value = {'DISTRIB_CODENAME': 'whatever'}
27 path.isdir.return_value = False
28 self.assertFalse(host.init_is_systemd())
29 path.isdir.assert_called_with('/run/systemd/system')
30
31+ @patch('charmhelpers.core.host.lsb_release')
32 @patch('os.path')
33- def test_init_is_systemd_system(self, path):
34+ def test_init_is_systemd_system(self, path, lsb_release):
35 """Systemd based init is correctly detected"""
36+ lsb_release.return_value = {'DISTRIB_CODENAME': 'whatever'}
37 path.isdir.return_value = True
38 self.assertTrue(host.init_is_systemd())
39 path.isdir.assert_called_with('/run/systemd/system')
40
41+ @patch('charmhelpers.core.host.lsb_release')
42+ @patch('os.path')
43+ def test_init_is_systemd_trusty(self, path, lsb_release):
44+ # Never returns true under trusty, even if the systemd
45+ # packages have been installed. lp:1670944
46+ lsb_release.return_value = {'DISTRIB_CODENAME': 'trusty'}
47+ path.isdir.return_value = True
48+ self.assertFalse(host.init_is_systemd())
49+ self.assertFalse(path.isdir.called)
50+
51 @patch.object(host, 'init_is_systemd')
52 @patch('subprocess.call')
53 def test_runs_service_action(self, mock_call, systemd):

Subscribers

People subscribed via source and target branches