Пример #1
0
 def test_associate_already_downloaded_units_negative(self, mock_save, mock_search_all_units):
     mock_search_all_units.return_value = []
     units = model_factory.rpm_models(3)
     for unit in units:
         unit.metadata['relativepath'] = 'test-relative-path'
     result = associate_already_downloaded_units(models.RPM.TYPE, units, self.conduit)
     self.assertEqual(len(list(result)), 3)
Пример #2
0
    def download(self, metadata_files, rpms_to_download, drpms_to_download):
        """
        Actually download the requested RPMs and DRPMs. This method iterates over
        the appropriate metadata file and downloads those items which are present
        in the corresponding set. It also checks for the RPMs and DRPMs which exist
        in other repositories before downloading them. If they are already downloaded,
        we skip the download and just associate them to the given repository.

        :param metadata_files:      populated instance of MetadataFiles
        :type  metadata_files:      pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
        :param rpms_to_download:    set of RPM.NAMEDTUPLEs
        :type  rpms_to_download:    set
        :param drpms_to_download:   set of DRPM.NAMEDTUPLEs
        :type  drpms_to_download:   set

        :rtype: pulp.plugins.model.SyncReport
        """
        # TODO: probably should make this more generic
        event_listener = ContentListener(self.sync_conduit, self.progress_status, self.call_config, metadata_files)
        primary_file_handle = metadata_files.get_metadata_file_handle(primary.METADATA_FILE_NAME)
        try:
            package_model_generator = packages.package_list_generator(primary_file_handle,
                                                                      primary.PACKAGE_TAG,
                                                                      primary.process_package_element)
            units_to_download = self._filtered_unit_generator(package_model_generator, rpms_to_download)
            new_units_to_download = existing.associate_already_downloaded_units(models.RPM.TYPE,
                                                                                units_to_download,
                                                                                self.sync_conduit)

            download_wrapper = packages.Packages(self.sync_feed, self.nectar_config,
                                                 new_units_to_download, self.tmp_dir, event_listener)
            # allow the downloader to be accessed by the cancel method if necessary
            self.downloader = download_wrapper.downloader
            download_wrapper.download_packages()
            self.downloader = None
        finally:
            primary_file_handle.close()

        # download DRPMs
        presto_file_handle = metadata_files.get_metadata_file_handle(presto.METADATA_FILE_NAME)
        if presto_file_handle:
            try:
                package_model_generator = packages.package_list_generator(presto_file_handle,
                                                                          presto.PACKAGE_TAG,
                                                                          presto.process_package_element)
                units_to_download = self._filtered_unit_generator(package_model_generator, drpms_to_download)
                new_units_to_download = existing.associate_already_downloaded_units(models.DRPM.TYPE,
                                                                                    units_to_download,
                                                                                    self.sync_conduit)

                download_wrapper = packages.Packages(self.sync_feed, self.nectar_config,
                                                     new_units_to_download, self.tmp_dir, event_listener)
                # allow the downloader to be accessed by the cancel method if necessary
                self.downloader = download_wrapper.downloader
                download_wrapper.download_packages()
                self.downloader = None
            finally:
                presto_file_handle.close()

        report = self.sync_conduit.build_success_report({}, {})
        return report