~barry/ubuntu-system-image/citrain302

« back to all changes in this revision

Viewing changes to systemimage/tests/test_main.py

  • Committer: CI bot
  • Author(s): Barry Warsaw, Stéphane Graber
  • Date: 2014-02-25 17:48:18 UTC
  • mfrom: (228.1.9 didier)
  • Revision ID: ps-jenkins@lists.canonical.com-20140225174818-3yz01iuxmcsz98zo
New upstream release, along with some packaging changes.  See changelog and NEWS.rst for details. Fixes: 1260768, 1277589, 1279056, 1284217

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2013 Canonical Ltd.
 
1
# Copyright (C) 2013-2014 Canonical Ltd.
2
2
# Author: Barry Warsaw <barry@ubuntu.com>
3
3
 
4
4
# This program is free software: you can redistribute it and/or modify
26
26
 
27
27
 
28
28
import os
 
29
import sys
29
30
import dbus
30
31
import stat
31
32
import time
32
33
import shutil
33
34
import unittest
 
35
import subprocess
34
36
 
35
37
from contextlib import ExitStack, contextmanager
36
38
from datetime import datetime
781
783
        self.assertEqual(stat.filemode(mode), 'drwx--S---')
782
784
        mode = os.stat(config.system.logfile).st_mode
783
785
        self.assertEqual(stat.filemode(mode), '-rw-------')
 
786
 
 
787
    def test_single_instance(self):
 
788
        # Only one instance of the system-image-dbus service is allowed to
 
789
        # remain active on a single system bus.
 
790
        self.assertIsNone(find_dbus_process(self.ini_path))
 
791
        self._activate()
 
792
        proc = find_dbus_process(self.ini_path)
 
793
        # Attempt to start a second process on the same system bus.
 
794
        env = dict(
 
795
            DBUS_SYSTEM_BUS_ADDRESS=os.environ['DBUS_SYSTEM_BUS_ADDRESS'])
 
796
        args = (sys.executable, '-m', 'systemimage.service',
 
797
                '-C', self.ini_path)
 
798
        second = subprocess.Popen(args, universal_newlines=True, env=env)
 
799
        # Allow a TimeoutExpired exception to fail the test.
 
800
        try:
 
801
            code = second.wait(timeout=10)
 
802
        except subprocess.TimeoutExpired:
 
803
            second.kill()
 
804
            second.communicate()
 
805
            raise
 
806
        self.assertNotEqual(second.pid, proc)
 
807
        self.assertEqual(code, 2)