Merge lp:~jamesodhunt/upstart/fix-python-tests into lp:upstart

Proposed by James Hunt on 2013-11-14
Status: Merged
Merged at revision: 1595
Proposed branch: lp:~jamesodhunt/upstart/fix-python-tests
Merge into: lp:upstart
Diff against target: 226 lines (+90/-16)
4 files modified
scripts/Makefile.am (+18/-1)
scripts/pyupstart.py.in (+51/-7)
scripts/tests/test_pyupstart_session_init.py (+19/-6)
scripts/tests/test_pyupstart_system_init.py (+2/-2)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/fix-python-tests
Reviewer Review Type Date Requested Status
Upstart Reviewers 2013-11-14 Pending
Review via email: mp+195210@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/Makefile.am'
2--- scripts/Makefile.am 2013-08-06 16:54:28 +0000
3+++ scripts/Makefile.am 2013-11-14 11:47:19 +0000
4@@ -1,5 +1,9 @@
5 ## Process this file with automake to produce Makefile.in
6
7+UPSTART_BINARY = $(abs_top_builddir)/init/init
8+INITCTL_BINARY = $(abs_top_builddir)/util/initctl
9+FILE_BRIDGE_BINARY = $(abs_top_builddir)/extra/upstart-file-bridge
10+
11 SUBDIRS = data
12
13 install_scripts = \
14@@ -7,13 +11,26 @@
15 init-checkconf.sh \
16 upstart-monitor.py
17
18+noinst_SCRIPTS = \
19+ pyupstart.py
20+
21+CLEANFILES = \
22+ pyupstart.py
23+
24 EXTRA_DIST = \
25 $(install_scripts) \
26- pyupstart.py \
27+ pyupstart.py.in \
28 tests/__init__.py \
29 tests/test_pyupstart_session_init.py \
30 tests/test_pyupstart_system_init.py
31
32+pyupstart.py: pyupstart.py.in Makefile
33+ sed -e 's|[@]built_init_binary[@]|$(UPSTART_BINARY)|g' \
34+ -e 's|[@]built_initctl_binary[@]|$(INITCTL_BINARY)|g' \
35+ -e 's|[@]built_file_bridge_binary[@]|$(FILE_BRIDGE_BINARY)|g' \
36+ $< > $@
37+ chmod +x $@
38+
39 dist_man_MANS = \
40 man/initctl2dot.8 \
41 man/init-checkconf.8 \
42
43=== renamed file 'scripts/pyupstart.py' => 'scripts/pyupstart.py.in'
44--- scripts/pyupstart.py 2013-09-12 10:56:22 +0000
45+++ scripts/pyupstart.py.in 2013-11-14 11:47:19 +0000
46@@ -32,10 +32,17 @@
47 VERSION = '0.1'
48 NAME = 'TestUpstart'
49
50-UPSTART = '/sbin/init'
51-INITCTL = '/sbin/initctl'
52+# FIXME: should really take account of autoconf prefix
53+SYSTEM_UPSTART = '/sbin/init'
54+SYSTEM_INITCTL = '/sbin/initctl'
55+SYSTEM_FILE_BRIDGE = '/sbin/upstart-file-bridge'
56+
57+BUILT_UPSTART = '@built_init_binary@'
58+BUILT_INITCTL = '@built_initctl_binary@'
59+BUILT_FILE_BRIDGE = '@built_file_bridge_binary@'
60
61 UPSTART_SESSION_ENV = 'UPSTART_SESSION'
62+USE_SYSTEM_BINARIES_ENV = 'UPSTART_TEST_USE_SYSTEM_BINARIES'
63
64 UPSTART_STATE_FILE = 'upstart.state'
65
66@@ -77,6 +84,41 @@
67
68 #---------------------------------------------------------------------
69
70+def get_init():
71+ """
72+ Return full path to an appropriate init daemon binary.
73+ """
74+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
75+ binary = SYSTEM_UPSTART
76+ else:
77+ binary = BUILT_UPSTART
78+
79+ assert (os.path.exists(binary))
80+ return binary
81+
82+def get_initctl():
83+ """
84+ Return full path to an appropriate initctl binary.
85+ """
86+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
87+ binary = SYSTEM_INITCTL
88+ else:
89+ binary = BUILT_INITCTL
90+
91+ assert (os.path.exists(binary))
92+ return binary
93+
94+def get_file_bridge():
95+ """
96+ Return full path to an appropriate upstart-file-bridge binary.
97+ """
98+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
99+ binary = SYSTEM_FILE_BRIDGE
100+ else:
101+ binary = BUILT_FILE_BRIDGE
102+
103+ assert (os.path.exists(binary))
104+ return binary
105
106 def dbus_encode(str):
107 """
108@@ -136,7 +178,6 @@
109 if os.path.exists(path):
110 return True
111 time.sleep(0.1)
112-
113 return False
114
115
116@@ -925,8 +966,8 @@
117 """
118 Stop the instance and cleanup.
119
120- Note: If the instance specified retain when created, this will
121- be a NOP.
122+ Note: If the instance specified retain when created, this will
123+ be a NOP.
124 """
125 if not self.job.retain:
126 self.stop()
127@@ -969,7 +1010,7 @@
128
129 sessions = {}
130
131- args = [INITCTL, 'list-sessions']
132+ args = [get_initctl(), 'list-sessions']
133
134 for line in subprocess.check_output(args,
135 universal_newlines=True).splitlines():
136@@ -1028,6 +1069,9 @@
137 args = []
138
139 pid = os.getpid()
140+ init_binary = get_init()
141+
142+ self.logger.debug('Using init binary %s' % init_binary)
143
144 self.conf_dir = \
145 tempfile.mkdtemp(prefix="%s-confdir-%d-" % (NAME, pid))
146@@ -1035,7 +1079,7 @@
147 self.log_dir = \
148 tempfile.mkdtemp(prefix="%s-logdir-%d-" % (NAME, pid))
149
150- args.extend([UPSTART, '--user',
151+ args.extend([init_binary, '--user',
152 '--confdir', self.conf_dir,
153 '--logdir', self.log_dir])
154
155
156=== modified file 'scripts/tests/test_pyupstart_session_init.py'
157--- scripts/tests/test_pyupstart_session_init.py 2013-11-03 00:28:07 +0000
158+++ scripts/tests/test_pyupstart_session_init.py 2013-11-14 11:47:19 +0000
159@@ -1,7 +1,7 @@
160 #!/usr/bin/python3
161 # -*- coding: utf-8 -*-
162 #---------------------------------------------------------------------
163-# Copyright © 2013 Canonical Ltd.
164+# Copyright 2013 Canonical Ltd.
165 #
166 # Author: James Hunt <james.hunt@canonical.com>
167 #
168@@ -89,7 +89,7 @@
169 self.upstart = None
170
171 self.logger = logging.getLogger(self.__class__.__name__)
172- for cmd in UPSTART, INITCTL:
173+ for cmd in get_init(), get_initctl():
174 if not os.path.exists(cmd):
175 raise UpstartException('Command %s not found' % cmd)
176
177@@ -141,10 +141,23 @@
178 def test_init_start_file_bridge(self):
179 self.start_session_init()
180
181- # Create the file-bridge job in the correct test location by copying
182- # the session job from the source package.
183- with open(self.file_bridge_conf, 'r', encoding='utf-8') as f:
184- lines = f.readlines()
185+ # Create upstart-file-bridge.conf
186+ #
187+ # Note that we do not use the bundled user job due to our
188+ # requirement for a different start condition and different
189+ # command options.
190+ cmd = '{} --daemon --user --debug'.format(get_file_bridge())
191+ lines = """
192+ start on startup
193+ stop on session-end
194+
195+ emits file
196+
197+ expect daemon
198+ respawn
199+ exec {}
200+ """.format(cmd)
201+
202 file_bridge = self.upstart.job_create('upstart-file-bridge', lines)
203 self.assertTrue(file_bridge)
204 file_bridge.start()
205
206=== modified file 'scripts/tests/test_pyupstart_system_init.py'
207--- scripts/tests/test_pyupstart_system_init.py 2013-09-12 10:56:22 +0000
208+++ scripts/tests/test_pyupstart_system_init.py 2013-11-14 11:47:19 +0000
209@@ -134,7 +134,7 @@
210 self.assertTrue(os.path.exists(chroot_path))
211
212 # Ensure Upstart is installed in the chroot
213- chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, INITCTL)
214+ chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, get_initctl())
215 self.assertTrue(os.path.exists(chroot_initctl))
216
217 # No sessions should exist before the test starts
218@@ -142,7 +142,7 @@
219
220 # Create an Upstart chroot session by talking from the chroot
221 # back to PID 1.
222- ret = subprocess.call(['chroot', chroot_path, INITCTL, 'list'])
223+ ret = subprocess.call(['chroot', chroot_path, get_initctl(), 'list'])
224 self.assertEqual(0, ret)
225
226 # Ensure a session now exists

Subscribers

People subscribed via source and target branches