~allenap/maas/neighbours-service-live

« back to all changes in this revision

Viewing changes to src/provisioningserver/tests/test_plugin_services.py

  • Committer: Gavin Panella
  • Date: 2015-10-14 19:48:39 UTC
  • mfrom: (3852.1.524 maas)
  • Revision ID: gavin.panella@canonical.com-20151014194839-xgjmom6qzxyj71pn
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012, 2013 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Tests for extra services in `provisioningserver.plugin`."""
5
 
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
str = None
13
 
 
14
 
__metaclass__ = type
15
 
__all__ = []
16
 
 
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
21
 
 
22
 
 
23
 
class TestServicesBase:
24
 
 
25
 
    run_tests_with = MAASTwistedRunTest.make_factory(timeout=5)
26
 
 
27
 
    def setUp(self):
28
 
        super(TestServicesBase, self).setUp()
29
 
        self.observers = theLogPublisher.observers[:]
30
 
        self.services = MultiService()
31
 
        self.services.privilegedStartService()
32
 
        self.services.startService()
33
 
 
34
 
    def tearDown(self):
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())
41
 
        return d
42
 
 
43
 
    def addDetailFromLog(self):
44
 
        content = content_from_file(self.log_filename, buffer_now=True)
45
 
        self.addDetail("log", content)
46
 
 
47
 
    def assertNoObserversLeftBehind(self):
48
 
        self.assertEqual(self.observers, theLogPublisher.observers)