1
from landscape.tests.helpers import LandscapeTest
2
from landscape.tests.helpers import ManagerHelper
3
from landscape.manager.plugin import ManagerPlugin, SUCCEEDED, FAILED
6
class BrokerPluginTest(LandscapeTest):
8
helpers = [ManagerHelper]
10
def test_call_with_operation_result_success(self):
12
A helper method exists which calls a function and sends an
13
operation-result message based on the success of that method.
15
plugin = ManagerPlugin()
16
plugin.register(self.manager)
17
broker_service = self.broker_service
18
broker_service.message_store.set_accepted_types(["operation-result"])
19
message = {"operation-id": 12312}
20
operation = lambda: None
22
def assert_messages(ignored):
23
messages = broker_service.message_store.get_pending_messages()
24
self.assertMessages(messages,
25
[{"type": "operation-result",
27
"operation-id": 12312}])
29
result = plugin.call_with_operation_result(message, operation)
30
return result.addCallback(assert_messages)
32
def test_call_with_operation_result_error(self):
34
The helper for operation-results sends an appropriate message when an
35
exception is raised from the given method.
37
self.log_helper.ignore_errors(RuntimeError)
38
plugin = ManagerPlugin()
39
plugin.register(self.manager)
40
broker_service = self.broker_service
41
broker_service.message_store.set_accepted_types(["operation-result"])
42
message = {"operation-id": 12312}
45
raise RuntimeError("What the crap!")
47
def assert_messages(ignored):
48
messages = broker_service.message_store.get_pending_messages()
49
self.assertMessages(messages,
50
[{"type": "operation-result", "status": FAILED,
51
"result-text": "RuntimeError: What the "
52
"crap!", "operation-id": 12312}])
53
logdata = self.logfile.getvalue()
54
self.assertTrue("RuntimeError: What the crap!" in logdata, logdata)
56
result = plugin.call_with_operation_result(message, operation)
57
return result.addCallback(assert_messages)
59
def test_call_with_operation_result_exchanges_urgently(self):
61
Operation results are reported to the server as quickly as possible.
63
plugin = ManagerPlugin()
64
plugin.register(self.manager)
65
broker_service = self.broker_service
66
broker_service.message_store.set_accepted_types(["operation-result"])
67
message = {"operation-id": 123}
68
operation = lambda: None
70
def assert_urgency(ignored):
71
self.assertTrue(broker_service.exchanger.is_urgent())
73
result = plugin.call_with_operation_result(message, operation)
74
return result.addCallback(assert_urgency)