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

Proposed by James Hunt
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 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
=== modified file 'scripts/Makefile.am'
--- scripts/Makefile.am 2013-08-06 16:54:28 +0000
+++ scripts/Makefile.am 2013-11-14 11:47:19 +0000
@@ -1,5 +1,9 @@
1## Process this file with automake to produce Makefile.in1## Process this file with automake to produce Makefile.in
22
3UPSTART_BINARY = $(abs_top_builddir)/init/init
4INITCTL_BINARY = $(abs_top_builddir)/util/initctl
5FILE_BRIDGE_BINARY = $(abs_top_builddir)/extra/upstart-file-bridge
6
3SUBDIRS = data7SUBDIRS = data
48
5install_scripts = \9install_scripts = \
@@ -7,13 +11,26 @@
7 init-checkconf.sh \11 init-checkconf.sh \
8 upstart-monitor.py12 upstart-monitor.py
913
14noinst_SCRIPTS = \
15 pyupstart.py
16
17CLEANFILES = \
18 pyupstart.py
19
10EXTRA_DIST = \20EXTRA_DIST = \
11 $(install_scripts) \21 $(install_scripts) \
12 pyupstart.py \22 pyupstart.py.in \
13 tests/__init__.py \23 tests/__init__.py \
14 tests/test_pyupstart_session_init.py \24 tests/test_pyupstart_session_init.py \
15 tests/test_pyupstart_system_init.py25 tests/test_pyupstart_system_init.py
1626
27pyupstart.py: pyupstart.py.in Makefile
28 sed -e 's|[@]built_init_binary[@]|$(UPSTART_BINARY)|g' \
29 -e 's|[@]built_initctl_binary[@]|$(INITCTL_BINARY)|g' \
30 -e 's|[@]built_file_bridge_binary[@]|$(FILE_BRIDGE_BINARY)|g' \
31 $< > $@
32 chmod +x $@
33
17dist_man_MANS = \34dist_man_MANS = \
18 man/initctl2dot.8 \35 man/initctl2dot.8 \
19 man/init-checkconf.8 \36 man/init-checkconf.8 \
2037
=== renamed file 'scripts/pyupstart.py' => 'scripts/pyupstart.py.in'
--- scripts/pyupstart.py 2013-09-12 10:56:22 +0000
+++ scripts/pyupstart.py.in 2013-11-14 11:47:19 +0000
@@ -32,10 +32,17 @@
32VERSION = '0.1'32VERSION = '0.1'
33NAME = 'TestUpstart'33NAME = 'TestUpstart'
3434
35UPSTART = '/sbin/init'35# FIXME: should really take account of autoconf prefix
36INITCTL = '/sbin/initctl'36SYSTEM_UPSTART = '/sbin/init'
37SYSTEM_INITCTL = '/sbin/initctl'
38SYSTEM_FILE_BRIDGE = '/sbin/upstart-file-bridge'
39
40BUILT_UPSTART = '@built_init_binary@'
41BUILT_INITCTL = '@built_initctl_binary@'
42BUILT_FILE_BRIDGE = '@built_file_bridge_binary@'
3743
38UPSTART_SESSION_ENV = 'UPSTART_SESSION'44UPSTART_SESSION_ENV = 'UPSTART_SESSION'
45USE_SYSTEM_BINARIES_ENV = 'UPSTART_TEST_USE_SYSTEM_BINARIES'
3946
40UPSTART_STATE_FILE = 'upstart.state'47UPSTART_STATE_FILE = 'upstart.state'
4148
@@ -77,6 +84,41 @@
7784
78#---------------------------------------------------------------------85#---------------------------------------------------------------------
7986
87def get_init():
88 """
89 Return full path to an appropriate init daemon binary.
90 """
91 if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
92 binary = SYSTEM_UPSTART
93 else:
94 binary = BUILT_UPSTART
95
96 assert (os.path.exists(binary))
97 return binary
98
99def get_initctl():
100 """
101 Return full path to an appropriate initctl binary.
102 """
103 if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
104 binary = SYSTEM_INITCTL
105 else:
106 binary = BUILT_INITCTL
107
108 assert (os.path.exists(binary))
109 return binary
110
111def get_file_bridge():
112 """
113 Return full path to an appropriate upstart-file-bridge binary.
114 """
115 if os.environ.get(USE_SYSTEM_BINARIES_ENV, None):
116 binary = SYSTEM_FILE_BRIDGE
117 else:
118 binary = BUILT_FILE_BRIDGE
119
120 assert (os.path.exists(binary))
121 return binary
80122
81def dbus_encode(str):123def dbus_encode(str):
82 """124 """
@@ -136,7 +178,6 @@
136 if os.path.exists(path):178 if os.path.exists(path):
137 return True179 return True
138 time.sleep(0.1)180 time.sleep(0.1)
139
140 return False181 return False
141182
142183
@@ -925,8 +966,8 @@
925 """966 """
926 Stop the instance and cleanup.967 Stop the instance and cleanup.
927968
928 Note: If the instance specified retain when created, this will969 Note: If the instance specified retain when created, this will
929 be a NOP.970 be a NOP.
930 """971 """
931 if not self.job.retain:972 if not self.job.retain:
932 self.stop()973 self.stop()
@@ -969,7 +1010,7 @@
9691010
970 sessions = {}1011 sessions = {}
9711012
972 args = [INITCTL, 'list-sessions']1013 args = [get_initctl(), 'list-sessions']
9731014
974 for line in subprocess.check_output(args,1015 for line in subprocess.check_output(args,
975 universal_newlines=True).splitlines():1016 universal_newlines=True).splitlines():
@@ -1028,6 +1069,9 @@
1028 args = []1069 args = []
10291070
1030 pid = os.getpid()1071 pid = os.getpid()
1072 init_binary = get_init()
1073
1074 self.logger.debug('Using init binary %s' % init_binary)
10311075
1032 self.conf_dir = \1076 self.conf_dir = \
1033 tempfile.mkdtemp(prefix="%s-confdir-%d-" % (NAME, pid))1077 tempfile.mkdtemp(prefix="%s-confdir-%d-" % (NAME, pid))
@@ -1035,7 +1079,7 @@
1035 self.log_dir = \1079 self.log_dir = \
1036 tempfile.mkdtemp(prefix="%s-logdir-%d-" % (NAME, pid))1080 tempfile.mkdtemp(prefix="%s-logdir-%d-" % (NAME, pid))
10371081
1038 args.extend([UPSTART, '--user',1082 args.extend([init_binary, '--user',
1039 '--confdir', self.conf_dir,1083 '--confdir', self.conf_dir,
1040 '--logdir', self.log_dir])1084 '--logdir', self.log_dir])
10411085
10421086
=== modified file 'scripts/tests/test_pyupstart_session_init.py'
--- scripts/tests/test_pyupstart_session_init.py 2013-11-03 00:28:07 +0000
+++ scripts/tests/test_pyupstart_session_init.py 2013-11-14 11:47:19 +0000
@@ -1,7 +1,7 @@
1#!/usr/bin/python31#!/usr/bin/python3
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3#---------------------------------------------------------------------3#---------------------------------------------------------------------
4# Copyright © 2013 Canonical Ltd.4# Copyright 2013 Canonical Ltd.
5#5#
6# Author: James Hunt <james.hunt@canonical.com>6# Author: James Hunt <james.hunt@canonical.com>
7#7#
@@ -89,7 +89,7 @@
89 self.upstart = None89 self.upstart = None
9090
91 self.logger = logging.getLogger(self.__class__.__name__)91 self.logger = logging.getLogger(self.__class__.__name__)
92 for cmd in UPSTART, INITCTL:92 for cmd in get_init(), get_initctl():
93 if not os.path.exists(cmd):93 if not os.path.exists(cmd):
94 raise UpstartException('Command %s not found' % cmd)94 raise UpstartException('Command %s not found' % cmd)
9595
@@ -141,10 +141,23 @@
141 def test_init_start_file_bridge(self):141 def test_init_start_file_bridge(self):
142 self.start_session_init()142 self.start_session_init()
143143
144 # Create the file-bridge job in the correct test location by copying144 # Create upstart-file-bridge.conf
145 # the session job from the source package.145 #
146 with open(self.file_bridge_conf, 'r', encoding='utf-8') as f:146 # Note that we do not use the bundled user job due to our
147 lines = f.readlines()147 # requirement for a different start condition and different
148 # command options.
149 cmd = '{} --daemon --user --debug'.format(get_file_bridge())
150 lines = """
151 start on startup
152 stop on session-end
153
154 emits file
155
156 expect daemon
157 respawn
158 exec {}
159 """.format(cmd)
160
148 file_bridge = self.upstart.job_create('upstart-file-bridge', lines)161 file_bridge = self.upstart.job_create('upstart-file-bridge', lines)
149 self.assertTrue(file_bridge)162 self.assertTrue(file_bridge)
150 file_bridge.start()163 file_bridge.start()
151164
=== modified file 'scripts/tests/test_pyupstart_system_init.py'
--- scripts/tests/test_pyupstart_system_init.py 2013-09-12 10:56:22 +0000
+++ scripts/tests/test_pyupstart_system_init.py 2013-11-14 11:47:19 +0000
@@ -134,7 +134,7 @@
134 self.assertTrue(os.path.exists(chroot_path))134 self.assertTrue(os.path.exists(chroot_path))
135135
136 # Ensure Upstart is installed in the chroot136 # Ensure Upstart is installed in the chroot
137 chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, INITCTL)137 chroot_initctl = '{}{}{}'.format(chroot_path, os.sep, get_initctl())
138 self.assertTrue(os.path.exists(chroot_initctl))138 self.assertTrue(os.path.exists(chroot_initctl))
139139
140 # No sessions should exist before the test starts140 # No sessions should exist before the test starts
@@ -142,7 +142,7 @@
142142
143 # Create an Upstart chroot session by talking from the chroot143 # Create an Upstart chroot session by talking from the chroot
144 # back to PID 1.144 # back to PID 1.
145 ret = subprocess.call(['chroot', chroot_path, INITCTL, 'list'])145 ret = subprocess.call(['chroot', chroot_path, get_initctl(), 'list'])
146 self.assertEqual(0, ret)146 self.assertEqual(0, ret)
147147
148 # Ensure a session now exists148 # Ensure a session now exists

Subscribers

People subscribed via source and target branches