~free.ekanayaka/landscape-client/jaunty-1.5.2.1-0ubuntu0.9.04.0

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2009-09-21 17:59:31 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090921175931-4ucv40j9ro26i3lm
Tags: 1.3.2.3-0ubuntu0.9.04.0
* New upstream release (LP: #347983):
  - Don't clear the hash_id_requests table upon resynchronize (LP #417122)
  - Include the README file in landscape-client (LP: #396260)
  - Fix client capturing stderr from run_command when constructing
    hash-id-databases url (LP: #397480)
  - Use substvars to conditionally depend on update-motd or
    libpam-modules (LP: #393454)
  - Fix reporting wrong version to the server (LP: #391225)
  - The init script does not wait for the network to be available
    before checking for EC2 user data (LP: #383336)
  - When the broker is restarted by the watchdog, the state of the client
    is inconsistent (LP: #380633)
  - Package stays unknown forever in the client with hash-id-databases
    support (LP: #381356)
  - Standard error not captured when calling smart-update (LP: #387441)
  - Changer calls reporter without switching groups, just user (LP: #388092)
  - Run smart update in the package-reporter instead of having a cronjob (LP: #362355)
  - Package changer does not inherit proxy settings (LP: #381241)
  - The ./test script doesn't work in landscape-client (LP: #381613)
  - The source package should build on all supported releases (LP: #385098)
  - Strip smart update's output (LP: #387331)
  - The fetch() timeout isn't based on activity (#389224)
  - Client can use a UUID of "None" when fetching the hash-id-database (LP: #381291)
  - Registration should use the fqdn rather than just the hostname (LP: #385730)

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
from smart.cache import Provides
9
9
 
10
 
from landscape.lib.lock import lock_path
11
 
 
12
10
from landscape.package.changer import (
13
11
    PackageChanger, main, find_changer_command, UNKNOWN_PACKAGE_DATA_TIMEOUT)
14
12
from landscape.package.store import PackageStore
15
13
from landscape.package.facade import (
16
 
    SmartFacade, DependencyError, TransactionError, SmartError)
17
 
from landscape.broker.remote import RemoteBroker
 
14
    DependencyError, TransactionError, SmartError)
 
15
from landscape.deployment import Configuration
18
16
 
19
17
from landscape.tests.mocker import ANY
20
18
from landscape.tests.helpers import (
31
29
        super(PackageChangerTest, self).setUp()
32
30
 
33
31
        self.store = PackageStore(self.makeFile())
34
 
        self.changer = PackageChanger(self.store, self.facade, self.remote)
 
32
        self.config = Configuration()
 
33
        self.changer = PackageChanger(self.store, self.facade, self.remote, self.config)
35
34
 
36
35
        service = self.broker_service
37
36
        service.message_store.set_accepted_types(["change-packages-result"])
420
419
                              "REPORTER RUN")
421
420
        return result.addCallback(got_result)
422
421
 
423
 
    def test_set_effective_uid_when_running_as_root(self):
 
422
    def test_set_effective_uid_and_gid_when_running_as_root(self):
424
423
        """
425
424
        After the package changer has run, we want the package-reporter to run
426
425
        to report the recent changes.  If we're running as root, we want to
427
 
        change to the "landscape" user.
 
426
        change to the "landscape" user and "landscape" group. We also want to
 
427
        deinitialize Smart to let the reporter run smart-update cleanly.
428
428
        """
 
429
 
429
430
        # We are running as root
430
431
        getuid_mock = self.mocker.replace("os.getuid")
431
432
        getuid_mock()
432
433
        self.mocker.result(0)
433
434
 
434
 
        # We want to return a known uid
 
435
        # The order matters (first smart then gid and finally uid)
 
436
        self.mocker.order()
 
437
 
 
438
        # Deinitialize smart
 
439
        facade_mock = self.mocker.patch(self.facade)
 
440
        facade_mock.deinit()
 
441
 
 
442
        # We want to return a known gid
 
443
        grnam_mock = self.mocker.replace("grp.getgrnam")
 
444
        grnam_mock("landscape")
 
445
 
 
446
        class FakeGroup(object):
 
447
            gr_gid = 199
 
448
 
 
449
        self.mocker.result(FakeGroup())
 
450
 
 
451
        # First the changer should change the group
 
452
        setgid_mock = self.mocker.replace("os.setgid")
 
453
        setgid_mock(199)
 
454
 
 
455
        # And a known uid as well
435
456
        pwnam_mock = self.mocker.replace("pwd.getpwnam")
436
457
        pwnam_mock("landscape")
437
458
 
440
461
 
441
462
        self.mocker.result(FakeUser())
442
463
 
443
 
        # And now, the changer should change the user
 
464
        # And now the user as well
444
465
        setuid_mock = self.mocker.replace("os.setuid")
445
466
        setuid_mock(199)
446
467
 
447
 
        # Finally, we don't really want the package changer to run.
 
468
        # Finally, we don't really want the package reporter to run.
448
469
        system_mock = self.mocker.replace("os.system")
449
470
        system_mock(ANY)
450
471
 
457
478
        return self.changer.run()
458
479
 
459
480
 
 
481
    def test_run(self):
 
482
        changer_mock = self.mocker.patch(self.changer)
 
483
 
 
484
        self.mocker.order()
 
485
 
 
486
        results = [Deferred() for i in range(2)]
 
487
 
 
488
        changer_mock.use_hash_id_db()
 
489
        self.mocker.result(results[0])
 
490
 
 
491
        changer_mock.handle_tasks()
 
492
        self.mocker.result(results[1])
 
493
 
 
494
        self.mocker.replay()
 
495
 
 
496
        self.changer.run()
 
497
 
 
498
        # It must raise an error because deferreds weren't yet fired.
 
499
        self.assertRaises(AssertionError, self.mocker.verify)
 
500
 
 
501
        for deferred in reversed(results):
 
502
            deferred.callback(None)
 
503
 
460
504
    def test_dont_spawn_reporter_after_running_if_nothing_done(self):
461
505
        output_filename = self.makeFile("REPORTER NOT RUN")
462
506
        reporter_filename = self.makeFile("#!/bin/sh\necho REPORTER RUN > %s" %
478
522
        return result.addCallback(got_result)
479
523
 
480
524
    def test_main(self):
481
 
        data_path = self.makeDir()
482
525
        self.mocker.order()
483
526
        
484
527
        run_task_handler = self.mocker.replace("landscape.package.taskhandler"