1
from landscape.tests.mocker import ANY
2
from landscape.tests.helpers import (
3
LandscapeTest, FakeBrokerServiceHelper)
4
from landscape.reactor import FakeReactor
5
from landscape.manager.config import ManagerConfiguration, ALL_PLUGINS
6
from landscape.manager.service import ManagerService
7
from landscape.manager.processkiller import ProcessKiller
10
class ManagerServiceTest(LandscapeTest):
12
helpers = [FakeBrokerServiceHelper]
15
super(ManagerServiceTest, self).setUp()
16
config = ManagerConfiguration()
17
config.load(["-c", self.config_filename])
19
class FakeManagerService(ManagerService):
20
reactor_factory = FakeReactor
22
self.service = FakeManagerService(config)
24
def test_plugins(self):
26
By default the L{ManagerService.plugins} list holds an instance of
27
every enabled manager plugin.
29
self.assertEquals(len(self.service.plugins), len(ALL_PLUGINS))
31
def test_get_plugins(self):
33
If the C{--manager-plugins} command line option is specified, only the
34
given plugins will be enabled.
36
self.service.config.load(["--manager-plugins", "ProcessKiller"])
37
[plugin] = self.service.get_plugins()
38
self.assertTrue(isinstance(plugin, ProcessKiller))
40
def test_start_service(self):
42
The L{ManagerService.startService} method connects to the broker,
43
starts the plugins and register the manager as broker client.
45
# FIXME: don't actually run the real register method, because at the
46
# moment the UserManager plugin still depends on DBus. We can probably
47
# drop this mocking once the AMP migration is completed.
48
for plugin in self.service.plugins:
49
plugin.register = self.mocker.mock()
53
def stop_service(ignored):
54
[connector] = self.broker_service.broker.get_connectors()
55
connector.disconnect()
56
self.service.stopService()
57
self.broker_service.stopService()
59
def assert_broker_connection(ignored):
60
self.assertEquals(len(self.broker_service.broker.get_clients()), 1)
61
self.assertIs(self.service.broker, self.service.manager.broker)
62
result = self.service.broker.ping()
63
return result.addCallback(stop_service)
65
self.broker_service.startService()
66
started = self.service.startService()
67
return started.addCallback(assert_broker_connection)