~ubuntu-branches/ubuntu/trusty/landscape-client/trusty-proposed

« back to all changes in this revision

Viewing changes to landscape/package/releaseupgrader.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-04-07 16:27:45 UTC
  • mfrom: (1.1.14 upstream) (24.1.1 karmic-proposed)
  • Revision ID: james.westby@ubuntu.com-20100407162745-oeyoppvl0qyvii55
Tags: 1.5.0-0ubuntu0.10.04.0
* 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: #522688)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from landscape.lib.fetch import url_to_filename, fetch_to_files
16
16
from landscape.lib.lsb_release import parse_lsb_release, LSB_RELEASE_FILENAME
17
17
from landscape.lib.gpg import gpg_verify
 
18
from landscape.lib.fs import read_file
18
19
from landscape.package.taskhandler import (
19
20
    PackageTaskHandlerConfiguration, PackageTaskHandler, run_task_handler)
20
21
from landscape.manager.manager import SUCCEEDED, FAILED
33
34
 
34
35
 
35
36
class ReleaseUpgrader(PackageTaskHandler):
36
 
    """Perform release upgrades."""
 
37
    """Perform release upgrades.
 
38
 
 
39
    @cvar config_factory: The configuration class to use to build configuration
 
40
        objects to be passed to our constructor.
 
41
    @cvar queue_name: The queue we pick tasks from.
 
42
    @cvar lsb_release_filename: The path to the LSB data on the file system.
 
43
    @cvar landscape_ppa_url: The URL of the Landscape PPA, if it is present
 
44
        in the computer's sources.list it won't be commented out.
 
45
    @cvar logs_directory: Path to the directory holding the upgrade-tool logs.
 
46
    @cvar logs_limit: When reporting upgrade-tool logs to the server, only the
 
47
        last C{logs_limit} lines will be sent.
 
48
    """
37
49
 
38
50
    config_factory = ReleaseUpgraderConfiguration
39
51
    queue_name = "release-upgrader"
40
52
    lsb_release_filename = LSB_RELEASE_FILENAME
41
 
    landscape_ppa_url = "http://ppa.launchpad.net/landscape/ppa/ubuntu/"
 
53
    landscape_ppa_url = "http://ppa.launchpad.net/landscape/trunk/ubuntu/"
 
54
    logs_directory = "/var/log/dist-upgrade"
 
55
    logs_limit = 100000
42
56
 
43
57
    def make_operation_result_message(self, operation_id, status, text, code):
44
58
        """Convenience to create messages of type C{"operation-result"}."""
180
194
            if not config.has_section("Distro"):
181
195
                config.add_section("Distro")
182
196
            if not config.has_option("Distro", "PostInstallScripts"):
183
 
                config.set("Distro", "PostInstallScripts", "./dbus/sh")
 
197
                config.set("Distro", "PostInstallScripts", "./dbus.sh")
184
198
            else:
185
199
                scripts = config.get("Distro", "PostInstallScripts")
186
200
                scripts += ", ./dbus.sh"
210
224
 
211
225
        return succeed(None)
212
226
 
 
227
    def make_operation_result_text(self, out, err):
 
228
        """Return the operation result text to be sent to the server.
 
229
 
 
230
        @param out: The standard output of the upgrade-tool process.
 
231
        @param err: The standard error of the upgrade-tool process.
 
232
        @return: A text aggregating the process output, error and log files.
 
233
        """
 
234
        buf = cStringIO.StringIO()
 
235
 
 
236
        for label, content in [("output", out), ("error", err)]:
 
237
            if content:
 
238
                buf.write("=== Standard %s ===\n\n%s\n\n" % (label, content))
 
239
 
 
240
        for basename in sorted(os.listdir(self.logs_directory)):
 
241
            if not basename.endswith(".log"):
 
242
                continue
 
243
            filename = os.path.join(self.logs_directory, basename)
 
244
            content = read_file(filename, - self.logs_limit)
 
245
            buf.write("=== %s ===\n\n%s\n\n" % (basename, content))
 
246
 
 
247
        return buf.getvalue()
 
248
 
213
249
    def upgrade(self, code_name, operation_id, allow_third_party=False,
214
250
                debug=False, mode=None):
215
251
        """Run the upgrade-tool command and send a report of the results.
267
303
                status = SUCCEEDED
268
304
            else:
269
305
                status = FAILED
270
 
            message = self.make_operation_result_message(
271
 
                operation_id, status, "%s%s" % (out, err), code)
 
306
            text = self.make_operation_result_text(out, err)
 
307
            message = self.make_operation_result_message(operation_id, status,
 
308
                                                         text, code)
272
309
            logging.info("Queuing message with release upgrade results to "
273
310
                         "exchange urgently.")
274
311
            return self._broker.send_message(message, True)