Exemple #1
0
    def test_some_existing(self):
        postfix = model_factory.rpm_models(1)[0]
        postfix.name = 'postfix'
        vim = model_factory.rpm_models(1)[0]
        vim.name = 'vim-common'
        existing = [
            Unit(postfix.TYPE, postfix.unit_key, postfix.metadata, ''),
            Unit(vim.TYPE, vim.unit_key, vim.metadata, ''),
        ]
        conduit = ImportUnitConduit('', '', '', '')
        conduit.get_destination_units = mock.MagicMock(
            spec_set=conduit.get_destination_units, return_value=existing)

        ret = associate.get_rpms_to_copy_by_name(self.RPM_NAMES, conduit)

        self.assertEqual(set(ret), set(['python-mock']))
        self.assertEqual(conduit.get_destination_units.call_count, 1)
        self.assertTrue(
            isinstance(conduit.get_destination_units.call_args[0][0],
                       UnitAssociationCriteria))
        self.assertEqual(
            conduit.get_destination_units.call_args[0][0].type_ids,
            [models.RPM.TYPE])
        self.assertEqual(
            conduit.get_destination_units.call_args[0][0].unit_fields,
            models.RPM.UNIT_KEY_NAMES)
Exemple #2
0
 def setUp(self):
     super(TestRemoveOldVersions, self).setUp()
     self.rpms = model_factory.rpm_models(3, True)
     self.rpms.extend(model_factory.rpm_models(2, False))
     self.srpms = model_factory.srpm_models(3, True)
     self.srpms.extend(model_factory.srpm_models(2, False))
     self.drpms = model_factory.drpm_models(3, True)
     self.drpms.extend(model_factory.drpm_models(2, False))
Exemple #3
0
 def setUp(self):
     super(TestRemoveOldVersions, self).setUp()
     self.rpms = model_factory.rpm_models(3, True)
     self.rpms.extend(model_factory.rpm_models(2, False))
     self.srpms = model_factory.srpm_models(3, True)
     self.srpms.extend(model_factory.srpm_models(2, False))
     self.drpms = model_factory.drpm_models(3, True)
     self.drpms.extend(model_factory.drpm_models(2, False))
Exemple #4
0
 def test_rpms_check_all_and_associate_negative(self, mock_isfile, mock_save, mock_search_all_units):
     mock_search_all_units.return_value = []
     mock_isfile.return_value = True
     units = model_factory.rpm_models(3)
     input_units = set([unit.as_named_tuple for unit in units])
     result = check_all_and_associate(input_units, self.conduit)
     self.assertEqual(len(list(result)), 3)
