1
# Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for extra services in `provisioningserver.plugin`."""
6
from __future__ import (
17
from maastesting.testcase import MAASTwistedRunTest
18
from testtools.content import content_from_file
19
from twisted.application.service import MultiService
20
from twisted.python.log import theLogPublisher
23
class TestServicesBase:
25
run_tests_with = MAASTwistedRunTest.make_factory(timeout=5)
28
super(TestServicesBase, self).setUp()
29
self.observers = theLogPublisher.observers[:]
30
self.services = MultiService()
31
self.services.privilegedStartService()
32
self.services.startService()
35
super(TestServicesBase, self).tearDown()
36
d = self.services.stopService()
37
# The log file must be read in right after services have stopped,
38
# before the temporary directory where the log lives is removed.
39
d.addBoth(lambda ignore: self.addDetailFromLog())
40
d.addBoth(lambda ignore: self.assertNoObserversLeftBehind())
43
def addDetailFromLog(self):
44
content = content_from_file(self.log_filename, buffer_now=True)
45
self.addDetail("log", content)
47
def assertNoObserversLeftBehind(self):
48
self.assertEqual(self.observers, theLogPublisher.observers)