1
from twisted.internet.defer import Deferred
3
from landscape.manager.deployment import ManagerService, ManagerConfiguration
4
from landscape.manager.manager import (
5
ManagerPlugin, ManagerDBusObject, SUCCEEDED, FAILED)
7
from landscape.lib.dbus_util import get_object
9
from landscape.tests.helpers import (
10
LandscapeTest, LandscapeIsolatedTest, ManagerHelper)
13
class PluginOperationResultTest(LandscapeTest):
15
helpers = [ManagerHelper]
17
def test_call_with_operation_result_success(self):
19
A helper method exists which calls a function and sends an
20
operation-result message based on the success of that method.
22
plugin = ManagerPlugin()
23
plugin.register(self.manager)
24
service = self.broker_service
25
service.message_store.set_accepted_types(["operation-result"])
26
message = {"operation-id": 12312}
29
plugin.call_with_operation_result(message, operation)
30
messages = self.broker_service.message_store.get_pending_messages()
31
self.assertMessages(messages,
32
[{"type": "operation-result", "status": SUCCEEDED,
33
"operation-id": 12312}])
35
def test_call_with_operation_result_error(self):
37
The helper for operation-results sends an appropriate message when an
38
exception is raised from the given method.
40
self.log_helper.ignore_errors(RuntimeError)
41
plugin = ManagerPlugin()
42
plugin.register(self.manager)
43
service = self.broker_service
44
service.message_store.set_accepted_types(["operation-result"])
45
message = {"operation-id": 12312}
47
raise RuntimeError("What the crap!")
48
plugin.call_with_operation_result(message, operation)
49
messages = self.broker_service.message_store.get_pending_messages()
50
self.assertMessages(messages,
51
[{"type": "operation-result", "status": FAILED,
52
"result-text": "RuntimeError: What the crap!",
53
"operation-id": 12312}])
55
logdata = self.logfile.getvalue()
56
self.assertTrue("RuntimeError: What the crap!" in logdata, logdata)
58
def test_call_with_operation_result_exchanges_urgently(self):
60
Operation results are reported to the server as quickly as possible.
62
plugin = ManagerPlugin()
63
plugin.register(self.manager)
64
service = self.broker_service
65
service.message_store.set_accepted_types(["operation-result"])
66
message = {"operation-id": 123}
69
plugin.call_with_operation_result(message, operation)
70
self.assertTrue(service.exchanger.is_urgent())
73
class ManagerDBusObjectTest(LandscapeIsolatedTest):
75
helpers = [ManagerHelper]
78
super(ManagerDBusObjectTest, self).setUp()
79
configuration = ManagerConfiguration()
80
configuration.load(["-d", self.makeFile(), "--bus", "session",
81
"--manager-plugins", "ProcessKiller"])
82
self.manager_service = ManagerService(configuration)
83
self.broker_service.startService()
84
self.manager_service.startService()
85
self.dbus_object = get_object(self.broker_service.bus,
86
ManagerDBusObject.bus_name,
87
ManagerDBusObject.object_path)
90
super(ManagerDBusObjectTest, self).tearDown()
91
self.broker_service.stopService()
94
result = self.dbus_object.ping()
95
def got_result(result):
96
self.assertEquals(result, True)
97
return result.addCallback(got_result)
101
reactor = self.mocker.replace("twisted.internet.reactor")
102
self.expect(reactor.stop()).call(lambda: result.callback(None))
104
self.dbus_object.exit()