~free.ekanayaka/landscape-client/lucid-1.4.4-0ubuntu0.10.04

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2009-12-16 10:50:05 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091216105005-svplwdorkgz6vja7
Tags: 1.4.0-0ubuntu0.10.04.0
* New upstream release with several bug fixes:
  - Fix landscape daemons fail to start when too many groups are
    available (LP: #456124)
  - Fix landscape programs wake up far too much. (LP: #340843)
  - Fix Package manager fails with 'no such table: task' (LP #465846)
  - Fix test suite leaving temporary files around (LP #476418)
  - Fix the 1hr long wait for user data to be uploaded following a
    resynchronisation (LP #369000)

* Add support for Ubuntu release upgrades:
  - Add helper function to fetch many files at once (LP: #450629)
  - Handle release-upgrade messages in the packagemanager
    plugin (LP: #455217)
  - Add a release-upgrader task handler (LP: #462543)
  - Support upgrade-tool environment variables (LP: #463321)

* Add initial support for Smart package locking:
  - Detect and report changes about Smart package locks (#488108)

* Packaging fixes:
  - Turn unnecessary Pre-Depends on python-gobject into a regular Depends
  - If it's empty, remove /etc/landscape upon purge

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from landscape.monitor.computeruptime import (LoginInfo, LoginInfoReader,
5
5
                                              ComputerUptime, BootTimes,
6
6
                                              get_uptime)
7
 
from landscape.tests.helpers import (LandscapeTest, MakePathHelper,
8
 
                                     MonitorHelper)
 
7
from landscape.tests.helpers import LandscapeTest, MonitorHelper
9
8
from landscape.tests.mocker import ANY
10
9
 
11
10
 
32
31
 
33
32
    def test_valid_uptime_file(self):
34
33
        """Test ensures that we can read a valid /proc/uptime file."""
35
 
        proc_file = self.make_path("17608.24 16179.25")
 
34
        proc_file = self.makeFile("17608.24 16179.25")
36
35
        self.assertEquals("%0.2f" % get_uptime(proc_file),
37
36
                          "17608.24")
38
37
 
40
39
class LoginInfoReaderTest(LandscapeTest):
41
40
    """Tests for login info file reader."""
42
41
 
43
 
    helpers = [MakePathHelper]
44
 
 
45
42
    def test_read_empty_file(self):
46
43
        """Test ensures the reader is resilient to empty files."""
47
 
        filename = self.make_path("")
 
44
        filename = self.makeFile("")
48
45
 
49
46
        file = open(filename, "rb")
50
47
        try:
55
52
 
56
53
    def test_read_login_info(self):
57
54
        """Test ensures the reader can read login info."""
58
 
        filename = self.make_path("")
 
55
        filename = self.makeFile("")
59
56
        append_login_data(filename, login_type=1, pid=100, tty_device="/dev/",
60
57
                          id="1", username="jkakar", hostname="localhost",
61
58
                          termination_status=0, exit_status=0, session_id=1,
104
101
 
105
102
    def test_login_info_iterator(self):
106
103
        """Test ensures iteration behaves correctly."""
107
 
        filename = self.make_path("")
 
104
        filename = self.makeFile("")
108
105
        append_login_data(filename)
109
106
        append_login_data(filename)
110
107
 
124
121
class ComputerUptimeTest(LandscapeTest):
125
122
    """Tests for the computer-uptime plugin."""
126
123
 
127
 
    helpers = [MakePathHelper, MonitorHelper]
 
124
    helpers = [MonitorHelper]
128
125
 
129
126
    def setUp(self):
130
127
        LandscapeTest.setUp(self)
132
129
 
133
130
    def test_deliver_message(self):
134
131
        """Test delivering a message with the boot and shutdown times."""
135
 
        wtmp_filename = self.make_path("")
 
132
        wtmp_filename = self.makeFile("")
136
133
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
137
134
                          entry_time_seconds=535)
138
135
        plugin = ComputerUptime(wtmp_file=wtmp_filename)
147
144
 
148
145
    def test_only_deliver_unique_shutdown_messages(self):
149
146
        """Test that only unique shutdown messages are generated."""
150
 
        wtmp_filename = self.make_path("")
 
147
        wtmp_filename = self.makeFile("")
151
148
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
152
149
                          entry_time_seconds=535)
153
150
 
173
170
 
174
171
    def test_only_queue_messages_with_data(self):
175
172
        """Test ensures that messages without data are not queued."""
176
 
        wtmp_filename = self.make_path("")
 
173
        wtmp_filename = self.makeFile("")
177
174
        append_login_data(wtmp_filename, tty_device="~", username="reboot",
178
175
                          entry_time_seconds=3212)
179
176
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
188
185
        self.assertEquals(len(self.mstore.get_pending_messages()), 1)
189
186
 
190
187
    def test_missing_wtmp_file(self):
191
 
        wtmp_filename = self.make_path()
 
188
        wtmp_filename = self.makeFile()
192
189
        plugin = ComputerUptime(wtmp_file=wtmp_filename)
193
190
        self.monitor.add(plugin)
194
191
        plugin.run()
196
193
 
197
194
    def test_boot_time_same_as_last_known_startup_time(self):
198
195
        """Ensure one message is queued for duplicate startup times."""
199
 
        wtmp_filename = self.make_path("")
 
196
        wtmp_filename = self.makeFile("")
200
197
        append_login_data(wtmp_filename, tty_device="~", username="reboot",
201
198
                          entry_time_seconds=3212)
202
199
        plugin = ComputerUptime(wtmp_file=wtmp_filename)
213
210
        Test ensures startup times are not duplicated even across restarts of
214
211
        the client. This is simulated by creating a new instance of the plugin.
215
212
        """
216
 
        wtmp_filename = self.make_path("")
 
213
        wtmp_filename = self.makeFile("")
217
214
        append_login_data(wtmp_filename, tty_device="~", username="reboot",
218
215
                          entry_time_seconds=3212)
219
216
        plugin1 = ComputerUptime(wtmp_file=wtmp_filename)
237
234
 
238
235
    def test_check_last_logrotated_file(self):
239
236
        """Test ensures reading falls back to logrotated files."""
240
 
        wtmp_filename = self.make_path("")
241
 
        logrotated_filename = self.make_path("", wtmp_filename + ".1")
 
237
        wtmp_filename = self.makeFile("")
 
238
        logrotated_filename = self.makeFile("", path=wtmp_filename + ".1")
242
239
        append_login_data(logrotated_filename, tty_device="~",
243
240
                          username="reboot", entry_time_seconds=125)
244
241
        append_login_data(logrotated_filename, tty_device="~",
258
255
 
259
256
    def test_check_logrotate_spillover(self):
260
257
        """Test ensures reading falls back to logrotated files."""
261
 
        wtmp_filename = self.make_path("")
262
 
        logrotated_filename = self.make_path("", wtmp_filename + ".1")
 
258
        wtmp_filename = self.makeFile("")
 
259
        logrotated_filename = self.makeFile("", path=wtmp_filename + ".1")
263
260
        append_login_data(logrotated_filename, tty_device="~",
264
261
                          username="reboot", entry_time_seconds=125)
265
262
        append_login_data(logrotated_filename, tty_device="~",
293
290
        self.assertEquals(message["shutdown-times"], [1150])
294
291
 
295
292
    def test_call_on_accepted(self):
296
 
        wtmp_filename = self.make_path("")
 
293
        wtmp_filename = self.makeFile("")
297
294
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
298
295
                          entry_time_seconds=535)
299
296
        plugin = ComputerUptime(wtmp_file=wtmp_filename)
313
310
        accepting their type.
314
311
        """
315
312
        self.mstore.set_accepted_types([])
316
 
        wtmp_filename = self.make_path("")
 
313
        wtmp_filename = self.makeFile("")
317
314
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
318
315
                          entry_time_seconds=535)
319
316
        plugin = ComputerUptime(wtmp_file=wtmp_filename)
325
322
 
326
323
class BootTimesTest(LandscapeTest):
327
324
 
328
 
    helpers = [MakePathHelper]
329
 
 
330
325
    def test_fallback_to_uptime(self):
331
326
        """
332
327
        When no data is available in C{/var/log/wtmp}
333
328
        L{BootTimes.get_last_boot_time} falls back to C{/proc/uptime}.
334
329
        """
335
 
        wtmp_filename = self.make_path("")
 
330
        wtmp_filename = self.makeFile("")
336
331
        append_login_data(wtmp_filename, tty_device="~", username="shutdown",
337
332
                          entry_time_seconds=535)
338
333
        self.assertTrue(BootTimes(filename=wtmp_filename).get_last_boot_time())