~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_eventloop.py

  • Committer: Package Import Robot
  • Author(s): Julian Edwards, Julian Edwards, Andres Rodriguez
  • Date: 2014-08-21 18:38:27 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20140821183827-9xyb5u2o4l8g3zxj
Tags: 1.6.1+bzr2550-0ubuntu1
* New upstream bugfix release:
  - Auto-link node MACs to Networks (LP: #1341619)

[ Julian Edwards ]
* debian/maas-region-controller.postinst: Don't restart RabbitMQ on
  upgrades, just ensure it's running.  Should prevent a race with the
  cluster celery restarting.
* debian/rules: Pull upstream branch from the right place.

[ Andres Rodriguez ]
* debian/maas-region-controller.postinst: Ensure cluster celery is
  started if it also runs on the region.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
__metaclass__ = type
15
15
__all__ = []
16
16
 
17
 
from maasserver import eventloop
 
17
from crochet import wait_for_reactor
 
18
from django.db import connections
 
19
from maasserver import (
 
20
    eventloop,
 
21
    nonces_cleanup,
 
22
    )
18
23
from maasserver.rpc import regionservice
 
24
from maasserver.testing.eventloop import RegionEventLoopFixture
 
25
from maasserver.utils.async import transactional
19
26
from maastesting.testcase import MAASTestCase
20
27
from testtools.matchers import IsInstance
21
 
from twisted.application.service import (
22
 
    MultiService,
23
 
    Service,
24
 
    )
 
28
from twisted.application.service import MultiService
 
29
from twisted.python.threadable import isInIOThread
25
30
 
26
31
 
27
32
class TestRegionEventLoop(MAASTestCase):
34
39
    def test_start_and_stop(self):
35
40
        # Replace the factories in RegionEventLoop with non-functional
36
41
        # dummies to avoid bringing up real services here.
37
 
        self.patch(eventloop.loop, "factories", tuple(
38
 
            (name, Service) for name, _ in eventloop.loop.factories))
 
42
        self.useFixture(RegionEventLoopFixture())
39
43
        # Reset the services list.
40
44
        self.patch(eventloop.loop, "services", MultiService())
41
45
        # At the outset, the eventloop's services are dorment.
91
95
        self.assertIn(
92
96
            eventloop.make_RegionAdvertisingService,
93
97
            {factory for _, factory in eventloop.loop.factories})
 
98
 
 
99
    def test_make_NonceCleanupService(self):
 
100
        service = eventloop.make_NonceCleanupService()
 
101
        self.assertThat(service, IsInstance(
 
102
            nonces_cleanup.NonceCleanupService))
 
103
        # It is registered as a factory in RegionEventLoop.
 
104
        self.assertIn(
 
105
            eventloop.make_NonceCleanupService,
 
106
            {factory for _, factory in eventloop.loop.factories})
 
107
 
 
108
 
 
109
class TestDisablingDatabaseConnections(MAASTestCase):
 
110
 
 
111
    @wait_for_reactor
 
112
    def test_connections_are_all_stubs_in_the_event_loop(self):
 
113
        self.assertTrue(isInIOThread())
 
114
        for alias in connections:
 
115
            connection = connections[alias]
 
116
            # isinstance() fails because it references __bases__, so
 
117
            # compare types here.
 
118
            self.assertEqual(
 
119
                eventloop.DisabledDatabaseConnection,
 
120
                type(connection))
 
121
 
 
122
    @transactional
 
123
    def test_connections_are_all_usable_outside_the_event_loop(self):
 
124
        self.assertFalse(isInIOThread())
 
125
        for alias in connections:
 
126
            connection = connections[alias]
 
127
            self.assertTrue(connection.is_usable())
 
128
 
 
129
    def test_DisabledDatabaseConnection(self):
 
130
        connection = eventloop.DisabledDatabaseConnection()
 
131
        self.assertRaises(RuntimeError, getattr, connection, "connect")
 
132
        self.assertRaises(RuntimeError, getattr, connection, "__call__")
 
133
        self.assertRaises(RuntimeError, setattr, connection, "foo", "bar")
 
134
        self.assertRaises(RuntimeError, delattr, connection, "baz")