Esempio n. 1
0
            def callback((out, err, code)):
                accepted_apt_errors = (
                    "Problem renaming the file /var/cache/apt/srcpkgcache.bin",
                    "Problem renaming the file /var/cache/apt/pkgcache.bin")

                touch_file(self._config.update_stamp_filename)
                logging.debug(
                    "'%s' exited with status %d (out='%s', err='%s')" % (
                        self.apt_update_filename, code, out, err))

                if code != 0:
                    logging.warning("'%s' exited with status %d (%s)" % (
                        self.apt_update_filename, code, err))

                    # Errors caused by missing cache files are acceptable, as
                    # they are not an issue for the lists update process.
                    # These errors can happen if an 'apt-get clean' is run
                    # while 'apt-get update' is running.
                    for message in accepted_apt_errors:
                        if message in err:
                            out, err, code = "", "", 0
                            break

                elif not self._facade.get_channels():
                    code = 1
                    err = ("There are no APT sources configured in %s or %s." %
                           (self.sources_list_filename,
                            self.sources_list_directory))

                deferred = self._broker.call_if_accepted(
                    "package-reporter-result", self.send_result, code, err)
                deferred.addCallback(lambda ignore: (out, err, code))
                return deferred
Esempio n. 2
0
 def update_currently_known(result):
     if new_installed:
         self._store.add_installed(new_installed)
     if not_installed:
         self._store.remove_installed(not_installed)
     if new_available:
         self._store.add_available(new_available)
     if new_locked:
         self._store.add_locked(new_locked)
     if new_autoremovable:
         self._store.add_autoremovable(new_autoremovable)
     if not_available:
         self._store.remove_available(not_available)
     if new_upgrades:
         self._store.add_available_upgrades(new_upgrades)
     if not_upgrades:
         self._store.remove_available_upgrades(not_upgrades)
     if not_locked:
         self._store.remove_locked(not_locked)
     if not_autoremovable:
         self._store.remove_autoremovable(not_autoremovable)
     if new_security:
         self._store.add_security(new_security)
     if not_security:
         self._store.remove_security(not_security)
     # Something has changed wrt the former run, let's update the
     # timestamp and return True.
     stamp_file = self._config.detect_package_changes_stamp
     touch_file(stamp_file)
     return True
Esempio n. 3
0
 def test_touch_file_multiple_times(self):
     """
     The L{touch_file} function can be called multiple times.
     """
     path = self.makeFile()
     touch_file(path)
     touch_file(path)
     self.assertFileContent(path, b"")
Esempio n. 4
0
 def test_touch_file(self, utime_mock):
     """
     The L{touch_file} function touches a file, setting its last
     modification time.
     """
     path = self.makeFile()
     touch_file(path)
     utime_mock.assert_called_once_with(path, None)
     self.assertFileContent(path, b"")
Esempio n. 5
0
 def test_wb_should_run(self):
     """
     If the Rados library is present with the correct version and a ceph
     config exists, the C{_should_run} method returns True.
     """
     plugin = CephUsage()
     plugin._has_rados = True
     plugin._ceph_config = self.makeFile()
     touch_file(plugin._ceph_config)
     self.assertTrue(plugin._should_run())
Esempio n. 6
0
 def _ensure_dir_structure(self):
     apt_dir = self._ensure_sub_dir("etc/apt")
     self._ensure_sub_dir("etc/apt/sources.list.d")
     self._ensure_sub_dir("var/cache/apt/archives/partial")
     self._ensure_sub_dir("var/lib/apt/lists/partial")
     dpkg_dir = self._ensure_sub_dir("var/lib/dpkg")
     self._ensure_sub_dir("var/lib/dpkg/info")
     self._ensure_sub_dir("var/lib/dpkg/updates")
     self._ensure_sub_dir("var/lib/dpkg/triggers")
     create_text_file(os.path.join(dpkg_dir, "available"), "")
     self._dpkg_status = os.path.join(dpkg_dir, "status")
     if not os.path.exists(self._dpkg_status):
         create_text_file(self._dpkg_status, "")
     # Apt will fail if it does not have a keyring.  It does not care if
     # the keyring is empty.
     touch_file(os.path.join(apt_dir, "trusted.gpg"))
Esempio n. 7
0
    def test_touch_file_with_offset_seconds(self):
        """
        The L{touch_file} function can be called with a offset in seconds that
        will be reflected in the access and modification times of the file.
        """
        path = self.makeFile()
        current_time = long(time.time())
        expected_time = current_time - 1

        with patch.object(time, "time",
                          return_value=current_time) as time_mock:
            with patch.object(os, "utime") as utime_mock:
                touch_file(path, offset_seconds=-1)

        time_mock.assert_called_once_with()
        utime_mock.assert_called_once_with(path,
                                           (expected_time, expected_time))

        self.assertFileContent(path, b"")
Esempio n. 8
0
    def run_apt_update(self):
        """
        Check if an L{_apt_update} call must be performed looping over specific
        delays so it can be retried.

        @return: a deferred returning (out, err, code)
        """
        if (self._config.force_apt_update or
            self._apt_sources_have_changed() or
            self._apt_update_timeout_expired(self._config.apt_update_interval)
            ) and \
           not self._is_release_upgrader_running():

            accepted_apt_errors = (
                "Problem renaming the file /var/cache/apt/srcpkgcache.bin",
                "Problem renaming the file /var/cache/apt/pkgcache.bin")

            for retry in range(len(LOCK_RETRY_DELAYS)):
                deferred = Deferred()
                self._reactor.call_later(
                    LOCK_RETRY_DELAYS[retry], self._apt_update, deferred)
                out, err, code = yield deferred
                out = out.decode("utf-8")
                err = err.decode("utf-8")

                timestamp = self._reactor.time()

                touch_file(self._config.update_stamp_filename)
                logging.debug(
                    "'%s' exited with status %d (out='%s', err='%s')" % (
                        self.apt_update_filename, code, out, err))

                if code != 0:
                    if code == 100:
                        if retry < len(LOCK_RETRY_DELAYS) - 1:
                            logging.warning(
                                "Could not acquire the apt lock. Retrying in"
                                " %s seconds." % LOCK_RETRY_DELAYS[retry + 1])
                            continue

                    logging.warning("'%s' exited with status %d (%s)" % (
                        self.apt_update_filename, code, err))

                    # Errors caused by missing cache files are acceptable,
                    # as they are not an issue for the lists update
                    # process.
                    # These errors can happen if an 'apt-get clean' is run
                    # while 'apt-get update' is running.
                    for message in accepted_apt_errors:
                        if message in err:
                            out, err, code = "", "", 0
                            break

                elif not self._facade.get_channels():
                    code = 1
                    err = ("There are no APT sources configured in %s or %s." %
                           (self.sources_list_filename,
                            self.sources_list_directory))

                yield self._broker.call_if_accepted(
                    "package-reporter-result", self.send_result, timestamp,
                    code, err)
                yield returnValue((out, err, code))
        else:
            logging.debug("'%s' didn't run, conditions not met" %
                          self.apt_update_filename)
            yield returnValue(("", "", 0))