Exemple #5
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)
    def test_rpms_to_download(self, mock_package_list_generator, mock_create_downloader):
        """
        test with only RPMs specified to download
        """
        file_handle = StringIO()
        self.metadata_files.get_metadata_file_handle = mock.MagicMock(
            spec_set=self.metadata_files.get_metadata_file_handle,
            side_effect=[file_handle, None], # None means it will skip DRPMs
        )
        rpms = model_factory.rpm_models(3)
        for rpm in rpms:
            rpm.metadata['relativepath'] = self.RELATIVEPATH
        mock_package_list_generator.return_value = rpms
        self.downloader.download = mock.MagicMock(spec_set=self.downloader.download)
        mock_create_downloader.return_value = self.downloader

        # call download, passing in only two of the 3 rpms as units we want
        report = self.reposync.download(self.metadata_files, set(m.as_named_tuple for m in rpms[:2]), set())

        # make sure we skipped DRPMs
        self.assertEqual(self.downloader.download.call_count, 1)
        self.assertEqual(mock_package_list_generator.call_count, 1)

        # verify that the download requests were correct
        requests = list(self.downloader.download.call_args[0][0])
        self.assertEqual(len(requests), 2)
        self.assertEqual(requests[0].url, os.path.join(self.url, self.RELATIVEPATH))
        self.assertEqual(requests[0].destination, os.path.join(self.reposync.tmp_dir, self.RELATIVEPATH))
        self.assertTrue(requests[0].data is rpms[0])
        self.assertEqual(requests[1].url, os.path.join(self.url, self.RELATIVEPATH))
        self.assertEqual(requests[1].destination, os.path.join(self.reposync.tmp_dir, self.RELATIVEPATH))
        self.assertTrue(requests[1].data is rpms[1])
        self.assertTrue(file_handle.closed)
    def test_keep_two(self):
        self.config.override_config[importer_constants.KEY_UNITS_RETAIN_OLD_COUNT] = 1
        units = model_factory.rpm_models(3, True)
        units.extend(model_factory.rpm_models(2))
        for unit in units:
            unit.metadata['size'] = 1024

        # the generator can yield results out of their original order, which is ok
        result = self.reposync._identify_wanted_versions(units)

        self.assertFalse(units[0].as_named_tuple in result)
        self.assertTrue(units[1].as_named_tuple in result)
        self.assertTrue(units[2].as_named_tuple in result)
        self.assertTrue(units[3].as_named_tuple in result)
        self.assertTrue(units[4].as_named_tuple in result)
        for size in result.values():
            self.assertEqual(size, 1024)
    def test_keep_all(self):
        self.config.override_config[importer_constants.KEY_UNITS_RETAIN_OLD_COUNT] = None
        units = model_factory.rpm_models(3)
        for unit in units:
            unit.metadata['size'] = 1024

        result = sorted(self.reposync._identify_wanted_versions(units).keys())

        self.assertEqual([u.as_named_tuple for u in units], result)
    def test_with_to_download(self):
        units = model_factory.rpm_models(3)
        # specify which we want
        to_download = set([unit.as_named_tuple for unit in units[:2]])

        result = list(self.reposync._filtered_unit_generator(units, to_download))

        # make sure we only got the ones we want
        self.assertEqual(result, units[:2])
Exemple #10
0
    def test_rpm(self, mock_copyfile):
        model = model_factory.rpm_models(1)[0]
        unit = Unit(model.TYPE, model.unit_key, model.metadata, '/')

        # passing "None" ensures that the importer isn't being called
        ret = associate._associate_unit('', None, unit)

        self.assertTrue(ret is unit)
        self.assertEqual(mock_copyfile.call_count, 0)
Exemple #11
0
    def test_no_epoch(self):
        rpm = model_factory.rpm_models(1)[0]
        # simulates repos that don't have epochs in their errata
        rpm.epoch = None

        ret = associate._no_checksum_clean_unit_key(rpm.as_named_tuple)

        self.assertTrue(isinstance(ret, dict))
        self.assertTrue('epoch' not in ret)
Exemple #12
0
    def test_no_epoch(self):
        rpm = model_factory.rpm_models(1)[0]
        # simulates repos that don't have epochs in their errata
        rpm.epoch = None

        ret = associate._no_checksum_clean_unit_key(rpm.as_named_tuple)

        self.assertTrue(isinstance(ret, dict))
        self.assertTrue('epoch' not in ret)
Exemple #13
0
    def test_rpm(self, mock_copyfile):
        model = model_factory.rpm_models(1)[0]
        unit = Unit(model.TYPE, model.unit_key, model.metadata, '/')

        # passing "None" ensures that the importer isn't being called
        ret = associate._associate_unit('', None, unit)

        self.assertTrue(ret is unit)
        self.assertEqual(mock_copyfile.call_count, 0)
Exemple #14
0
    def test_all(self):
        rpm = model_factory.rpm_models(1)[0]

        ret = associate._no_checksum_clean_unit_key(rpm.as_named_tuple)

        self.assertTrue(isinstance(ret, dict))
        self.assertTrue('checksum' not in ret)
        self.assertTrue('checksumtype' not in ret)
        for key in ['name', 'epoch', 'version', 'release', 'arch']:
            self.assertEqual(ret[key], rpm.unit_key[key])
