Merge lp:~rvb/maas/init-sys-bug-1459338 into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 3956
Proposed branch: lp:~rvb/maas/init-sys-bug-1459338
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 152 lines (+52/-39)
4 files modified
src/provisioningserver/service_monitor.py (+2/-10)
src/provisioningserver/tests/test_service_monitor.py (+6/-29)
src/provisioningserver/utils/__init__.py (+19/-0)
src/provisioningserver/utils/tests/test_utils.py (+25/-0)
To merge this branch: bzr merge lp:~rvb/maas/init-sys-bug-1459338
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Blake Rouse (community) Approve
Review via email: mp+260345@code.launchpad.net

Commit message

Use '/proc/1/comm' to figure out which init system is used.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve
Revision history for this message
Raphaël Badin (rvb) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (80.4 KiB)

The attempt to merge lp:~rvb/maas/init-sys-bug-1459338 into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [81.9 kB]
Get:6 http://security.ubuntu.com trusty-security/universe Sources [25.2 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [273 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [105 kB]
Get:9 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [206 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [118 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [526 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [281 kB]
Get:13 http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en [249 kB]
Get:14 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en [147 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 2,140 kB in 3s (628 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 phantomjs postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr ...

Revision history for this message
Andres Rodriguez (andreserl) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (79.4 KiB)

The attempt to merge lp:~rvb/maas/init-sys-bug-1459338 into lp:maas failed. Below is the output from the failed tests.

Ign http://security.ubuntu.com trusty-security InRelease
Get:1 http://security.ubuntu.com trusty-security Release.gpg [933 B]
Get:2 http://security.ubuntu.com trusty-security Release [63.5 kB]
Ign http://nova.clouds.archive.ubuntu.com trusty InRelease
Ign http://nova.clouds.archive.ubuntu.com trusty-updates InRelease
Hit http://nova.clouds.archive.ubuntu.com trusty Release.gpg
Get:3 http://nova.clouds.archive.ubuntu.com trusty-updates Release.gpg [933 B]
Hit http://nova.clouds.archive.ubuntu.com trusty Release
Get:4 http://nova.clouds.archive.ubuntu.com trusty-updates Release [63.5 kB]
Get:5 http://security.ubuntu.com trusty-security/main Sources [81.9 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/main Sources
Get:6 http://security.ubuntu.com trusty-security/universe Sources [25.2 kB]
Get:7 http://security.ubuntu.com trusty-security/main amd64 Packages [273 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Sources
Hit http://nova.clouds.archive.ubuntu.com trusty/main amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/universe amd64 Packages
Hit http://nova.clouds.archive.ubuntu.com trusty/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en
Get:8 http://nova.clouds.archive.ubuntu.com trusty-updates/main Sources [206 kB]
Get:9 http://security.ubuntu.com trusty-security/universe amd64 Packages [105 kB]
Hit http://security.ubuntu.com trusty-security/main Translation-en
Hit http://security.ubuntu.com trusty-security/universe Translation-en
Get:10 http://nova.clouds.archive.ubuntu.com trusty-updates/universe Sources [118 kB]
Get:11 http://nova.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [526 kB]
Get:12 http://nova.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [282 kB]
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/main Translation-en
Hit http://nova.clouds.archive.ubuntu.com trusty-updates/universe Translation-en
Ign http://nova.clouds.archive.ubuntu.com trusty/main Translation-en_US
Ign http://nova.clouds.archive.ubuntu.com trusty/universe Translation-en_US
Fetched 1,745 kB in 3s (541 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
     --no-install-recommends install apache2 authbind bind9 bind9utils build-essential bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libpq-dev make nodejs-legacy npm pep8 phantomjs postgresql pyflakes python-apt python-bson python-bzrlib python-convoy python-coverage python-crochet python-cssselect python-curtin python-dev python-distro-info python-django python-django-piston python-django-south python-djorm-ext-pgarray python-docutils python-extras python-fixtures python-flake8 python-formencode python-hivex python-httplib2 python-iscpy python-jinja2 python-jsonschema python-lockfile python-lxml python-mock python-netaddr python-netifaces python-...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/service_monitor.py'
2--- src/provisioningserver/service_monitor.py 2015-05-19 13:32:51 +0000
3+++ src/provisioningserver/service_monitor.py 2015-05-27 17:53:59 +0000
4@@ -30,7 +30,7 @@
5 ServiceRegistry,
6 )
7 from provisioningserver.logger.log import get_maas_logger
8-from provisioningserver.utils.shell import has_command_available
9+from provisioningserver.utils import get_init_system
10 from provisioningserver.utils.twisted import (
11 asynchronous,
12 synchronous,
13@@ -91,18 +91,10 @@
14
15 def __init__(self, init_system=None):
16 if init_system is None:
17- init_system = self._get_init_system()
18+ init_system = get_init_system()
19 self.init_system = init_system
20 self.service_locks = {}
21
22- def _get_init_system(self):
23- """Return "upstart" or "systemd" depending on the version of the
24- init system the system is running."""
25- if has_command_available("systemctl"):
26- return "systemd"
27- else:
28- return "upstart"
29-
30 def _get_service_lock(self, service):
31 """Return the lock for service."""
32 if service not in self.service_locks:
33
34=== modified file 'src/provisioningserver/tests/test_service_monitor.py'
35--- src/provisioningserver/tests/test_service_monitor.py 2015-05-19 13:32:51 +0000
36+++ src/provisioningserver/tests/test_service_monitor.py 2015-05-27 17:53:59 +0000
37@@ -73,35 +73,12 @@
38 ServiceRegistry.register_item(service.name, service)
39 return service
40
41- def test_init_determines_init_system_upstart(self):
42-
43- def mock_has_command_available(cmd):
44- if cmd == "systemctl":
45- return False
46- else:
47- raise Exception("Should have been called with systemctl.")
48-
49- mock_has_cmd = self.patch(
50- service_monitor_module, "has_command_available")
51- mock_has_cmd.side_effect = mock_has_command_available
52- service_monitor = ServiceMonitor()
53- self.assertEquals("upstart", service_monitor.init_system)
54- self.assertThat(mock_has_cmd, MockCalledOnceWith("systemctl"))
55-
56- def test_init_determines_init_system_systemd(self):
57-
58- def mock_has_command_available(cmd):
59- if cmd == "systemctl":
60- return True
61- else:
62- raise Exception("Should have been called with systemctl.")
63-
64- mock_has_cmd = self.patch(
65- service_monitor_module, "has_command_available")
66- mock_has_cmd.side_effect = mock_has_command_available
67- service_monitor = ServiceMonitor()
68- self.assertEquals("systemd", service_monitor.init_system)
69- self.assertThat(mock_has_cmd, MockCalledOnceWith("systemctl"))
70+ def test_init_determines_init_system(self):
71+ mock_has_cmd = self.patch(
72+ service_monitor_module, "get_init_system")
73+ mock_has_cmd.return_value = sentinel.init_system
74+ service_monitor = ServiceMonitor()
75+ self.assertEquals(sentinel.init_system, service_monitor.init_system)
76
77 def test__get_service_lock_adds_lock_to_service_locks(self):
78 service_monitor = ServiceMonitor()
79
80=== modified file 'src/provisioningserver/utils/__init__.py'
81--- src/provisioningserver/utils/__init__.py 2015-05-15 22:13:17 +0000
82+++ src/provisioningserver/utils/__init__.py 2015-05-27 17:53:59 +0000
83@@ -515,3 +515,22 @@
84 return command_args
85 else:
86 return ['sudo', '-n'] + command_args
87+
88+
89+FIRST_PROC_COMM = '/proc/1/comm'
90+
91+
92+INIT_SYSTEMS = {'init': 'upstart', 'systemd': 'systemd'}
93+
94+
95+def get_init_system():
96+ """Returns 'upstart' or 'systemd'."""
97+ # Circular imports.
98+ from provisioningserver.utils.fs import read_text_file
99+ init_system = read_text_file(FIRST_PROC_COMM).strip()
100+ try:
101+ return INIT_SYSTEMS[init_system]
102+ except KeyError:
103+ raise ValueError(
104+ "Unable to determine init daemon: "
105+ "unknown comm value for process 1: '%s'" % init_system)
106
107=== modified file 'src/provisioningserver/utils/tests/test_utils.py'
108--- src/provisioningserver/utils/tests/test_utils.py 2015-05-15 21:58:26 +0000
109+++ src/provisioningserver/utils/tests/test_utils.py 2015-05-27 17:53:59 +0000
110@@ -52,6 +52,7 @@
111 escape_py_literal,
112 filter_dict,
113 flatten,
114+ get_init_system,
115 get_cluster_config,
116 locate_config,
117 maas_custom_config_markers,
118@@ -62,6 +63,7 @@
119 in_develop_mode,
120 sudo,
121 )
122+from testtools import ExpectedException
123 from testtools.matchers import (
124 DirExists,
125 EndsWith,
126@@ -704,3 +706,26 @@
127 def test_returns_command_with_sudo_prepended_not_in_develop_mode(self):
128 cmd = [factory.make_name('cmd') for _ in range(3)]
129 self.assertEquals(['sudo', '-n'] + cmd, sudo(cmd))
130+
131+
132+class TestGetInitSystem(MAASTestCase):
133+
134+ def test__identifies_upstart(self):
135+ filename = self.make_file(contents='init')
136+ self.patch(provisioningserver.utils, 'FIRST_PROC_COMM', filename)
137+ self.assertEqual('upstart', get_init_system())
138+
139+ def test__identifies_systemd(self):
140+ filename = self.make_file(contents='systemd')
141+ self.patch(provisioningserver.utils, 'FIRST_PROC_COMM', filename)
142+ self.assertEqual('systemd', get_init_system())
143+
144+ def test__raises_if_unknown(self):
145+ contents = factory.make_name('unknown')
146+ filename = self.make_file(contents=contents)
147+ self.patch(provisioningserver.utils, 'FIRST_PROC_COMM', filename)
148+ expected_message = (
149+ "Unable to determine init daemon: unknown comm value for "
150+ "process 1: '%s'" % contents)
151+ with ExpectedException(ValueError, expected_message):
152+ get_init_system()