Пример #1
0
    def test__filter_missing_isos_available_isos(self):
        """
        Test that when there are units in Pulp that match those in the manifest, but that are
        not currently associated with the repository, they are returned by _filter_missing_isos
        as the second list in the 3-tuple.
        """
        # Let's put all three mammajammas in the manifest
        manifest = ['%s,%s,%s' % (iso.unit_key['name'], iso.unit_key['checksum'],
                                  iso.unit_key['size']) for iso in self.existing_units]
        manifest = '\n'.join(manifest)
        manifest = StringIO(manifest)
        manifest = models.ISOManifest(manifest, 'http://test.com')

        # Set up the sync conduit to return all three units as units in Pulp, but only the first
        # is associated with the repository
        sync_conduit = importer_mocks.get_sync_conduit(pkg_dir=self.pkg_dir,
                                                       existing_units=[self.existing_units[0]],
                                                       pulp_units=self.existing_units)
        iso_sync_run = ISOSyncRun(sync_conduit, self.config)

        filtered_isos = iso_sync_run._filter_missing_isos(manifest)
        local_missing_isos, local_available_isos, remote_missing_isos = filtered_isos

        # Everything except the first unit should be in the list of local available isos
        self.assertEqual(0, len(local_missing_isos))
        self.assertEqual(2, len(local_available_isos))
        for expected, actual in zip(sorted(self.existing_units[1:]), sorted(local_available_isos)):
            self.assertEqual(expected, actual)
Пример #2
0
    def _download_manifest(self):
        """
        Download the manifest file, and process it to return an ISOManifest.

        :return: manifest of available ISOs
        :rtype:  pulp_rpm.plugins.db.models.ISOManifest
        """
        manifest_url = urljoin(self._repo_url, models.ISOManifest.FILENAME)
        # I probably should have called this manifest destination, but I couldn't help myself
        manifest_destiny = StringIO()
        manifest_request = request.DownloadRequest(manifest_url,
                                                   manifest_destiny)
        self.downloader.download([manifest_request])
        # We can inspect the report status to see if we had an error when retrieving the manifest.
        if self.progress_report.state == self.progress_report.STATE_MANIFEST_FAILED:
            raise IOError(
                _("Could not retrieve %(url)s") % {'url': manifest_url})

        manifest_destiny.seek(0)
        try:
            manifest = models.ISOManifest(manifest_destiny, self._repo_url)
        except ValueError:
            self.progress_report.error_message = _(
                'The PULP_MANIFEST file was not in the ' + 'expected format.')
            self.progress_report.state = self.progress_report.STATE_MANIFEST_FAILED
            raise ValueError(self.progress_report.error_message)

        return manifest
Пример #3
0
    def test__filter_missing_isos(self):
        """
        Make sure this method returns the items from the manifest that weren't in the
        sync_conduit. By
        default, remove_missing_units is False, so we will also assert that the return value of
        this method
        doesn't suggest removing any ISOs.
        """
        # Let's put all three mammajammas in the manifest
        manifest = ['%s,%s,%s' % (iso.unit_key['name'], iso.unit_key['checksum'],
                                  iso.unit_key['size'])
                    for iso in self.existing_units if iso.unit_key['name'] != 'test4.iso']
        manifest = '\n'.join(manifest)
        manifest = StringIO(manifest)
        manifest = models.ISOManifest(manifest, 'http://test.com')

        filtered_isos = self.iso_sync_run._filter_missing_isos(manifest)
        local_missing_isos, local_available_isos, remote_missing_isos = filtered_isos

        # Only the third item from the manifest should be missing locally
        self.assertEqual(local_missing_isos, [iso for iso in manifest if iso.name == 'test3.iso'])
        # The remote repo doesn't have test4.iso, and so this method should tell us
        self.assertEqual(len(remote_missing_isos), 1)
        remote_missing_iso = remote_missing_isos[0]
        self.assertEqual(remote_missing_iso.unit_key,
                         {'name': 'test4.iso', 'size': 4, 'checksum': 'sum4'})