Exemple #15
0
    def test_all(self):
        rpm = model_factory.rpm_models(1)[0]

        ret = associate._no_checksum_clean_unit_key(rpm.as_named_tuple)

        self.assertTrue(isinstance(ret, dict))
        self.assertTrue('checksum' not in ret)
        self.assertTrue('checksumtype' not in ret)
        for key in ['name', 'epoch', 'version', 'release', 'arch']:
            self.assertEqual(ret[key], rpm.unit_key[key])
    def test_some_existing(self):
        postfix = model_factory.rpm_models(1)[0]
        postfix.name = 'postfix'
        vim = model_factory.rpm_models(1)[0]
        vim.name = 'vim-common'
        existing = [
            Unit(postfix.TYPE, postfix.unit_key, postfix.metadata, ''),
            Unit(vim.TYPE, vim.unit_key, vim.metadata, ''),
        ]
        conduit = ImportUnitConduit('', '','', '', '', '')
        conduit.get_destination_units = mock.MagicMock(spec_set=conduit.get_destination_units,
                                                       return_value=existing)

        ret = associate.get_rpms_to_copy_by_name(self.RPM_NAMES, conduit)

        self.assertEqual(set(ret), set(['python-mock']))
        self.assertEqual(conduit.get_destination_units.call_count, 1)
        self.assertTrue(isinstance(conduit.get_destination_units.call_args[0][0], UnitAssociationCriteria))
        self.assertEqual(conduit.get_destination_units.call_args[0][0].type_ids, [models.RPM.TYPE])
        self.assertEqual(conduit.get_destination_units.call_args[0][0].unit_fields, models.RPM.UNIT_KEY_NAMES)
Exemple #17
0
 def test_rpms_check_all_and_associate_positive(self, mock_isfile, mock_save, mock_search_all_units):
     units = model_factory.rpm_models(3)
     mock_search_all_units.return_value = units
     mock_isfile.return_value = True
     input_units = set([unit.as_named_tuple for unit in units])
     for unit in units:
         unit.metadata['filename'] = 'test-filename'
         unit.storage_path = "existing_storage_path"
     result = check_all_and_associate(input_units, self.conduit)
     self.assertEqual(len(list(result)), 0)
     # verify we are saving the storage path
     for c in mock_save.mock_calls:
         (conduit, unit) = c[1]
         self.assertEquals(unit.storage_path, "existing_storage_path")
Exemple #18
0
    def test_remove_missing_units(self, mock_get_existing):
        self.conduit.remove_unit = mock.MagicMock(spec_set=self.conduit.remove_unit)
        # setup such that only one of the 2 existing units appears to be present
        # in the remote repo, thus the other unit should be purged
        mock_get_existing.return_value = model_factory.rpm_units(2)
        remote_named_tuples = set(model.as_named_tuple for model in model_factory.rpm_models(2))
        common_unit = mock_get_existing.return_value[1]
        common_named_tuple = models.RPM.NAMEDTUPLE(**common_unit.unit_key)
        remote_named_tuples.add(common_named_tuple)

        purge.remove_missing_units(self.conduit, models.RPM, remote_named_tuples)

        mock_get_existing.assert_called_once_with(models.RPM, self.conduit.get_units)
        self.conduit.remove_unit.assert_called_once_with(mock_get_existing.return_value[0])
Exemple #19
0
    def test_remove_missing_units(self, mock_get_existing):
        self.conduit.remove_unit = mock.MagicMock(spec_set=self.conduit.remove_unit)
        # setup such that only one of the 2 existing units appears to be present
        # in the remote repo, thus the other unit should be purged
        mock_get_existing.return_value = model_factory.rpm_units(2)
        remote_named_tuples = set(model.as_named_tuple for model in model_factory.rpm_models(2))
        common_unit = mock_get_existing.return_value[1]
        common_named_tuple = models.RPM.NAMEDTUPLE(**common_unit.unit_key)
        remote_named_tuples.add(common_named_tuple)

        purge.remove_missing_units(self.conduit, models.RPM, remote_named_tuples)

        mock_get_existing.assert_called_once_with(models.RPM, self.conduit.get_units)
        self.conduit.remove_unit.assert_called_once_with(mock_get_existing.return_value[0])
