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

« back to all changes in this revision

Viewing changes to landscape/package/taskhandler.py

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Free Ekanayaka
  • Date: 2009-07-22 14:54:50 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090722145450-pvbp13gh8734c8ft
Tags: 1.3.2.2-0ubuntu0.9.10.1
[ Free Ekanayaka ]
* New upstream release:
  - 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
1
import os
 
2
import logging
2
3
 
3
4
from twisted.internet.defer import Deferred, succeed
4
5
 
5
6
from landscape.lib.dbus_util import get_bus
6
7
from landscape.lib.lock import lock_path, LockError
7
8
from landscape.lib.log import log_failure
 
9
from landscape.lib.command import run_command, CommandError
8
10
from landscape.deployment import Configuration, init_logging
9
 
from landscape.package.store import PackageStore
 
11
from landscape.package.store import PackageStore, InvalidHashIdDb
10
12
from landscape.broker.remote import RemoteBroker
11
13
 
12
14
 
14
16
 
15
17
    queue_name = "default"
16
18
 
17
 
    def __init__(self, package_store, package_facade, remote_broker):
 
19
    def __init__(self, package_store, package_facade, remote_broker, config):
18
20
        self._store = package_store
19
21
        self._facade = package_facade
20
22
        self._broker = remote_broker
 
23
        self._config = config
21
24
        self._channels_reloaded = False
 
25
        self._server_uuid = None
22
26
 
23
27
    def ensure_channels_reloaded(self):
24
28
        if not self._channels_reloaded:
53
57
    def handle_task(self, task):
54
58
        return succeed(None)
55
59
 
 
60
    def use_hash_id_db(self):
 
61
        """
 
62
        Attach the appropriate pre-canned hash=>id database to our store.
 
63
        """
 
64
 
 
65
        def use_it(hash_id_db_filename):
 
66
 
 
67
            if hash_id_db_filename is None:
 
68
                # Couldn't determine which hash=>id database to use,
 
69
                # just ignore the failure and go on
 
70
                return
 
71
 
 
72
            if not os.path.exists(hash_id_db_filename):
 
73
                # The appropriate database isn't there, but nevermind
 
74
                # and just go on
 
75
                return
 
76
 
 
77
            try:
 
78
                self._store.add_hash_id_db(hash_id_db_filename)
 
79
            except InvalidHashIdDb:
 
80
                # The appropriate database is there but broken,
 
81
                # let's remove it and go on
 
82
                logging.warning("Invalid hash=>id database %s" %
 
83
                                hash_id_db_filename)
 
84
                os.remove(hash_id_db_filename)
 
85
                return
 
86
 
 
87
        result = self._determine_hash_id_db_filename()
 
88
        result.addCallback(use_it)
 
89
        return result
 
90
 
 
91
    def _determine_hash_id_db_filename(self):
 
92
        """Build up the filename of the hash=>id database to use.
 
93
 
 
94
        @return: a deferred resulting in the filename to use or C{None}
 
95
            in case of errors.
 
96
        """
 
97
 
 
98
        def got_server_uuid(server_uuid):
 
99
 
 
100
            warning = "Couldn't determine which hash=>id database to use: %s"
 
101
 
 
102
            if server_uuid is None:
 
103
                logging.warning(warning % "server UUID not available")
 
104
                return None
 
105
 
 
106
            try:
 
107
                # XXX replace this with a L{SmartFacade} method
 
108
                codename = run_command("lsb_release -cs")
 
109
            except CommandError, error:
 
110
                logging.warning(warning % str(error))
 
111
                return None
 
112
 
 
113
            arch = self._facade.get_arch()
 
114
            if arch is None:
 
115
                # The Smart code should always return a proper string, so this
 
116
                # branch shouldn't get executed at all. However this check is
 
117
                # kept as an extra paranoia sanity check.
 
118
                logging.warning(warning % "unknown dpkg architecture")
 
119
                return None
 
120
 
 
121
            package_directory = os.path.join(self._config.data_path, "package")
 
122
            hash_id_db_directory = os.path.join(package_directory, "hash-id")
 
123
 
 
124
            return os.path.join(hash_id_db_directory,
 
125
                                "%s_%s_%s" % (server_uuid,
 
126
                                              codename,
 
127
                                              arch))
 
128
 
 
129
        result = self._broker.get_server_uuid()
 
130
        result.addCallback(got_server_uuid)
 
131
        return result
 
132
 
56
133
 
57
134
def run_task_handler(cls, args, reactor=None):
58
135
    from twisted.internet.glib2reactor import install
69
146
    config.load(args)
70
147
 
71
148
    package_directory = os.path.join(config.data_path, "package")
72
 
    if not os.path.isdir(package_directory):
73
 
        os.mkdir(package_directory)
 
149
    hash_id_directory = os.path.join(package_directory, "hash-id")
 
150
    for directory in [package_directory, hash_id_directory]:
 
151
        if not os.path.isdir(directory):
 
152
            os.mkdir(directory)
74
153
 
75
154
    lock_filename = os.path.join(package_directory, program_name + ".lock")
76
155
    try:
98
177
    package_facade = SmartFacade()
99
178
    remote = RemoteBroker(get_bus(config.bus))
100
179
 
101
 
    handler = cls(package_store, package_facade, remote)
 
180
    handler = cls(package_store, package_facade, remote, config)
102
181
 
103
182
    def got_err(failure):
104
183
        log_failure(failure)