1
from landscape.monitor.updatemanager import UpdateManager
2
from landscape.tests.helpers import (
3
LandscapeTest, MonitorHelper, LogKeeperHelper)
4
from landscape.tests.mocker import ANY
7
class UpdateManagerTest(LandscapeTest):
9
Tests relating to the L{UpdateManager} monitoring plug-in, which should
10
notice changes to update-manager's configuration and report these back to
14
helpers = [MonitorHelper, LogKeeperHelper]
17
super(UpdateManagerTest, self).setUp()
18
self.update_manager_filename = self.makeFile()
19
self.plugin = UpdateManager(self.update_manager_filename)
20
self.monitor.add(self.plugin)
21
self.mstore.set_accepted_types(["update-manager-info"])
23
def test_get_prompt(self):
25
L{UpdateManager._get_prompt} returns the value of the
26
variable C{Prompt} in the update-manager's configuration.
32
self.makeFile(path=self.update_manager_filename, content=content)
33
self.assertEqual("lts", self.plugin._get_prompt())
35
def test_get_prompt_with_invalid_value_configured(self):
37
L{update_manager._get_prompt} returns "normal" if an invalid value
38
is specified in the file. A warning is also logged.
44
self.makeFile(path=self.update_manager_filename, content=content)
45
self.assertEqual("normal", self.plugin._get_prompt())
47
def test_get_prompt_with_missing_config_file(self):
49
When the configuration file does not exist we just return "normal".
50
Any machine that doesn't have update-manager installed would fit into
51
this category, so there's no need to warn about it.
53
self.plugin.update_manager_filename = "/I/Do/Not/Exist"
54
self.assertEqual("normal", self.plugin._get_prompt())
56
def test_send_message(self):
58
A new C{"update-manager-info"} message should be enqueued if and only
59
if the update-manager status of the system has changed.
65
self.makeFile(path=self.update_manager_filename, content=content)
66
self.plugin.send_message()
67
self.assertIn("Queueing message with updated update-manager status.",
68
self.logfile.getvalue())
69
self.assertMessages(self.mstore.get_pending_messages(),
70
[{"type": "update-manager-info",
72
self.mstore.delete_all_messages()
73
self.plugin.send_message()
74
self.assertMessages(self.mstore.get_pending_messages(), [])
76
def test_run_interval(self):
78
The L{UpdateManager} plugin will be scheduled to run every hour.
80
self.assertEqual(3600, self.plugin.run_interval)
82
def test_run_immediately(self):
84
The L{UpdateManager} plugin will be run immediately at startup.
86
self.assertTrue(True, self.plugin.run_immediately)
90
If the server can accept them, the plugin should send
91
C{update-manager} messages.
93
broker_mock = self.mocker.replace(self.remote)
94
broker_mock.send_message(ANY)
97
self.mstore.set_accepted_types([])
100
def test_resynchronize(self):
102
The "resynchronize" reactor message cause the plugin to send fresh
106
self.reactor.fire("resynchronize")
108
messages = self.mstore.get_pending_messages()
109
self.assertEqual(len(messages), 2)