~ubuntu-branches/ubuntu/precise/landscape-client/precise-updates

« back to all changes in this revision

Viewing changes to landscape/monitor/tests/test_updatemanager.py

  • Committer: Package Import Robot
  • Author(s): Christopher Glass (Canonical)
  • Date: 2013-09-20 10:10:28 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130920101028-hldi7uo5wudxurmt
Tags: 13.07.3-0ubuntu0.12.04
* New upstream version (LP: #1190510)
 - New annotations exchange mechanism allows clients to send any key-value
   data to the landscape server (LP: #1123932)
 - Network devices now report their maximum theoretical speeds, and duplex
   status to landscape-server (LP: #1126331, LP: #1130733)
 - Landscape.client is now HA aware when HA is implemented using juju
   charms (LP: #1122508)
 - The landscape client will now trigger a reboot if server sends a
   reboot-required message. (LP: #1133005)
 - Big AMP code cleanup and refactoring in order to improve testing, improve
   performance and ease future maintainability (LP: #1165047, LP: #1169102,
   LP: #1170669)
 - Added logic to detect cloned (virtual) computers (LP: #1161856)
 - The landscape-client and landscape-common packages do not use or depend
   on dbus code anymore, and the dependencies to python-gi and gudev are
   dropped. The hardware info plugin now looks at /proc instead of querying
   DBus (LP: #1175553, LP: #1180691)
 - The ceph manager plugin is now a monitor plugin and thus does not require
   root privileges anymore. (LP: #1186973)
 - The detection logic for virtual machine was changed to account for the
   different semantics between Openstack Folsom and Grizzly, and was
   expanded to detect more hypervisors (LP: #1191843)
 - Removed legacy upgrader code from postinst since support for it was
   dropped.
 - The /etc/dbus-1/system.d/landscape.conf file was moved from the
   landscape-common package to the landscape-client-uii as part of
   LP: #1175553, LP: #1180691. No "Breaks" rule was added since the
   landscape-client-ui package requires the exact same version of
   landscape-common, which avoids the case outlined in
   http://www.debian.org/doc/debian-policy/footnotes.html#f53 .
* Removed the hardwareinfo patch since the changes were merged upstream
* Changed dh_clean -K to dh_prep (dh_clean -K is deprecated)
* Removed the packages arguments to dh_installman since all pacakges have
  manpages now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from landscape.monitor.updatemanager import UpdateManager
 
2
from landscape.tests.helpers import (
 
3
    LandscapeTest, MonitorHelper, LogKeeperHelper)
 
4
from landscape.tests.mocker import ANY
 
5
 
 
6
 
 
7
class UpdateManagerTest(LandscapeTest):
 
8
    """
 
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
 
11
    landscape server.
 
12
    """
 
13
 
 
14
    helpers = [MonitorHelper, LogKeeperHelper]
 
15
 
 
16
    def setUp(self):
 
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"])
 
22
 
 
23
    def test_get_prompt(self):
 
24
        """
 
25
        L{UpdateManager._get_prompt} returns the value of the
 
26
        variable C{Prompt} in the update-manager's configuration.
 
27
        """
 
28
        content = """
 
29
[DEFAULT]
 
30
Prompt=lts
 
31
"""
 
32
        self.makeFile(path=self.update_manager_filename, content=content)
 
33
        self.assertEqual("lts", self.plugin._get_prompt())
 
34
 
 
35
    def test_get_prompt_with_invalid_value_configured(self):
 
36
        """
 
37
        L{update_manager._get_prompt} returns "normal" if an invalid value
 
38
        is specified in the file.  A warning is also logged.
 
39
        """
 
40
        content = """
 
41
[DEFAULT]
 
42
Prompt=zarniwhoop
 
43
"""
 
44
        self.makeFile(path=self.update_manager_filename, content=content)
 
45
        self.assertEqual("normal", self.plugin._get_prompt())
 
46
 
 
47
    def test_get_prompt_with_missing_config_file(self):
 
48
        """
 
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.
 
52
        """
 
53
        self.plugin.update_manager_filename = "/I/Do/Not/Exist"
 
54
        self.assertEqual("normal", self.plugin._get_prompt())
 
55
 
 
56
    def test_send_message(self):
 
57
        """
 
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.
 
60
        """
 
61
        content = """
 
62
[DEFAULT]
 
63
Prompt=never
 
64
"""
 
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",
 
71
                              "prompt": u"never"}])
 
72
        self.mstore.delete_all_messages()
 
73
        self.plugin.send_message()
 
74
        self.assertMessages(self.mstore.get_pending_messages(), [])
 
75
 
 
76
    def test_run_interval(self):
 
77
        """
 
78
        The L{UpdateManager} plugin will be scheduled to run every hour.
 
79
        """
 
80
        self.assertEqual(3600, self.plugin.run_interval)
 
81
 
 
82
    def test_run_immediately(self):
 
83
        """
 
84
        The L{UpdateManager} plugin will be run immediately at startup.
 
85
        """
 
86
        self.assertTrue(True, self.plugin.run_immediately)
 
87
 
 
88
    def test_run(self):
 
89
        """
 
90
        If the server can accept them, the plugin should send
 
91
        C{update-manager} messages.
 
92
        """
 
93
        broker_mock = self.mocker.replace(self.remote)
 
94
        broker_mock.send_message(ANY)
 
95
        self.mocker.replay()
 
96
        self.plugin.run()
 
97
        self.mstore.set_accepted_types([])
 
98
        self.plugin.run()
 
99
 
 
100
    def test_resynchronize(self):
 
101
        """
 
102
        The "resynchronize" reactor message cause the plugin to send fresh
 
103
        data.
 
104
        """
 
105
        self.plugin.run()
 
106
        self.reactor.fire("resynchronize")
 
107
        self.plugin.run()
 
108
        messages = self.mstore.get_pending_messages()
 
109
        self.assertEqual(len(messages), 2)