Exemple #20
0
    def test_rpm(self, mock_open, mock_package_list_generator):
        rpms = model_factory.rpm_models(2)
        mock_package_list_generator.return_value = rpms
        fake_file = StringIO()
        mock_open.return_value = fake_file
        process_func = lambda x: x

        ret = purge.get_remote_units(self.metadata_files, self.FAKE_TYPE, 'bar', process_func)

        mock_open.assert_called_once_with('/a/b/c', 'r')
        self.assertTrue(fake_file.closed)
        mock_package_list_generator.assert_called_once_with(fake_file, 'bar', process_func)
        self.assertEqual(len(rpms), len(ret))
        for model in rpms:
            self.assertTrue(model.as_named_tuple in ret)
    def test_with_existing_deps(self, mock_find, mock_get_existing):
        conduit = mock.MagicMock()
        rpms = model_factory.rpm_units(1)
        deps = model_factory.rpm_models(2)
        dep_units = [Unit(model.TYPE, model.unit_key, model.metadata, '') for model in deps]
        mock_find.return_value = [r.as_named_tuple for r in deps]
        mock_get_existing.return_value = dep_units

        associate.copy_rpms(rpms, conduit, True)

        self.assertEqual(conduit.associate_unit.call_count, 1)
        self.assertEqual(mock_find.call_count, 1)
        self.assertEqual(mock_find.call_args[0][0], set(rpms))
        # called once directly, and once from filter_available_rpms
        self.assertEqual(mock_get_existing.call_count, 2)
Exemple #22
0
    def test_calls_identify_wanted_and_existing(self, mock_check_repo, mock_identify,
                                                mock_generator, mock_open):
        primary_file = StringIO()
        mock_open.return_value = primary_file
        model = model_factory.rpm_models(1)[0]
        self.metadata_files.metadata[primary.METADATA_FILE_NAME] = {'local_path': '/path/to/primary'}
        mock_generator.return_value = [model.as_named_tuple]
        mock_identify.return_value = {model.as_named_tuple: 1024}
        mock_check_repo.return_value = set([model.as_named_tuple])

        ret = self.reposync._decide_rpms_to_download(self.metadata_files)

        self.assertEqual(ret, (set([model.as_named_tuple]), 1, 1024))
        mock_open.assert_called_once_with('/path/to/primary', 'r')
        mock_generator.assert_called_once_with(primary_file, primary.PACKAGE_TAG, primary.process_package_element)
        mock_identify.assert_called_once_with(mock_generator.return_value)
        self.assertTrue(primary_file.closed)
Exemple #23
0
    def test_none_to_download(self, mock_package_list_generator):
        """
        make sure it does nothing if there are no units specified to download
        """
        self.metadata_files.get_metadata_file_handle = mock.MagicMock(
            spec_set=self.metadata_files.get_metadata_file_handle,
            side_effect=StringIO,
        )
        mock_package_list_generator.side_effect = iter([model_factory.rpm_models(3),
                                                    model_factory.drpm_models(3)])

        report = self.reposync.download(self.metadata_files, set(), set())

        self.assertTrue(report.success_flag)
        self.assertEqual(report.added_count, 0)
        self.assertEqual(report.removed_count, 0)
        self.assertEqual(report.updated_count, 0)