Пример #4
0
    def test___len__(self):
        """
        The ISOManifest should support the use of len() to return the number of ISOs it contains.
        """
        manifest_file = StringIO()
        manifest_file.write('test1.iso,checksum1,1\ntest2.iso,checksum2,2\ntest3.iso,checksum3,3')
        repo_url = 'http://awesomestuff.com/repo/'

        manifest = models.ISOManifest(manifest_file, repo_url)

        self.assertEqual(len(manifest), 3)
Пример #5
0
    def test___iter__(self):
        """
        Test the ISOManifest's __iter__() method.
        """
        manifest_file = StringIO()
        manifest_file.write('test1.iso,checksum1,1\ntest2.iso,checksum2,2\ntest3.iso,checksum3,3')
        repo_url = 'http://awesomestuff.com/repo/'

        manifest = models.ISOManifest(manifest_file, repo_url)

        num_isos = 0
        for iso in manifest:
            self.assertTrue(isinstance(iso, models.ISO))
            num_isos += 1
        self.assertEqual(num_isos, 3)
Пример #6
0
    def test__download_isos(self, mock_download):
        mock_download.side_effect = self.fake_download

        # We need to mark the iso_downloader as being in the ISO downloading state
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS
        # Let's put three ISOs in the manifest
        manifest = StringIO()
        manifest.write(
            'test.iso,f02d5a72cd2d57fa802840a76b44c6c6920a8b8e6b90b20e26c03876275069e0,16\n'
        )
        manifest.write(
            'test2.iso,c7fbc0e821c0871805a99584c6a384533909f68a6bbe9a2a687d28d9f3b10c16,22\n'
        )
        manifest.write(
            'test3.iso,94f7fe923212286855dea858edac1b4a292301045af0ddb275544e5251a50b3c,34'
        )
        manifest.seek(0)
        manifest = models.ISOManifest(manifest, 'https://fake.com/')
        # Add expected test data to each ISO
        manifest._isos[0].expected_test_data = 'This is a file.\n'
        manifest._isos[1].expected_test_data = 'This is another file.\n'
        manifest._isos[
            2].expected_test_data = 'Are you starting to get the idea?\n'

        self.iso_sync_run._download_isos(manifest)

        # There should have been two calls to the sync_conduit per ISO, for a total of six calls.
        #  Once each to
        # initialize the unit, and once each to save it
        self.assertEqual(self.sync_conduit.init_unit.call_count, 3)
        self.assertEqual(self.sync_conduit.save_unit.call_count, 3)

        for index, iso in enumerate(manifest):
            expected_relative_path = os.path.join(iso.name, iso.checksum,
                                                  str(iso.size), iso.name)
            self.sync_conduit.init_unit.assert_any_call(
                TYPE_ID_ISO, {
                    'name': iso.name,
                    'size': iso.size,
                    'checksum': iso.checksum
                }, {server_constants.PULP_USER_METADATA_FIELDNAME: {}},
                expected_relative_path)
            unit = self.sync_conduit.save_unit.call_args_list[index][0][0]
            self.assertEqual(unit.unit_key['name'], iso.name)
            self.assertEqual(unit.unit_key['checksum'], iso.checksum)
            self.assertEqual(unit.unit_key['size'], iso.size)
Пример #7
0
    def test___init__(self):
        """
        Assert good behavior from the __init__() method.
        """
        manifest_file = StringIO()
        manifest_file.write('test1.iso,checksum1,1\ntest2.iso,checksum2,2\ntest3.iso,checksum3,3')
        repo_url = 'http://awesomestuff.com/repo/'

        manifest = models.ISOManifest(manifest_file, repo_url)

        # There should be three ISOs with all the right stuff
        self.assertEqual(len(manifest._isos), 3)
        for index, iso in enumerate(manifest._isos):
            self.assertEqual(iso.name, 'test%s.iso' % (index + 1))
            self.assertEqual(iso.size, index + 1)
            self.assertEqual(iso.checksum, 'checksum%s' % (index + 1))
            self.assertEqual(iso.url, urljoin(repo_url, iso.name))
            self.assertEqual(iso._unit, None)