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

« back to all changes in this revision

Viewing changes to landscape/package/tests/test_releaseupgrader.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-04-21 12:31:28 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100421123128-qwde8pqe5zi6so05
Tags: 1.5.0.1-0ubuntu0.9.10.0
* New upstream version
  - Fix smart-update failing its very first run (LP: #562496)
  - Depend on pythonX.Y-dbus and pythonX.Y-pycurl (LP: #563063)
  - Make only one request at a time to retrieve EC2 instances (LP: #567515)

* New upstream version (LP: #557244)
  - Fix package-changer running before smart-update has completed (LP: #542215)
  - Report the version of Eucalyptus used to generate topology data (LP: #554007)
  - Enable the Eucalyptus plugin by default, if supported (LP: #546531)
  - Use a whitelist of allowed filesystem types to instead of a blacklist (LP: #351927)
  - Report the update-manager logs to the server (LP: #503384)
  - Turn off Curl's DNS caching for requests. (LP: #522668)

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
            self.assertFileContent(mirrors_filename,
238
238
                                   "ftp://ftp.lug.ro/ubuntu/\n"
239
239
                                   "http://ppa.launchpad.net/landscape/"
240
 
                                   "ppa/ubuntu/\n")
 
240
                                   "trunk/ubuntu/\n")
241
241
 
242
242
        result = self.upgrader.tweak("hardy")
243
243
        result.addCallback(check_result)
270
270
        result.addCallback(check_result)
271
271
        return result
272
272
 
 
273
    def test_tweak_sets_dbus_start_script_with_no_post_install_scripts(self):
 
274
        """
 
275
        The L{ReleaseUpgrader.tweak} method adds to the upgrade-tool
 
276
        configuration a little script that starts dbus after the upgrade. This
 
277
        works even when the config file doesn't have a PostInstallScripts entry
 
278
        yet.
 
279
        """
 
280
        config_filename = os.path.join(self.config.upgrade_tool_directory,
 
281
                                       "DistUpgrade.cfg.dapper")
 
282
        self.makeFile(path=config_filename, content="")
 
283
 
 
284
        def check_result(ignored):
 
285
            config = ConfigParser.ConfigParser()
 
286
            config.read(config_filename)
 
287
            self.assertEquals(config.get("Distro", "PostInstallScripts"),
 
288
                              "./dbus.sh")
 
289
            dbus_sh = os.path.join(self.config.upgrade_tool_directory,
 
290
                                   "dbus.sh")
 
291
            self.assertFileContent(dbus_sh,
 
292
                                   "#!/bin/sh\n"
 
293
                                   "/etc/init.d/dbus start\n"
 
294
                                   "sleep 10\n")
 
295
 
 
296
        result = self.upgrader.tweak("dapper")
 
297
        result.addCallback(check_result)
 
298
        return result
 
299
 
 
300
    def test_default_logs_directory(self):
 
301
        """
 
302
        The default directory for the upgrade-tool logs is the system one.
 
303
        """
 
304
        self.assertEquals(self.upgrader.logs_directory,
 
305
                          "/var/log/dist-upgrade")
 
306
 
 
307
    def test_default_logs_limit(self):
 
308
        """
 
309
        The default read limit for the upgrade-tool logs is 100000 bytes.
 
310
        """
 
311
        self.assertEquals(self.upgrader.logs_limit, 100000)
 
312
 
 
313
    def test_make_operation_result_text(self):
 
314
        """
 
315
        L{ReleaseUpgrade.make_operation_result_text} aggregates the contents of
 
316
        the process standard output, error and log files.
 
317
        """
 
318
        self.upgrader.logs_directory = self.makeDir()
 
319
        self.makeFile(basename="main.log",
 
320
                      dirname=self.upgrader.logs_directory,
 
321
                      content="main log")
 
322
        self.makeFile(basename="apt.log",
 
323
                      dirname=self.upgrader.logs_directory,
 
324
                      content="apt log")
 
325
        text = self.upgrader.make_operation_result_text("stdout", "stderr")
 
326
        self.assertEquals(text,
 
327
                          "=== Standard output ===\n\n"
 
328
                          "stdout\n\n"
 
329
                          "=== Standard error ===\n\n"
 
330
                          "stderr\n\n"
 
331
                          "=== apt.log ===\n\n"
 
332
                          "apt log\n\n"
 
333
                          "=== main.log ===\n\n"
 
334
                          "main log\n\n")
 
335
 
 
336
    def test_make_operation_result_text_with_no_stderr(self):
 
337
        """
 
338
        L{ReleaseUpgrade.make_operation_result_text} skips the standard error
 
339
        if it's empty.
 
340
        """
 
341
        self.upgrader.logs_directory = self.makeDir()
 
342
        text = self.upgrader.make_operation_result_text("stdout", "")
 
343
        self.assertEquals(text,
 
344
                          "=== Standard output ===\n\n"
 
345
                          "stdout\n\n")
 
346
 
 
347
    def test_make_operation_result_text_only_considers_log_files(self):
 
348
        """
 
349
        L{ReleaseUpgrade.make_operation_result_text} only considers log files
 
350
        from the last upgrade-tool run, directories containing log files from
 
351
        an older run are skipped.
 
352
        """
 
353
        self.upgrader.logs_directory = self.makeDir()
 
354
        self.makeDir(dirname=self.upgrader.logs_directory)
 
355
        text = self.upgrader.make_operation_result_text("stdout", "stderr")
 
356
        self.assertEquals(text,
 
357
                          "=== Standard output ===\n\n"
 
358
                          "stdout\n\n"
 
359
                          "=== Standard error ===\n\n"
 
360
                          "stderr\n\n")
 
361
 
 
362
    def test_make_operation_result_text_trims_long_files(self):
 
363
        """
 
364
        L{ReleaseUpgrade.make_operation_result_text} only reads the last
 
365
        L{logs_limit} lines of a log file.
 
366
        """
 
367
        self.upgrader.logs_directory = self.makeDir()
 
368
        self.upgrader.logs_limit = 8
 
369
        self.makeFile(basename="main.log",
 
370
                      dirname=self.upgrader.logs_directory,
 
371
                      content="very long log")
 
372
        text = self.upgrader.make_operation_result_text("stdout", "stderr")
 
373
        self.assertEquals(text,
 
374
                          "=== Standard output ===\n\n"
 
375
                          "stdout\n\n"
 
376
                          "=== Standard error ===\n\n"
 
377
                          "stderr\n\n"
 
378
                          "=== main.log ===\n\n"
 
379
                          "long log\n\n")
 
380
 
273
381
    def test_upgrade(self):
274
382
        """
275
383
        The L{ReleaseUpgrader.upgrade} method spawns the appropropriate
276
384
        upgrade-tool script and reports the result.
277
385
        """
 
386
        self.upgrader.logs_directory = self.makeDir()
278
387
        upgrade_tool_directory = self.config.upgrade_tool_directory
279
388
        upgrade_tool_filename = os.path.join(upgrade_tool_directory, "karmic")
280
389
        fd = open(upgrade_tool_filename, "w")
298
407
                self.assertIn("INFO: Queuing message with release upgrade "
299
408
                              "results to exchange urgently.",
300
409
                              self.logfile.getvalue())
301
 
                result_text = u"--frontend DistUpgradeViewNonInteractive\n" \
302
 
                              "FOO=bar\nPWD=%s\nout\n" % upgrade_tool_directory
 
410
                result_text = (u"=== Standard output ===\n\n"
 
411
                               "--frontend DistUpgradeViewNonInteractive\n"
 
412
                               "FOO=bar\n"
 
413
                               "PWD=%s\nout\n\n\n" % upgrade_tool_directory)
303
414
                self.assertMessages(self.get_pending_messages(),
304
415
                                    [{"type": "operation-result",
305
416
                                      "operation-id": 100,
324
435
        which gets passed to the upgrade-tool script as argument for the
325
436
        C{--mode} command line option.
326
437
        """
 
438
        self.upgrader.logs_directory = self.makeDir()
327
439
        upgrade_tool_directory = self.config.upgrade_tool_directory
328
440
        upgrade_tool_filename = os.path.join(upgrade_tool_directory, "hardy")
329
441
        self.makeFile(path=upgrade_tool_filename,
337
449
            result = self.upgrader.upgrade("hardy", 100, mode="server")
338
450
 
339
451
            def check_result(ignored):
340
 
                result_text = ("--frontend DistUpgradeViewNonInteractive "
341
 
                               "--mode server\n")
 
452
                result_text = (u"=== Standard output ===\n\n"
 
453
                               "--frontend DistUpgradeViewNonInteractive "
 
454
                               "--mode server\n\n\n")
342
455
                self.assertMessages(self.get_pending_messages(),
343
456
                                    [{"type": "operation-result",
344
457
                                      "operation-id": 100,
357
470
        The L{ReleaseUpgrader.upgrade} method optionally sets environment
358
471
        variables to be passed to the upgrade-tool process.
359
472
        """
 
473
        self.upgrader.logs_directory = self.makeDir()
360
474
        upgrade_tool_directory = self.config.upgrade_tool_directory
361
475
        upgrade_tool_filename = os.path.join(upgrade_tool_directory, "karmic")
362
476
        fd = open(upgrade_tool_filename, "w")
377
491
                                           debug=True)
378
492
 
379
493
            def check_result(ignored):
380
 
                result_text = u"DEBUG_UPDATE_MANAGER=True\n" \
381
 
                              u"RELEASE_UPRADER_ALLOW_THIRD_PARTY=True\n"
 
494
                result_text = (u"=== Standard output ===\n\n"
 
495
                               "DEBUG_UPDATE_MANAGER=True\n"
 
496
                               "RELEASE_UPRADER_ALLOW_THIRD_PARTY=True\n\n\n")
382
497
                self.assertMessages(self.get_pending_messages(),
383
498
                                    [{"type": "operation-result",
384
499
                                      "operation-id": 100,
402
517
        The L{ReleaseUpgrader.upgrade} sends a message with failed status
403
518
        field if the upgrade-tool exits with non-zero code.
404
519
        """
 
520
        self.upgrader.logs_directory = self.makeDir()
405
521
        upgrade_tool_directory = self.config.upgrade_tool_directory
406
522
        upgrade_tool_filename = os.path.join(upgrade_tool_directory, "karmic")
407
523
        fd = open(upgrade_tool_filename, "w")
419
535
            result = self.upgrader.upgrade("karmic", 100)
420
536
 
421
537
            def check_result(ignored):
 
538
                result_text = (u"=== Standard output ===\n\nout\n\n\n"
 
539
                               "=== Standard error ===\n\nerr\n\n\n")
422
540
                self.assertMessages(self.get_pending_messages(),
423
541
                                    [{"type": "operation-result",
424
542
                                      "operation-id": 100,
425
543
                                      "status": FAILED,
426
 
                                      "result-text": "out\nerr\n",
 
544
                                      "result-text": result_text,
427
545
                                      "result-code": 3}])
428
546
 
429
547
            result.addCallback(check_result)
439
557
        and passes its files descriptors over to child processes we don't know
440
558
        about.
441
559
        """
 
560
        self.upgrader.logs_directory = self.makeDir()
442
561
        upgrade_tool_directory = self.config.upgrade_tool_directory
443
562
        upgrade_tool_filename = os.path.join(upgrade_tool_directory, "karmic")
444
563
        child_pid_filename = self.makeFile()