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

« back to all changes in this revision

Viewing changes to landscape/package/reporter.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:
10
10
from landscape.lib.sequenceranges import sequence_to_ranges
11
11
from landscape.lib.twisted_util import gather_results
12
12
from landscape.lib.fetch import fetch_async
 
13
from landscape.lib.fs import touch_file
13
14
 
14
15
from landscape.package.taskhandler import (
15
16
    PackageTaskHandlerConfiguration, PackageTaskHandler, run_task_handler)
75
76
 
76
77
        # Finally, verify if we have anything new to report to the server.
77
78
        result.addCallback(lambda x: self.detect_changes())
78
 
        result.addCallback(lambda x: self.detect_package_locks_changes())
79
79
 
80
80
        result.callback(None)
81
81
        return result
200
200
                    self.smart_update_filename, code, err))
201
201
            logging.debug("'%s' exited with status %d (out='%s', err='%s'" % (
202
202
                self.smart_update_filename, code, out, err))
 
203
            touch_file(self._config.smart_update_stamp_filename)
203
204
            return (out, err, code)
204
205
 
205
206
        result.addCallback(callback)
385
386
        return result.addCallbacks(set_message_id, send_message_failed)
386
387
 
387
388
    def detect_changes(self):
 
389
        """Detect all changes concerning packages.
 
390
 
 
391
        If some changes were detected with respect to our last run, then an
 
392
        event of type 'package-data-changed' will be fired in the broker
 
393
        reactor.
 
394
        """
 
395
 
 
396
        def changes_detected(results):
 
397
            # Release all smart locks, in case the changer runs after us.
 
398
            self._facade.deinit()
 
399
            if True in results:
 
400
                # Something has changed, notify the broker.
 
401
                return self._broker.fire_event("package-data-changed")
 
402
 
 
403
        result = gather_results([self.detect_packages_changes(),
 
404
                                 self.detect_package_locks_changes()])
 
405
        return result.addCallback(changes_detected)
 
406
 
 
407
    def detect_packages_changes(self):
388
408
        """Detect changes in the universe of known packages.
389
409
 
390
410
        This method will verify if there are packages that:
403
423
 
404
424
        In all cases, the server is notified of the new situation
405
425
        with a "packages" message.
 
426
 
 
427
        @return: A deferred resulting in C{True} if package changes were
 
428
            detected with respect to the previous run, or C{False} otherwise.
406
429
        """
407
430
        self._facade.ensure_channels_reloaded()
408
431
 
489
512
                list(sequence_to_ranges(sorted(not_locked)))
490
513
 
491
514
        if not message:
492
 
            result = succeed(None)
493
 
        else:
494
 
            message["type"] = "packages"
495
 
 
496
 
            result = self._broker.send_message(message, True)
497
 
 
498
 
            logging.info("Queuing message with changes in known packages: "
499
 
                         "%d installed, %d available, %d available upgrades, "
500
 
                         "%d locked, %d not installed, %d not available, "
501
 
                         "%d not available upgrades, %d not locked."
502
 
                         % (len(new_installed), len(new_available),
503
 
                            len(new_upgrades), len(new_locked),
504
 
                            len(not_installed), len(not_available),
505
 
                            len(not_upgrades), len(not_locked)))
 
515
            return succeed(False)
 
516
 
 
517
        message["type"] = "packages"
 
518
        result = self._broker.send_message(message, True)
 
519
 
 
520
        logging.info("Queuing message with changes in known packages: "
 
521
                     "%d installed, %d available, %d available upgrades, "
 
522
                     "%d locked, %d not installed, %d not available, "
 
523
                     "%d not available upgrades, %d not locked."
 
524
                     % (len(new_installed), len(new_available),
 
525
                        len(new_upgrades), len(new_locked),
 
526
                        len(not_installed), len(not_available),
 
527
                        len(not_upgrades), len(not_locked)))
506
528
 
507
529
        def update_currently_known(result):
508
530
            if new_installed:
521
543
                self._store.remove_available_upgrades(not_upgrades)
522
544
            if not_locked:
523
545
                self._store.remove_locked(not_locked)
 
546
            # Something has changed wrt the former run, let's return True
 
547
            return True
524
548
 
525
549
        result.addCallback(update_currently_known)
526
550
 
536
560
 
537
561
        In all cases, the server is notified of the new situation
538
562
        with a "packages" message.
 
563
 
 
564
        @return: A deferred resulting in C{True} if package lock changes were
 
565
            detected with respect to the previous run, or C{False} otherwise.
539
566
        """
540
567
        old_package_locks = set(self._store.get_package_locks())
541
568
        current_package_locks = set(self._facade.get_package_locks())
550
577
            message["deleted"] = sorted(unset_package_locks)
551
578
 
552
579
        if not message:
553
 
            result = succeed(None)
554
 
        else:
555
 
            message["type"] = "package-locks"
556
 
 
557
 
            result = self._broker.send_message(message, True)
558
 
 
559
 
            logging.info("Queuing message with changes in known package locks:"
560
 
                         " %d created, %d deleted." %
561
 
                         (len(set_package_locks), len(unset_package_locks)))
 
580
            return succeed(False)
 
581
 
 
582
        message["type"] = "package-locks"
 
583
        result = self._broker.send_message(message, True)
 
584
 
 
585
        logging.info("Queuing message with changes in known package locks:"
 
586
                     " %d created, %d deleted." %
 
587
                     (len(set_package_locks), len(unset_package_locks)))
562
588
 
563
589
        def update_currently_known(result):
564
590
            if set_package_locks:
565
591
                self._store.add_package_locks(set_package_locks)
566
592
            if unset_package_locks:
567
593
                self._store.remove_package_locks(unset_package_locks)
 
594
            return True
568
595
 
569
596
        result.addCallback(update_currently_known)
570
597