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
=== modified file 'charmhelpers/core/host.py'
--- charmhelpers/core/host.py 2017-02-09 22:15:56 +0000
+++ charmhelpers/core/host.py 2017-03-08 06:59:35 +0000
@@ -306,6 +306,8 @@
306306
307def init_is_systemd():307def init_is_systemd():
308 """Return True if the host system uses systemd, False otherwise."""308 """Return True if the host system uses systemd, False otherwise."""
309 if lsb_release()['DISTRIB_CODENAME'] == 'trusty':
310 return False
309 return os.path.isdir(SYSTEMD_SYSTEM)311 return os.path.isdir(SYSTEMD_SYSTEM)
310312
311313
312314
=== modified file 'tests/core/test_host.py'
--- tests/core/test_host.py 2017-02-09 22:15:56 +0000
+++ tests/core/test_host.py 2017-03-08 06:59:35 +0000
@@ -81,20 +81,34 @@
8181
82class HelpersTest(TestCase):82class HelpersTest(TestCase):
8383
84 @patch('charmhelpers.core.host.lsb_release')
84 @patch('os.path')85 @patch('os.path')
85 def test_init_is_systemd_upstart(self, path):86 def test_init_is_systemd_upstart(self, path, lsb_release):
86 """Upstart based init is correctly detected"""87 """Upstart based init is correctly detected"""
88 lsb_release.return_value = {'DISTRIB_CODENAME': 'whatever'}
87 path.isdir.return_value = False89 path.isdir.return_value = False
88 self.assertFalse(host.init_is_systemd())90 self.assertFalse(host.init_is_systemd())
89 path.isdir.assert_called_with('/run/systemd/system')91 path.isdir.assert_called_with('/run/systemd/system')
9092
93 @patch('charmhelpers.core.host.lsb_release')
91 @patch('os.path')94 @patch('os.path')
92 def test_init_is_systemd_system(self, path):95 def test_init_is_systemd_system(self, path, lsb_release):
93 """Systemd based init is correctly detected"""96 """Systemd based init is correctly detected"""
97 lsb_release.return_value = {'DISTRIB_CODENAME': 'whatever'}
94 path.isdir.return_value = True98 path.isdir.return_value = True
95 self.assertTrue(host.init_is_systemd())99 self.assertTrue(host.init_is_systemd())
96 path.isdir.assert_called_with('/run/systemd/system')100 path.isdir.assert_called_with('/run/systemd/system')
97101
102 @patch('charmhelpers.core.host.lsb_release')
103 @patch('os.path')
104 def test_init_is_systemd_trusty(self, path, lsb_release):
105 # Never returns true under trusty, even if the systemd
106 # packages have been installed. lp:1670944
107 lsb_release.return_value = {'DISTRIB_CODENAME': 'trusty'}
108 path.isdir.return_value = True
109 self.assertFalse(host.init_is_systemd())
110 self.assertFalse(path.isdir.called)
111
98 @patch.object(host, 'init_is_systemd')112 @patch.object(host, 'init_is_systemd')
99 @patch('subprocess.call')113 @patch('subprocess.call')
100 def test_runs_service_action(self, mock_call, systemd):114 def test_runs_service_action(self, mock_call, systemd):

Subscribers

People subscribed via source and target branches