Exemple #24
0
    def test_rpm(self, mock_open, mock_package_list_generator):
        rpms = model_factory.rpm_models(2)
        mock_package_list_generator.return_value = rpms
        fake_file = StringIO()
        mock_open.return_value = fake_file

        def process_func(x):
            return x

        file_function = functools.partial(self.metadata_files.get_metadata_file_handle, self.FAKE_TYPE)
        ret = purge.get_remote_units(file_function, "bar", process_func)

        mock_open.assert_called_once_with("/a/b/c", "r")
        self.assertTrue(fake_file.closed)
        mock_package_list_generator.assert_called_once_with(fake_file, "bar", process_func)
        self.assertEqual(len(rpms), len(ret))
        for model in rpms:
            self.assertTrue(model.as_named_tuple in ret)
Exemple #25
0
    def test_rpm(self, mock_open, mock_package_list_generator):
        rpms = model_factory.rpm_models(2)
        mock_package_list_generator.return_value = rpms
        fake_file = StringIO()
        mock_open.return_value = fake_file

        def process_func(x):
            return x
        file_function = functools.partial(self.metadata_files.get_metadata_file_handle,
                                          self.FAKE_TYPE)
        ret = purge.get_remote_units(file_function, 'bar', process_func)

        mock_open.assert_called_once_with('/a/b/c', 'r')
        self.assertTrue(fake_file.closed)
        mock_package_list_generator.assert_called_once_with(fake_file, 'bar', process_func)
        self.assertEqual(len(rpms), len(ret))
        for model in rpms:
            self.assertTrue(model.as_named_tuple in ret)
    def test_with_recursive_deps(self, mock_find, mock_get_existing, mock_filter):
        """
        Test getting dependencies that do not exist in the repository already
        """
        conduit = mock.MagicMock()
        # Create the primary RPMS that we want to copy
        rpms = model_factory.rpm_units(1)

        # Create the recursive dependencies that we want to copy
        deps = model_factory.rpm_models(2)
        dep_units = [Unit(model.TYPE, model.unit_key, model.metadata, '') for model in deps]

        # the first call to filter gets all the dependencies for the parent repository
        # The second time it is called during the recursion and all the units have already
        # been copied.
        mock_filter.side_effect = iter([dep_units, []])
        # The get existing units always assumes there are no units in the target repository
        mock_get_existing.return_value = []
        unit_set = associate.copy_rpms(rpms, conduit, True)

        merged_set = set(dep_units)
        merged_set.update(rpms)
        self.assertEquals(unit_set, merged_set)
Exemple #27
0
    def test_all(self, mock_decide_drpms, mock_decide_rpms):
        rpm_model = model_factory.rpm_models(1)[0]
        drpm_model = model_factory.drpm_models(1)[0]
        mock_decide_rpms.return_value = (set([rpm_model.as_named_tuple]), 1, 1024)
        mock_decide_drpms.return_value = (set([drpm_model.as_named_tuple]), 1, 1024)
        self.conduit.set_progress = mock.MagicMock(spec_set=self.conduit.set_progress)

        ret = self.reposync._decide_what_to_download(self.metadata_files)

        self.assertEqual(ret[0], set([rpm_model.as_named_tuple]))
        self.assertEqual(ret[1], set([drpm_model.as_named_tuple]))
        self.assertEqual(len(ret), 2)
        mock_decide_rpms.assert_called_once_with(self.metadata_files)
        mock_decide_drpms.assert_called_once_with(self.metadata_files)
        self.assertEqual(self.conduit.set_progress.call_count, 1)

        # make sure we reported initial progress values correctly
        report = self.conduit.set_progress.call_args[0][0]
        self.assertEqual(report['content']['size_total'], 2048)
        self.assertEqual(report['content']['size_left'], 2048)
        self.assertEqual(report['content']['items_total'], 2)
        self.assertEqual(report['content']['items_left'], 2)
        self.assertEqual(report['content']['details']['rpm_total'], 1)
        self.assertEqual(report['content']['details']['drpm_total'], 1)
Exemple #28
0
    def test_without_to_download(self):
        units = model_factory.rpm_models(3)

        result = list(self.reposync._filtered_unit_generator(units))

        self.assertEqual(units, result)