~jamesodhunt/ubuntu/trusty/upstart/1.12.1

« back to all changes in this revision

Viewing changes to scripts/tests/test_pyupstart_session_init.py

  • Committer: James Hunt
  • Date: 2014-03-11 15:29:02 UTC
  • mfrom: (1436.2.5)
  • Revision ID: james.hunt@ubuntu.com-20140311152902-xszpbkjufkdv6js8
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python3
2
2
# -*- coding: utf-8 -*-
3
3
#---------------------------------------------------------------------
4
 
# Copyright © 2013 Canonical Ltd.
 
4
# Copyright  2013 Canonical Ltd.
5
5
#
6
6
# Author: James Hunt <james.hunt@canonical.com>
7
7
#
30
30
import os
31
31
import sys
32
32
import re
33
 
import json
34
33
 
35
34
base_dir = os.path.abspath(os.path.dirname(__file__))
36
35
module_dir = os.path.normpath(os.path.realpath(base_dir + os.sep + '..'))
81
80
            tmp = '{}{}{}'.format(DEFAULT_SESSION_INSTALL_PATH, os.sep, self.REEXEC_CONF)
82
81
            if os.path.exists(tmp):
83
82
                print('INFO: UPSTART_TEST_USE_INSTALLED_CONF set - using {} rather than {}'.format(tmp, self.reexec_conf))
84
 
                reexec_conf = tmp
 
83
                self.reexec_conf = tmp
85
84
 
86
85
        self.assertTrue(os.path.exists(self.file_bridge_conf))
87
86
        self.assertTrue(os.path.exists(self.reexec_conf))
89
88
        self.upstart = None
90
89
 
91
90
        self.logger = logging.getLogger(self.__class__.__name__)
92
 
        for cmd in UPSTART, INITCTL:
 
91
        for cmd in get_init(), get_initctl():
93
92
            if not os.path.exists(cmd):
94
93
                raise UpstartException('Command %s not found' % cmd)
95
94
 
141
140
    def test_init_start_file_bridge(self):
142
141
        self.start_session_init()
143
142
 
144
 
        # Create the file-bridge job in the correct test location by copying
145
 
        # the session job from the source package.
146
 
        with open(self.file_bridge_conf, 'r', encoding='utf-8') as f:
147
 
            lines = f.readlines()
 
143
        # Create upstart-file-bridge.conf
 
144
        #
 
145
        # Note that we do not use the bundled user job due to our
 
146
        # requirement for a different start condition and different
 
147
        # command options.
 
148
        cmd = '{} --daemon --user --debug'.format(get_file_bridge())
 
149
        lines = """
 
150
        start on startup
 
151
        stop on session-end
 
152
 
 
153
        emits file
 
154
 
 
155
        expect daemon
 
156
        respawn
 
157
        exec {}
 
158
        """.format(cmd)
 
159
 
148
160
        file_bridge = self.upstart.job_create('upstart-file-bridge', lines)
149
161
        self.assertTrue(file_bridge)
150
162
        file_bridge.start()