Merge authors:
James Hunt (jamesodhunt)
Related merge proposals:
https://code.launchpad.net/~jamesodhunt/upstart/fix-python-tests/+merge/195210
proposed by: James Hunt (jamesodhunt)
------------------------------------------------------------
revno: 1595 [merge]
committer: Dimitri John Ledkov <[email protected]>
branch nick: trunk
timestamp: Wed 2014-03-05 10:34:32 +0000
message:
Merge lp:~jamesodhunt/upstart/fix-python-tests
renamed:
scripts/pyupstart.py => scripts/pyupstart.py.in
modified:
scripts/Makefile.am
scripts/tests/test_pyupstart_session_init.py
scripts/tests/test_pyupstart_system_init.py
scripts/pyupstart.py.in
--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk
Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to
https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== modified file 'scripts/Makefile.am'
--- scripts/Makefile.am 2013-08-06 16:54:28 +0000
+++ scripts/Makefile.am 2013-11-14 11:42:05 +0000
@@ -1,5 +1,9 @@
## Process this file with automake to produce Makefile.in
+UPSTART_BINARY = $(abs_top_builddir)/init/init
+INITCTL_BINARY = $(abs_top_builddir)/util/initctl
+FILE_BRIDGE_BINARY = $(abs_top_builddir)/extra/upstart-file-bridge
+
SUBDIRS = data
install_scripts = \
@@ -7,13 +11,26 @@
init-checkconf.sh \
upstart-monitor.py
+noinst_SCRIPTS = \
+ pyupstart.py
+
+CLEANFILES = \
+ pyupstart.py
+
EXTRA_DIST = \
$(install_scripts) \
- pyupstart.py \
+ pyupstart.py.in \
tests/__init__.py \
tests/test_pyupstart_session_init.py \
tests/test_pyupstart_system_init.py
+pyupstart.py: pyupstart.py.in Makefile
+ sed -e 's|[@]built_init_binary[@]|$(UPSTART_BINARY)|g' \
+ -e 's|[@]built_initctl_binary[@]|$(INITCTL_BINARY)|g' \
+ -e 's|[@]built_file_bridge_binary[@]|$(FILE_BRIDGE_BINARY)|g' \
+ $< > $@
+ chmod +x $@
+
dist_man_MANS = \
man/initctl2dot.8 \
man/init-checkconf.8 \
=== renamed file 'scripts/pyupstart.py' => 'scripts/pyupstart.py.in'
--- scripts/pyupstart.py 2014-01-17 15:39:55 +0000
+++ scripts/pyupstart.py.in 2014-03-05 10:34:32 +0000
@@ -32,10 +32,17 @@
VERSION = '0.1'
NAME = 'TestUpstart'
-UPSTART = '/sbin/init'
-INITCTL = '/sbin/initctl'
+# FIXME: should really take account of autoconf prefix
+SYSTEM_UPSTART = '/sbin/init'
+SYSTEM_INITCTL = '/sbin/initctl'
+SYSTEM_FILE_BRIDGE = '/sbin/upstart-file-bridge'
+
+BUILT_UPSTART = '@built_init_binary@'
+BUILT_INITCTL = '@built_initctl_binary@'
+BUILT_FILE_BRIDGE = '@built_file_bridge_binary@'
UPSTART_SESSION_ENV = 'UPSTART_SESSION'
+USE_SYSTEM_BINARIES_ENV = 'UPSTART_TEST_USE_SYSTEM_BINARIES'
UPSTART_STATE_FILE = 'upstart.state'
@@ -77,6 +84,41 @@
#---------------------------------------------------------------------
+def get_init():
+ """
+ Return full path to an appropriate init daemon binary.
+ """
+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
+ binary = SYSTEM_UPSTART
+ else:
+ binary = BUILT_UPSTART
+
+ assert (os.path.exists(binary))
+ return binary
+
+def get_initctl():
+ """
+ Return full path to an appropriate initctl binary.
+ """
+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
+ binary = SYSTEM_INITCTL
+ else:
+ binary = BUILT_INITCTL
+
+ assert (os.path.exists(binary))
+ return binary
+
+def get_file_bridge():
+ """
+ Return full path to an appropriate upstart-file-bridge binary.
+ """
+ if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
+ binary = SYSTEM_FILE_BRIDGE
+ else:
+ binary = BUILT_FILE_BRIDGE
+
+ assert (os.path.exists(binary))
+ return binary
def dbus_encode(str):
"""
@@ -136,7 +178,6 @@
if os.path.exists(path):
return True
time.sleep(0.1)
-
return False
@@ -969,7 +1010,7 @@
sessions = {}
- args = [INITCTL, 'list-sessions']
+ args = [get_initctl(), 'list-sessions']
for line in subprocess.check_output(args,
universal_newlines=True).splitlines():
@@ -1028,6 +1069,9 @@
args = []
pid = os.getpid()
+ init_binary = get_init()
+
+ self.logger.debug('Using init binary %s' % init_binary)
self.conf_dir = \
tempfile.mkdtemp(prefix="%s-confdir-%d-" % (NAME, pid))
@@ -1035,7 +1079,7 @@
self.log_dir = \
tempfile.mkdtemp(prefix="%s-logdir-%d-" % (NAME, pid))
- args.extend([UPSTART, '--user',
+ args.extend([init_binary, '--user',
'--confdir', self.conf_dir,
'--logdir', self.log_dir])
=== modified file 'scripts/tests/test_pyupstart_session_init.py'
--- scripts/tests/test_pyupstart_session_init.py 2014-01-17 15:39:55 +0000
+++ scripts/tests/test_pyupstart_session_init.py 2014-03-05 10:34:32 +0000
@@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#---------------------------------------------------------------------
-# Copyright © 2013 Canonical Ltd.
+# Copyright 2013 Canonical Ltd.
#
# Author: James Hunt <[email protected]>
#
@@ -89,7 +89,7 @@
self.upstart = None
self.logger = logging.getLogger(self.__class__.__name__)
- for cmd in UPSTART, INITCTL:
+ for cmd in get_init(), get_initctl():
if not os.path.exists(cmd):
raise UpstartException('Command %s not found' % cmd)
@@ -141,10 +141,23 @@
def test_init_start_file_bridge(self):
self.start_session_init()
- # Create the file-bridge job in the correct test location by copying
- # the session job from the source package.
- with open(self.file_bridge_conf, 'r', encoding='utf-8') as f:
- lines = f.readlines()
+ # Create upstart-file-bridge.conf
+ #
+ # Note that we do not use the bundled user job due to our
+ # requirement for a different start condition and different
+ # command options.
+ cmd = '{} --daemon --user --debug'.format(get_file_bridge())
+ lines = """
+ start on startup
+ stop on session-end
+
+ emits file
+
+ expect daemon
+ respawn
+ exec {}
+ """.format(cmd)
+
file_bridge = self.upstart.job_create('upstart-file-bridge', lines)
self.assertTrue(file_bridge)
file_bridge.start()
=== modified file 'scripts/tests/test_pyupstart_system_init.py'
--- scripts/tests/test_pyupstart_system_init.py 2014-01-17 15:39:55 +0000
+++ scripts/tests/test_pyupstart_system_init.py 2014-03-05 10:34:32 +0000
@@ -146,7 +146,7 @@
self.assertTrue(os.path.exists(chroot_path))
# Ensure Upstart is installed in the chroot
- chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, INITCTL)
+ chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, get_initctl())
self.assertTrue(os.path.exists(chroot_initctl))
# No sessions should exist before the test starts
@@ -154,7 +154,7 @@
# Create an Upstart chroot session by talking from the chroot
# back to PID 1.
- ret = subprocess.call(['chroot', chroot_path, INITCTL, 'list'])
+ ret = subprocess.call(['chroot', chroot_path, get_initctl(), 'list'])
self.assertEqual(0, ret)
# Ensure a session now exists
--
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/upstart-devel