~free.ekanayaka/landscape-client/jaunty-updates-1.4.4-0ubuntu0.9.04

« back to all changes in this revision

Viewing changes to landscape/package/tests/test_facade.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:
1
 
import gdbm
2
1
import time
3
2
import os
 
3
import re
 
4
import sys
4
5
 
5
6
from smart.control import Control
6
7
from smart.cache import Provides
 
8
from smart.const import NEVER
 
9
 
 
10
from twisted.internet import reactor
 
11
from twisted.internet.defer import Deferred
 
12
from twisted.internet.utils import getProcessOutputAndValue
7
13
 
8
14
import smart
9
15
 
10
16
from landscape.package.facade import (
11
 
    SmartFacade, TransactionError, DependencyError, SmartError)
 
17
    TransactionError, DependencyError, ChannelError, SmartError,
 
18
    make_apt_deb_channel, make_deb_dir_channel)
12
19
 
13
20
from landscape.tests.mocker import ANY
14
21
from landscape.tests.helpers import LandscapeTest
79
86
        pkg = self.facade.get_packages_by_name("name2")[0]
80
87
        self.assertEquals(self.facade.get_package_hash(pkg), HASH2)
81
88
 
 
89
    def test_get_package_hashes(self):
 
90
        self.facade.reload_channels()
 
91
        hashes = self.facade.get_package_hashes()
 
92
        self.assertEquals(sorted(hashes), sorted([HASH1, HASH2, HASH3]))
 
93
 
82
94
    def test_get_package_by_hash(self):
83
95
        self.facade.reload_channels()
84
96
        pkg = self.facade.get_package_by_hash(HASH1)
91
103
    def test_reload_channels_clears_hash_cache(self):
92
104
        # Load hashes.
93
105
        self.facade.reload_channels()
94
 
        start = time.time()
95
106
 
96
107
        # Hold a reference to packages.
97
108
        pkg1 = self.facade.get_packages_by_name("name1")[0]
393
404
 
394
405
        self.facade.reload_channels()
395
406
        self.assertEquals(self.facade.get_package_hash(pkg), None)
 
407
 
 
408
    def test_reset_add_get_channels(self):
 
409
 
 
410
        channels = [("alias0", {"type": "test"}),
 
411
                    ("alias1", {"type": "test"})]
 
412
 
 
413
        self.facade.reset_channels()
 
414
 
 
415
        self.assertEquals(self.facade.get_channels(), {})
 
416
 
 
417
        self.facade.add_channel(*channels[0])
 
418
        self.facade.add_channel(*channels[1])
 
419
 
 
420
        self.assertEquals(self.facade.get_channels(), dict(channels))
 
421
 
 
422
    def test_make_channels(self):
 
423
 
 
424
        channel0 = make_apt_deb_channel("http://my.url/dir", "hardy", "main")
 
425
        channel1 = make_deb_dir_channel("/my/repo")
 
426
 
 
427
        self.assertEquals(channel0, {"baseurl": "http://my.url/dir",
 
428
                                     "distribution": "hardy",
 
429
                                     "components": "main",
 
430
                                     "type": "apt-deb"})
 
431
 
 
432
        self.assertEquals(channel1, {"path": "/my/repo",
 
433
                                     "type": "deb-dir"})
 
434
 
 
435
    def test_get_arch(self):
 
436
        """
 
437
        The L{SmartFacade.get_arch} should return the system dpkg
 
438
        architecture.
 
439
        """
 
440
        deferred = Deferred()
 
441
 
 
442
        def do_test():
 
443
            result = getProcessOutputAndValue("/usr/bin/dpkg",
 
444
                                              ("--print-architecture",))
 
445
            def callback((out, err, code)):
 
446
                self.assertEquals(self.facade.get_arch(), out.strip())
 
447
            result.addCallback(callback)
 
448
            result.chainDeferred(deferred)
 
449
 
 
450
        reactor.callWhenRunning(do_test)
 
451
        return deferred
 
452
 
 
453
    def test_set_arch_multiple_times(self):
 
454
 
 
455
        repository_dir = os.path.join(os.path.dirname(__file__), "repository")
 
456
 
 
457
        alias = "alias"
 
458
        channel = {"baseurl": "file://%s" % repository_dir,
 
459
                   "distribution": "hardy",
 
460
                   "components": "main",
 
461
                   "type": "apt-deb"}
 
462
 
 
463
        self.facade.set_arch("i386")
 
464
        self.facade.reset_channels()
 
465
        self.facade.add_channel(alias, channel)
 
466
        self.facade.reload_channels()
 
467
 
 
468
        pkgs = self.facade.get_packages()
 
469
        self.assertEquals(len(pkgs), 1)
 
470
        self.assertEquals(pkgs[0].name, "syslinux")
 
471
 
 
472
        self.facade.deinit()
 
473
        self.facade.set_arch("amd64")
 
474
        self.facade.reset_channels()
 
475
        self.facade.add_channel(alias, channel)
 
476
        self.facade.reload_channels()
 
477
 
 
478
        pkgs = self.facade.get_packages()
 
479
        self.assertEquals(len(pkgs), 1)
 
480
        self.assertEquals(pkgs[0].name, "libclthreads2")
 
481
 
 
482
    def test_set_caching_with_reload_error(self):
 
483
 
 
484
        alias = "alias"
 
485
        channel = {"type": "deb-dir",
 
486
                   "path": "/does/not/exist"}
 
487
 
 
488
        self.facade.reset_channels()
 
489
        self.facade.add_channel(alias, channel)
 
490
        self.facade.set_caching(NEVER)
 
491
 
 
492
        self.assertRaises(ChannelError, self.facade.reload_channels)
 
493
        self.facade._channels = {}
 
494
 
 
495
        ignore_re = re.compile("\[Smart\].*'alias'.*/does/not/exist")
 
496
 
 
497
        self.log_helper.ignored_exception_regexes = [ignore_re]
 
498
 
 
499
    def test_init_landscape_plugins(self):
 
500
        """
 
501
        The landscape plugin which helps managing proxies is loaded when smart
 
502
        is initialized: this sets a smart configuration variable and load the
 
503
        module.
 
504
        """
 
505
        self.facade.reload_channels()
 
506
        self.assertTrue(smart.sysconf.get("use-landscape-proxies"))
 
507
        self.assertIn("smart.plugins.landscape", sys.modules)