~ubuntu-branches/ubuntu/saucy/system-image/saucy-proposed

« back to all changes in this revision

Viewing changes to systemimage/testing/controller.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2013-07-30 11:56:33 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20130730115633-l3eclt78gz5632e7
Tags: 0.9.2-0ubuntu1
* New upstream release.
  - LP: #1206558 - Run system-image-dbus on the system bus.
  - LP: #1206523 - Install policy file com.canonical.SystemImage.conf
    into /etc/dbus-1/system.d/
  - Use full path to executable in dbus service file.
  - Move system-image-dbus executable to /usr/sbin
  - client.ini: Bump dbus timeout to 10 minutes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
import os
 
25
import pwd
25
26
import sys
26
27
import time
27
28
import dbus
50
51
    def __init__(self, testing_mode='live'):
51
52
        self._stack = ExitStack()
52
53
        self.tmpdir = self._stack.enter_context(temporary_directory())
53
 
        self.config_path = os.path.join(self.tmpdir, 'dbus-session.conf')
 
54
        self.config_path = os.path.join(self.tmpdir, 'dbus-system.conf')
54
55
        self.ini_path = None
55
56
        self.serverdir = self._stack.enter_context(temporary_directory())
56
57
        self._testing_mode = testing_mode
57
58
 
58
59
    def _setup(self):
59
 
        # Set up the dbus-daemon session configuration file.
60
 
        with open(test_data_path('dbus-session.conf.in'),
 
60
        # Set up the dbus-daemon system configuration file.
 
61
        with open(test_data_path('dbus-system.conf.in'),
61
62
                  'r', encoding='utf-8') as fp:
62
63
            template = fp.read()
63
 
        config = template.format(tmpdir=self.tmpdir)
 
64
        username = pwd.getpwuid(os.getuid()).pw_name
 
65
        config = template.format(tmpdir=self.tmpdir, user=username)
64
66
        with open(self.config_path, 'w', encoding='utf-8') as fp:
65
67
            fp.write(config)
 
68
        with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
 
69
            fp.write(config)
66
70
        # We need a client.ini file for the subprocess.
67
71
        ini_tmpdir = self._stack.enter_context(temporary_directory())
68
72
        ini_vardir = self._stack.enter_context(temporary_directory())
119
123
        dbus_address = lines[0].strip()
120
124
        daemon_pid = int(lines[1].strip())
121
125
        self._stack.callback(self._kill, daemon_pid)
122
 
        #print('DBUS_SESSION_BUS_ADDRESS={}'.format(dbus_address))
 
126
        #print("DBUS_SYSTEM_BUS_ADDRESS='{}'".format(dbus_address))
123
127
        # Set the service's address into the environment for rendezvous.
124
 
        self._stack.enter_context(reset_envar('DBUS_SESSION_BUS_ADDRESS'))
125
 
        os.environ['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
 
128
        self._stack.enter_context(reset_envar('DBUS_SYSTEM_BUS_ADDRESS'))
 
129
        os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = dbus_address
126
130
 
127
131
    def start(self):
128
132
        try:
132
136
            raise
133
137
 
134
138
    def _kill(self, pid):
135
 
        with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
136
 
            print('FORCE', pid, file=fp)
137
139
        os.kill(pid, signal.SIGTERM)
138
140
        # Wait for it to die.
139
141
        until = datetime.datetime.now() + datetime.timedelta(seconds=10)
143
145
                os.kill(pid, 0)
144
146
            except ProcessLookupError:
145
147
                break
146
 
        with open('/tmp/debug.log', 'a', encoding='utf-8') as fp:
147
 
            print('GONE', pid, file=fp)
148
148
 
149
149
    def shutdown(self):
150
150
        self._stack.close()