Пример #1
0
    def test_sync(self):
        """Sync repositories with the rpm plugin.

        In order to sync a repository a remote has to be associated within
        this repository. When a repository is created this version field is set
        as None. After a sync the repository version is updated.

        Do the following:

        1. Create a repository and a remote.
        2. Assert that repository version is None.
        3. Sync the remote.
        4. Assert that repository version is not None.
        5. Assert that the correct number of units were added and are present
           in the repo.
        6. Sync the remote one more time.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of are present and that no units were
           added.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Create a remote with the standard test fixture url.
        body = gen_rpm_remote()
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Check that we have the correct content counts.
        self.assertIsNotNone(repo['_latest_version_href'])
        self.assertDictEqual(get_content_summary(repo),
                             RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), RPM_FIXTURE_COUNT)

        # Sync the repository again.
        latest_version_href = repo['_latest_version_href']
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Check that nothing has changed since the last sync.
        self.assertNotEqual(latest_version_href, repo['_latest_version_href'])
        self.assertDictEqual(get_content_summary(repo),
                             RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), 0)
Пример #2
0
    def test_sync(self):
        """Sync repositories with the rpm plugin.

        In order to sync a repository a remote has to be associated within
        this repository. When a repository is created this version field is set
        as None. After a sync the repository version is updated.

        Do the following:

        1. Create a repository and a remote.
        2. Assert that repository version is None.
        3. Sync the remote.
        4. Assert that repository version is not None.
        5. Assert that the correct number of units were added and are present
        in the repo.
        6. Sync the remote one more time.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of are present and that no units were added.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Create a remote with the standard test fixture url.
        body = gen_rpm_remote()
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Check that we have the correct content counts.
        self.assertIsNotNone(repo['_latest_version_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), RPM_FIXTURE_COUNT)

        # Sync the repository again.
        latest_version_href = repo['_latest_version_href']
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Check that nothing has changed since the last sync.
        self.assertNotEqual(latest_version_href, repo['_latest_version_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), 0)
Пример #3
0
    def test_all(self):
        """Test content promotion for a distribution.

        This test targets the following issue:

        * `Pulp #4186 <https://pulp.plan.io/issues/4186>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publication.
        3. Create 2 distributions - using the same publication. Those
           distributions will have different ``base_path``.
        4. Assert that distributions have the same publication.
        5. Select a content unit. Download that content unit from Pulp using
           the two different distributions.
           Assert that content unit has the same checksum when fetched from
           different distributions.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo["pulp_href"])

        remote = client.post(FILE_REMOTE_PATH,
                             gen_remote(FILE_FIXTURE_MANIFEST_URL))
        self.addCleanup(client.delete, remote["pulp_href"])

        sync(cfg, remote, repo)
        repo = client.get(repo["pulp_href"])

        publication = create_file_publication(cfg, repo)
        self.addCleanup(client.delete, publication["pulp_href"])

        distributions = []
        for _ in range(2):
            body = gen_distribution()
            body["publication"] = publication["pulp_href"]
            distribution = client.using_handler(api.task_handler).post(
                FILE_DISTRIBUTION_PATH, body)
            distributions.append(distribution)
            self.addCleanup(client.delete, distribution["pulp_href"])

        self.assertEqual(distributions[0]["publication"],
                         distributions[1]["publication"], distributions)

        unit_urls = []
        unit_path = get_added_content(
            repo)[FILE_CONTENT_NAME][0]["relative_path"]
        for distribution in distributions:
            unit_url = distribution["base_url"]
            unit_urls.append(urljoin(unit_url, unit_path))

        client.response_handler = api.safe_handler
        self.assertEqual(
            hashlib.sha256(client.get(unit_urls[0]).content).hexdigest(),
            hashlib.sha256(client.get(unit_urls[1]).content).hexdigest(),
            unit_urls,
        )
Пример #4
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        * The ``_latest_version_href + content/`` API call is correct.
        * The ``_latest_version_href + added_content/`` API call is correct.
        * The ``_latest_version_href + removed_content/`` API call is correct.
        * The ``content_summary`` attribute is correct.
        """
        body = gen_remote(urljoin(FILE_FIXTURE_URL, 'PULP_MANIFEST'))
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 1, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), FILE_FIXTURE_COUNT, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Пример #5
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 0, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 1, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT - 1})
Пример #6
0
    def test_sync_repo_metadata_change(self):
        """Sync RPM modular content.

        This test targets sync issue when only custom metadata changes:

        * `Pulp #7030 <https://pulp.plan.io/issues/7030>`_
        """
        body = gen_rpm_remote(RPM_CUSTOM_REPO_METADATA_FIXTURE_URL)
        remote = self.remote_api.create(body)

        repo, remote = self.do_test(remote=remote)

        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_CUSTOM_REPO_METADATA_CHANGED_FIXTURE_URL)
        remote_changed = self.remote_api.create(body)

        self.addCleanup(self.remote_api.delete, remote_changed.pulp_href)

        repo, remote = self.do_test(repository=repo, remote=remote_changed)

        # Check if repository was updated with repository metadata
        self.assertEqual(repo.latest_version_href.rstrip("/")[-1], "2")
        self.assertTrue(PULP_TYPE_REPOMETADATA in get_added_content(repo.to_dict()))
Пример #7
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.content['_href']]})
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 1, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Пример #8
0
    def test_content_served(self):
        """Verify that content is served over publication distribution."""
        repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])

        remote = self.client.post(FILE_REMOTE_PATH, gen_file_remote())
        self.addCleanup(self.client.delete, remote["pulp_href"])

        sync(self.cfg, remote, repo)
        repo = self.client.get(repo["pulp_href"])

        publication = create_file_publication(self.cfg, repo)
        self.addCleanup(self.client.delete, publication["pulp_href"])

        distribution = self.client.post(
            FILE_DISTRIBUTION_PATH,
            gen_distribution(publication=publication["pulp_href"]))
        self.addCleanup(self.client.delete, distribution["pulp_href"])

        pulp_manifest = parse_pulp_manifest(
            self.download_pulp_manifest(distribution))

        self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)

        added_content = get_added_content(repo)
        unit_path = added_content[FILE_CONTENT_NAME][0]["relative_path"]
        unit_url = distribution["base_url"]
        unit_url = urljoin(unit_url, unit_path)

        pulp_hash = hashlib.sha256(
            self.client.get(unit_url).content).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))).hexdigest()

        self.assertEqual(fixtures_hash, pulp_hash)
Пример #9
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        * The ``_latest_version_href + content/`` API call is correct.
        * The ``_latest_version_href + added_content/`` API call is correct.
        * The ``_latest_version_href + removed_content/`` API call is correct.
        * The ``content_summary`` attribute is correct.
        """
        body = gen_file_remote()
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 1, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), FILE_FIXTURE_COUNT, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Пример #10
0
    def test_sync_advisory_updated_update_date(self):
        """Test sync advisory with updated update_date."""
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_UPDATED_UPDATEINFO_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # re-sync
        repo, remote = self.do_test(repo, remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        added_advisory_date = [
            advisory["updated_date"]
            for advisory in get_added_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if RPM_ADVISORY_TEST_ID_NEW in advisory["id"]
        ]
        removed_advisory_date = [
            advisory["updated_date"]
            for advisory in get_removed_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if RPM_ADVISORY_TEST_ID_NEW in advisory["id"]
        ]

        self.assertGreater(
            parse_datetime(added_advisory_date[0]), parse_datetime(removed_advisory_date[0])
        )
Пример #11
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 1, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Пример #12
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)))
        self.client.post(repo['_versions_href'],
                         {'remove_content_units': [self.content['_href']]})
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 0, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 1, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT - 1})
Пример #13
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo["pulp_href"])
        modify_repo(self.cfg, self.repo, add_units=[self.content])
        repo = self.client.get(self.repo["pulp_href"])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 4, repo_versions)

        self.assertIsNotNone(repo["latest_version_href"])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs)

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [self.content], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {FILE_CONTENT_NAME: 1})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Пример #14
0
    def test_all(self):
        """Sync two copies of the same packages, make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated errata (packages with the same
           NEVRA as the existing package content, but different pkgId)
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one but has the same
           content summary.
        7. Assert that the packages have changed since the last sync.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Create a remote with the unsigned RPM fixture url.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(get_content_summary(repo),
                             RPM_FIXTURE_CONTENT_SUMMARY)

        # Save a copy of the original packages.
        original_packages = {
            content['errata_id']: content
            for content in get_content(repo) if content['type'] == 'packages'
        }

        # Create a remote with a different test fixture with the same NEVRA but different digests.
        body = gen_rpm_remote(url=RPM_SIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(get_content_summary(repo),
                             RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), 0)

        # Test that the packages have been modified.
        mutated_packages = {
            content['errata_id']: content
            for content in get_content(repo) if content['type'] == 'update'
        }

        self.assertNotEqual(mutated_packages, original_packages)
        self.assertNotEqual(mutated_packages[RPM_PACKAGE_NAME]['pkgId'],
                            original_packages[RPM_PACKAGE_NAME]['pkgId'])
Пример #15
0
    def test_all(self):
        """Sync two copies of the same packages, make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated errata (packages with the same
           NEVRA as the existing package content, but different pkgId)
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one but has the same
           content summary.
        7. Assert that the packages have changed since the last sync.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Create a remote with the unsigned RPM fixture url.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_CONTENT_SUMMARY)

        # Save a copy of the original packages.
        original_packages = {
            content['errata_id']: content for content in get_content(repo)
            if content['type'] == 'packages'
        }

        # Create a remote with a different test fixture with the same NEVRA but different digests.
        body = gen_rpm_remote(url=RPM_SIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_CONTENT_SUMMARY)
        self.assertEqual(len(get_added_content(repo)), 0)

        # Test that the packages have been modified.
        mutated_packages = {
            content['errata_id']: content for content in get_content(repo)
            if content['type'] == 'update'
        }

        self.assertNotEqual(mutated_packages, original_packages)
        self.assertNotEqual(mutated_packages[RPM_PACKAGE_NAME]['pkgId'],
                            original_packages[RPM_PACKAGE_NAME]['pkgId'])
Пример #16
0
    def test_sync(self):
        """Sync repositories with the file plugin.

        In order to sync a repository a remote has to be associated within
        this repository. When a repository is created this version field is set
        as None. After a sync the repository version is updated.

        Do the following:

        1. Create a repository, and a remote.
        2. Assert that repository version is None.
        3. Sync the remote.
        4. Assert that repository version is not None.
        5. Assert that the correct number of units were added and are present
           in the repo.
        6. Sync the remote one more time.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of are present and that no units were
           added.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        body = gen_file_remote()
        remote = self.client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['_href'])

        self.assertIsNotNone(repo['_latest_version_href'])
        self.assertEqual(len(get_content(repo)), FILE_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), FILE_FIXTURE_COUNT)

        # Sync the repository again.
        latest_version_href = repo['_latest_version_href']
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['_href'])

        self.assertNotEqual(latest_version_href, repo['_latest_version_href'])
        self.assertEqual(len(get_content(repo)), FILE_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), 0)
Пример #17
0
    def test_sync(self):
        """Sync repositories with the plugin_template plugin.

        In order to sync a repository a remote has to be associated within
        this repository. When a repository is created this version field is set
        as None. After a sync the repository version is updated.

        Do the following:

        1. Create a repository, and a remote.
        2. Assert that repository version is None.
        3. Sync the remote.
        4. Assert that repository version is not None.
        5. Sync the remote one more time.
        6. Assert that repository version is different from the previous one.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_plugin_template_remote()
        remote = client.post(PLUGIN_TEMPLATE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        self.assertIsNotNone(repo['_latest_version_href'])
        self.assertEqual(len(get_content(repo)), PLUGIN_TEMPLATE_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)),
                         PLUGIN_TEMPLATE_FIXTURE_COUNT)

        # Sync the repository again.
        latest_version_href = repo['_latest_version_href']
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])

        self.assertNotEqual(latest_version_href, repo['_latest_version_href'])
        self.assertEqual(len(get_content(repo)), PLUGIN_TEMPLATE_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), 0)
Пример #18
0
 def test_http_error(self):
     """Test http error is raised."""
     added_content = choice(get_added_content(self.repo)[FILE_CONTENT_NAME])
     with self.assertRaises(HTTPError) as ctx:
         self.client.post(
             self.repo['pulp_href'] + "modify/",
             {'remove_content_units': ['*', added_content['pulp_href']]},
         )
     for key in ('content', 'units', '*'):
         self.assertIn(
             key,
             ctx.exception.response.json()['remove_content_units'][0].lower(),
             ctx.exception.response,
         )
Пример #19
0
 def test_http_error(self):
     """Test http error is raised."""
     added_content = choice(get_added_content(self.repo)[FILE_CONTENT_NAME])
     with self.assertRaises(HTTPError) as ctx:
         self.client.post(
             self.repo["pulp_href"] + "modify/",
             {"remove_content_units": ["*", added_content["pulp_href"]]},
         )
     for key in ("content", "units", "*"):
         self.assertIn(
             key,
             ctx.exception.response.json()["remove_content_units"][0].lower(),
             ctx.exception.response,
         )
Пример #20
0
    def assert_content_served(self, repo, distribution):
        """Asserts content served at distribution is correct."""
        pulp_manifest = parse_pulp_manifest(self.download_pulp_manifest(distribution))

        self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)

        added_content = get_added_content(repo)
        unit_path = added_content[FILE_CONTENT_NAME][0]["relative_path"]
        unit_url = distribution["base_url"]
        unit_url = urljoin(unit_url, unit_path)

        pulp_hash = hashlib.sha256(self.client.get(unit_url).content).hexdigest()
        fixtures_hash = hashlib.sha256(utils.http_get(urljoin(FILE_URL, unit_path))).hexdigest()

        self.assertEqual(fixtures_hash, pulp_hash)
Пример #21
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``versions_href`` API call is correct.
        * The ``latest_version_href`` API call is correct.
        * The ``content_hrefs`` attribute is correct.
        * The ``content_added_hrefs`` attribute is correct.
        * The ``content_removed_hrefs`` attribute is correct.
        * The ``content_summary`` attribute is correct.
        * The ``content_added_summary`` attribute is correct.
        * The ``content_removed_summary`` attribute is correct.
        """
        body = gen_file_remote()
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['pulp_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        content_added = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_added), FILE_FIXTURE_COUNT)

        content_removed = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_removed), 0)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, FILE_FIXTURE_SUMMARY)

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Пример #22
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        * The ``content_hrefs`` attribute is correct.
        * The ``content_added_hrefs`` attribute is correct.
        * The ``content_removed_hrefs`` attribute is correct.
        * The ``content_summary`` attribute is correct.
        * The ``content_added_summary`` attribute is correct.
        * The ``content_removed_summary`` attribute is correct.
        """
        body = gen_file_remote()
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 1, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        content_added = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_added), FILE_FIXTURE_COUNT)

        content_removed = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_removed), 0)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, FILE_FIXTURE_SUMMARY)

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Пример #23
0
    def test_sync_advisory_older_update_date(self):
        """Test sync advisory with older update_date."""
        body = gen_rpm_remote(RPM_UPDATED_UPDATEINFO_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)
        advisory_date = [
            advisory['updated_date']
            for advisory in get_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if advisory['id'] == RPM_ADVISORY_TEST_ID
        ]

        # add remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # re-sync
        repo, remote = self.do_test(repo, remote)

        advisory_date_new = [
            advisory['updated_date']
            for advisory in get_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if advisory['id'] == RPM_ADVISORY_TEST_ID
        ]
        added_advisories = [
            advisory['id']
            for advisory in get_added_content(repo.to_dict())[PULP_TYPE_ADVISORY]
        ]

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # check if advisory is preserved and no advisory with same id was added
        self.assertEqual(
            parse_datetime(advisory_date[0]),
            parse_datetime(advisory_date_new[0])
        )
        self.assertNotIn(
            RPM_ADVISORY_TEST_ID,
            added_advisories
        )
Пример #24
0
    def test_sync_merge_advisories(self):
        """Sync two advisories with same ID, version and different pkglist.

        Test if two advisories are merged.
        """
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_ADVISORY_DIFFERENT_PKGLIST_URL)
        remote = self.remote_api.create(body)

        # re-sync
        repo, remote = self.do_test(repo, remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # check advisories were merged
        added_advisories = get_added_content(repo.to_dict())[PULP_TYPE_ADVISORY]
        added_advisory_pkglist = [
            advisory["pkglist"]
            for advisory in added_advisories
            if advisory["id"] == RPM_ADVISORY_TEST_ID
        ]
        removed_advisories = get_removed_content(repo.to_dict())[PULP_TYPE_ADVISORY]
        removed_advisory_pkglist = [
            advisory["pkglist"]
            for advisory in removed_advisories
            if advisory["id"] == RPM_ADVISORY_TEST_ID
        ]
        added_count = 0
        removed_count = 0
        for collection in added_advisory_pkglist[0]:
            added_count += len(collection["packages"])
        for collection in removed_advisory_pkglist[0]:
            removed_count += len(collection["packages"])
        self.assertEqual(RPM_ADVISORY_TEST_REMOVE_COUNT, removed_count)
        self.assertEqual(RPM_ADVISORY_TEST_ADDED_COUNT, added_count)
Пример #25
0
    def test_sync_advisory_new_version(self):
        """Sync a repository and re-sync with newer version of Advisory.

        Test if advisory with same ID and pkglist, but newer version is updated.

        `Pulp #4142 <https://pulp.plan.io/issues/4142>`_

        1. Sync rpm-unsigned repository
        2. Re-sync rpm-advisory-updateversion
        3. Check if the newer version advisory was synced
        """
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_ADVISORY_UPDATED_VERSION_URL)
        remote = self.remote_api.create(body)

        # re-sync
        repo, remote = self.do_test(repo, remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # check if newer version advisory was added and older removed
        added_advisories = get_added_content(repo.to_dict())[PULP_TYPE_ADVISORY]
        added_advisory = [
            advisory["version"]
            for advisory in added_advisories
            if advisory["id"] == RPM_ADVISORY_TEST_ID
        ]
        removed_advisories = get_removed_content(repo.to_dict())[PULP_TYPE_ADVISORY]
        removed_advisory = [
            advisory["version"]
            for advisory in removed_advisories
            if advisory["id"] == RPM_ADVISORY_TEST_ID
        ]
        self.assertGreater(int(added_advisory[0]), int(removed_advisory[0]))
Пример #26
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)['pulp_file.file']
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT - 1, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(
            content_summary, {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1}
        )

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Пример #27
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT - 1, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(
            content_summary, {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1}
        )

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Пример #28
0
    def test_sync_advisory_no_updated_date(self):
        """Test sync advisory with no update.

        1. Sync repository with advisory which has updated_date
        2. Re-sync with repo with same id and version as previous
           but missing updated_date (issued_date should be used instead).
        """
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_rpm_remote(RPM_ADVISORY_NO_DATES)
        remote = self.remote_api.create(body)

        # re-sync
        repo, remote = self.do_test(repo, remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        added_advisory_date = [
            advisory['updated_date']
            for advisory in get_added_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if RPM_ADVISORY_TEST_ID in advisory['id']
        ]
        removed_advisory_date = [
            advisory['issued_date']
            for advisory in get_removed_content(repo.to_dict())[PULP_TYPE_ADVISORY]
            if RPM_ADVISORY_TEST_ID in advisory['id']
        ]

        self.assertGreater(
            parse_datetime(added_advisory_date[0]),
            parse_datetime(removed_advisory_date[0])
        )
Пример #29
0
    def test_content_served(self):
        """Verify that content is served over publication distribution."""
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        remote = self.client.post(FILE_REMOTE_PATH, gen_file_remote())
        self.addCleanup(self.client.delete, remote['_href'])

        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['_href'])

        publication = create_file_publication(self.cfg, repo)
        self.addCleanup(self.client.delete, publication['_href'])

        distribution = self.client.post(
            FILE_DISTRIBUTION_PATH,
            gen_distribution(publication=publication['_href'])
        )
        self.addCleanup(self.client.delete, distribution['_href'])

        pulp_manifest = parse_pulp_manifest(
            self.download_pulp_manifest(distribution)
        )

        self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)

        added_content = get_added_content(repo)
        unit_path = added_content[FILE_CONTENT_NAME][0]['relative_path']
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        pulp_hash = hashlib.sha256(
            self.client.using_handler(api.safe_handler).get(unit_url).content
        ).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))
        ).hexdigest()

        self.assertEqual(fixtures_hash, pulp_hash)
Пример #30
0
    def test_02_including_prereleases(self):
        """
        Sync a Remote, including prereleases.

        Do the following:

        1. Update the remote to include pre-releases.
        2. Sync the remote again.
        3. Assert that the content counts in the repo match *all* the packages matched by the
           specifier, including prereleases.

        """
        body = {'prereleases': True}
        self.client.patch(self.remote['_href'], body)
        type(self).remote = self.client.get(self.remote['_href'])

        sync(self.cfg, self.remote, self.repo)
        type(self).repo = self.client.get(self.repo['_href'])

        self.assertEqual(len(get_content(self.repo)), PYTHON_WITH_PRERELEASE_COUNT)
        self.assertEqual(len(get_added_content(self.repo)),
                         PYTHON_WITH_PRERELEASE_COUNT - PYTHON_WITHOUT_PRERELEASE_COUNT)
Пример #31
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [self.content], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {FILE_CONTENT_NAME: 1})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Пример #32
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo["pulp_href"])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))

        modify_repo(self.cfg, self.repo, remove_units=[self.content])
        repo = self.client.get(self.repo["pulp_href"])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo["latest_version_href"])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_hrefs), FILE_FIXTURE_COUNT - 1,
                         content_hrefs)

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary,
                             {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1})

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Пример #33
0
    def test_mutated_advisory_metadata(self):
        """Sync two copies of the same Advisory (only description is updated).

        Make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated advisory
           (updaterecords with the ID as the existing updaterecord content, but
           different metadata).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the updaterecords have changed since the last sync.
        """
        # Create a remote with the unsigned RPM fixture url.
        # We need to use the unsigned fixture because the one used down below
        # has unsigned RPMs. Signed and unsigned units have different hashes,
        # so they're seen as different units.
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # check if sync OK
        self.assertDictEqual(get_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)

        original_updaterecords = {
            content["id"]: content
            for content in get_content(repo.to_dict())[RPM_ADVISORY_CONTENT_NAME]
        }

        body = gen_rpm_remote(RPM_UPDATED_UPDATEINFO_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync the repository again
        repo, remote = self.do_test(repo, remote)

        # add the second remote to clean up
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        self.assertDictEqual(get_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)
        self.assertEqual(len(get_added_content(repo.to_dict())[RPM_ADVISORY_CONTENT_NAME]), 4)
        self.assertEqual(len(get_removed_content(repo.to_dict())[RPM_ADVISORY_CONTENT_NAME]), 4)

        # Test that the updateinfo have been modified.
        mutated_updaterecords = {
            content["id"]: content
            for content in get_content(repo.to_dict())[RPM_ADVISORY_CONTENT_NAME]
        }

        self.assertNotEqual(mutated_updaterecords, original_updaterecords)
        self.assertEqual(
            mutated_updaterecords[RPM_ADVISORY_TEST_ID_NEW]["description"],
            "Updated Gorilla_Erratum and the updated date contains timezone",
            mutated_updaterecords[RPM_ADVISORY_TEST_ID_NEW],
        )
Пример #34
0
    def test_all(self):
        """Test content promotion for a distribution.

        This test targets the following issue:

        * `Pulp #4186 <https://pulp.plan.io/issues/4186>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher, and publication.
        3. Create 2 distributions - using the same publication. Those
           distributions will have different ``base_path``.
        4. Assert that distributions have the same publication.
        5. Select a content unit. Download that content unit from Pulp using
           the two different distributions.
           Assert that content unit has the same checksum when fetched from
           different distributions.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        remote = client.post(
            FILE_REMOTE_PATH,
            gen_remote(FILE_FIXTURE_MANIFEST_URL)
        )
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)
        repo = client.get(repo['_href'])

        publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        publication = publish(cfg, publisher, repo)
        self.addCleanup(client.delete, publication['_href'])

        distributions = []
        for _ in range(2):
            body = gen_distribution()
            body['publication'] = publication['_href']
            distribution = client.post(DISTRIBUTION_PATH, body)
            distributions.append(distribution)
            self.addCleanup(client.delete, distribution['_href'])

        self.assertEqual(
            distributions[0]['publication'],
            distributions[1]['publication'],
            distributions
        )

        unit_urls = []
        unit_path = get_added_content(repo)[FILE_CONTENT_NAME][0]['relative_path']
        for distribution in distributions:
            unit_url = cfg.get_hosts('api')[0].roles['api']['scheme']
            unit_url += '://' + distribution['base_url'] + '/'
            unit_urls.append(urljoin(unit_url, unit_path))

        client.response_handler = api.safe_handler
        self.assertEqual(
            hashlib.sha256(client.get(unit_urls[0]).content).hexdigest(),
            hashlib.sha256(client.get(unit_urls[1]).content).hexdigest(),
            unit_urls,
        )
Пример #35
0
    def test_all(self):
        """Sync two copies of the same UpdateRecords.

        Make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated advisory
           (updaterecords with the ID as the existing updaterecord content, but
           different metadata).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the updaterecords have changed since the last sync.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(RPM_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['pulp_href'])

        # Create a remote with the unsigned RPM fixture url.
        # We need to use the unsigned fixture because the one used down below
        # has unsigned RPMs. Signed and unsigned units have different hashes,
        # so they're seen as different units.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['pulp_href'])

        # Sync the repository.
        self.assertEqual(repo["latest_version_href"],
                         f"{repo['pulp_href']}versions/0/")
        sync(self.cfg, remote, repo)
        repo = client.get(repo['pulp_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)

        # Save a copy of the original updateinfo
        original_updaterecords = {
            content['id']: content
            for content in get_content(repo)[RPM_ADVISORY_CONTENT_NAME]
        }

        # Create a remote with a different test fixture, one containing mutated
        # updateinfo.
        body = gen_rpm_remote(url=RPM_UPDATED_UPDATEINFO_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['pulp_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = client.get(repo['pulp_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)
        self.assertEqual(
            len(get_added_content(repo)[RPM_ADVISORY_CONTENT_NAME]), 4)
        self.assertEqual(
            len(get_removed_content(repo)[RPM_ADVISORY_CONTENT_NAME]), 4)

        # Test that the updateinfo have been modified.
        mutated_updaterecords = {
            content['id']: content
            for content in get_content(repo)[RPM_ADVISORY_CONTENT_NAME]
        }

        self.assertNotEqual(mutated_updaterecords, original_updaterecords)
        self.assertEqual(
            mutated_updaterecords[RPM_UPDATERECORD_ID]['description'],
            'Updated Gorilla_Erratum and the updated date contains timezone',
            mutated_updaterecords[RPM_UPDATERECORD_ID],
        )
Пример #36
0
    def test_all(self):
        """Sync two copies of the same packages.

        Make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated advisory
           (packages with the same NEVRA as the existing package content, but
           different pkgId).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the packages have changed since the last sync.
        """
        repo = self.client.post(RPM_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['pulp_href'])

        # Create a remote with the unsigned RPM fixture url.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['pulp_href'])

        # Sync the repository.
        self.assertEqual(repo["latest_version_href"],
                         f"{repo['pulp_href']}versions/0/")
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['pulp_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)

        # Save a copy of the original packages.
        original_packages = {
            (
                content['name'],
                content['epoch'],
                content['version'],
                content['release'],
                content['arch'],
            ): content
            for content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        }

        # Create a remote with a different test fixture with the same NEVRA but
        # different digests.
        body = gen_rpm_remote(url=RPM_SIGNED_FIXTURE_URL)
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['pulp_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['pulp_href'])
        self.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)

        # In case of "duplicates" the most recent one is chosen, so the old
        # package is removed from and the new one is added to a repo version.
        self.assertEqual(
            len(get_added_content(repo)[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGE_COUNT,
            get_added_content(repo)[RPM_PACKAGE_CONTENT_NAME],
        )
        self.assertEqual(
            len(get_removed_content(repo)[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGE_COUNT,
            get_removed_content(repo)[RPM_PACKAGE_CONTENT_NAME],
        )

        # Test that the packages have been modified.
        mutated_packages = {
            (
                content['name'],
                content['epoch'],
                content['version'],
                content['release'],
                content['arch'],
            ): content
            for content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        }

        for nevra in original_packages:
            with self.subTest(pkg=nevra):
                self.assertNotEqual(
                    original_packages[nevra]['pkgId'],
                    mutated_packages[nevra]['pkgId'],
                    original_packages[nevra]['pkgId'],
                )
Пример #37
0
    def test_repo_auto_distribution(self):
        """Test auto distribution of a repository.

        This test targets the following issue:

        * `Pulp Smash #947 <https://github.com/PulpQE/pulp-smash/issues/947>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher.
        3. Create a distribution and set the repository and publishera to the
           previous created ones.
        4. Create a publication using the latest repository version.
        5. Assert that the previous distribution has a  ``publication`` set as
           the one created in step 4.
        6. Create a new repository version by adding content to the repository.
        7. Create another publication using the just created repository
           version.
        8. Assert that distribution now has the ``publication`` set to the
           publication created in the step 7.
        9. Verify that content added in the step 7 is now available to download
           from distribution, and verify that the content unit has the same
           checksum when fetched directly from Pulp-Fixtures.
        """
        self.assertGreaterEqual(len(self.contents), 2, self.contents)

        # Create a repository.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.contents[0]['_href']]})
        repo = self.client.get(repo['_href'])

        # Create publisher.
        publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Create a distribution
        body = gen_distribution()
        body['repository'] = repo['_href']
        body['publisher'] = publisher['_href']
        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 5.
        self.assertEqual(distribution['publication'], publication['_href'])

        # Create a new repository version.
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.contents[1]['_href']]})
        repo = self.client.get(repo['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 8.
        self.assertEqual(distribution['publication'], publication['_href'])
        unit_path = get_added_content(repo,
                                      last_version_href)[0]['relative_path']
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        pulp_hash = hashlib.sha256(
            self.client.get(unit_url).content).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))).hexdigest()

        # Verify checksum. Step 9.
        self.assertEqual(fixtures_hash, pulp_hash)
Пример #38
0
    def test_all(self):
        """Sync two copies of the same packages.

        Make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated errata
           (packages with the same NEVRA as the existing package content, but
           different pkgId).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the packages have changed since the last sync.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        # Create a remote with the unsigned RPM fixture url.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['_href'])
        self.assertDictEqual(
            get_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )

        # Save a copy of the original packages.
        original_packages = {
            (content['name'],
             content['epoch'],
             content['version'],
             content['release'],
             content['arch']): content
            for content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        }

        # Create a remote with a different test fixture with the same NEVRA but
        # different digests.
        body = gen_rpm_remote(url=RPM_SIGNED_FIXTURE_URL)
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo['_href'])
        self.assertDictEqual(
            get_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )

        # In case of "duplicates" the most recent one is chosen, so the old
        # package is removed from and the new one is added to a repo version.
        self.assertEqual(
            len(get_added_content(repo)[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGES_COUNT,
            get_added_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        )
        self.assertEqual(
            len(get_removed_content(repo)[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGES_COUNT,
            get_removed_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        )

        # Test that the packages have been modified.
        mutated_packages = {
            (content['name'],
             content['epoch'],
             content['version'],
             content['release'],
             content['arch']): content
            for content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        }

        for nevra in original_packages:
            with self.subTest(pkg=nevra):
                self.assertNotEqual(
                    original_packages[nevra]['pkgId'],
                    mutated_packages[nevra]['pkgId'],
                    original_packages[nevra]['pkgId']
                )
Пример #39
0
    def test_all(self):
        """Sync two copies of the same UpdateRecords.

        Make sure we end up with only one copy.

        Do the following:

        1. Create a repository and a remote.
        2. Sync the remote.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated errata
           (updaterecords with the ID as the existing updaterecord content, but
           different metadata).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the updaterecords have changed since the last sync.
        """
        client = api.Client(self.cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Create a remote with the unsigned RPM fixture url.
        # We need to use the unsigned fixture because the one used down below
        # has unsigned RPMs. Signed and unsigned units have different hashes,
        # so they're seen as different units.
        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository.
        self.assertIsNone(repo['_latest_version_href'])
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(
            get_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )

        # Save a copy of the original updateinfo
        original_updaterecords = {
            content['id']: content
            for content in get_content(repo)[RPM_UPDATE_CONTENT_NAME]
        }

        # Create a remote with a different test fixture, one containing mutated
        # updateinfo.
        body = gen_rpm_remote(url=RPM_UPDATED_UPDATEINFO_FIXTURE_URL)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        # Sync the repository again.
        sync(self.cfg, remote, repo)
        repo = client.get(repo['_href'])
        self.assertDictEqual(
            get_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )
        self.assertEqual(
            len(get_added_content(repo)[RPM_UPDATE_CONTENT_NAME]),
            4
        )
        self.assertEqual(
            len(get_removed_content(repo)[RPM_UPDATE_CONTENT_NAME]),
            4
        )

        # Test that the updateinfo have been modified.
        mutated_updaterecords = {
            content['id']: content
            for content in get_content(repo)[RPM_UPDATE_CONTENT_NAME]
        }

        self.assertNotEqual(mutated_updaterecords, original_updaterecords)
        self.assertEqual(
            mutated_updaterecords[RPM_UPDATERECORD_ID]['description'],
            'Updated Gorilla_Erratum and the updated date contains timezone',
            mutated_updaterecords[RPM_UPDATERECORD_ID]
        )
Пример #40
0
    def test_repo_auto_distribution(self):
        """Test auto distribution of a repository.

        This test targets the following issue:

        * `Pulp Smash #947 <https://github.com/PulpQE/pulp-smash/issues/947>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher.
        3. Create a distribution and set the repository and publishera to the
           previous created ones.
        4. Create a publication using the latest repository version.
        5. Assert that the previous distribution has a  ``publication`` set as
           the one created in step 4.
        6. Create a new repository version by adding content to the repository.
        7. Create another publication using the just created repository
           version.
        8. Assert that distribution now has the ``publication`` set to the
           publication created in the step 7.
        9. Verify that content added in the step 7 is now available to download
           from distribution, and verify that the content unit has the same
           checksum when fetched directly from Pulp-Fixtures.
        """
        self.assertGreaterEqual(len(self.contents), 2, self.contents)

        # Create a repository.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.contents[0]['_href']]}
        )
        repo = self.client.get(repo['_href'])

        # Create publisher.
        publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Create a distribution
        body = gen_distribution()
        body['repository'] = repo['_href']
        body['publisher'] = publisher['_href']
        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 5.
        self.assertEqual(distribution['publication'], publication['_href'])

        # Create a new repository version.
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.contents[1]['_href']]}
        )
        repo = self.client.get(repo['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 8.
        self.assertEqual(distribution['publication'], publication['_href'])
        unit_path = get_added_content(repo, last_version_href)[0]['relative_path']
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        pulp_hash = hashlib.sha256(
            self.client.get(unit_url).content
        ).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))
        ).hexdigest()

        # Verify checksum. Step 9.
        self.assertEqual(fixtures_hash, pulp_hash)
Пример #41
0
    def test_mutated_packages(self):
        """Sync two copies of the same packages.

        Make sure we end up with only one copy.

        Do the following:

        1. Sync.
        3. Assert that the content summary matches what is expected.
        4. Create a new remote w/ using fixture containing updated advisory
           (packages with the same NEVRA as the existing package content, but
           different pkgId).
        5. Sync the remote again.
        6. Assert that repository version is different from the previous one
           but has the same content summary.
        7. Assert that the packages have changed since the last sync.
        """
        body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync
        repo, remote = self.do_test(remote=remote)

        # add resources to clean up
        self.addCleanup(self.repo_api.delete, repo.pulp_href)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # check if sync OK
        self.assertDictEqual(get_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)

        # Save a copy of the original packages.
        original_packages = {
            (
                content["name"],
                content["epoch"],
                content["version"],
                content["release"],
                content["arch"],
            ): content
            for content in get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]
        }

        # Create a remote with a different test fixture with the same NEVRA but
        # different digests.
        body = gen_rpm_remote(RPM_SIGNED_FIXTURE_URL)
        remote = self.remote_api.create(body)

        # sync again
        repo, remote = self.do_test(repo, remote)

        # In case of "duplicates" the most recent one is chosen, so the old
        # package is removed from and the new one is added to a repo version.
        self.assertEqual(
            len(get_added_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGE_COUNT,
            get_added_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME],
        )
        self.assertEqual(
            len(get_removed_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]),
            RPM_PACKAGE_COUNT,
            get_removed_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME],
        )

        # Test that the packages have been modified.
        mutated_packages = {
            (
                content["name"],
                content["epoch"],
                content["version"],
                content["release"],
                content["arch"],
            ): content
            for content in get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]
        }

        for nevra in original_packages:
            with self.subTest(pkg=nevra):
                self.assertNotEqual(
                    original_packages[nevra]["pkgId"],
                    mutated_packages[nevra]["pkgId"],
                    original_packages[nevra]["pkgId"],
                )
    def test_all(self):
        """Test content promotion for a distribution.

        This test targets the following issue:

        * `Pulp #4186 <https://pulp.plan.io/issues/4186>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher, and publication.
        3. Create 2 distributions - using the same publication. Those
           distributions will have different ``base_path``.
        4. Assert that distributions have the same publication.
        5. Select a content unit. Download that content unit from Pulp using
           the two different distributions.
           Assert that content unit has the same checksum when fetched from
           different distributions.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        remote = client.post(FILE_REMOTE_PATH,
                             gen_remote(FILE_FIXTURE_MANIFEST_URL))
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)
        repo = client.get(repo['_href'])

        publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        publication = publish(cfg, publisher, repo)
        self.addCleanup(client.delete, publication['_href'])

        distributions = []
        for _ in range(2):
            body = gen_distribution()
            body['publication'] = publication['_href']
            distribution = client.post(DISTRIBUTION_PATH, body)
            distributions.append(distribution)
            self.addCleanup(client.delete, distribution['_href'])

        self.assertEqual(distributions[0]['publication'],
                         distributions[1]['publication'], distributions)

        unit_urls = []
        unit_path = get_added_content(repo)[0]['relative_path']
        for distribution in distributions:
            unit_url = cfg.get_hosts('api')[0].roles['api']['scheme']
            unit_url += '://' + distribution['base_url'] + '/'
            unit_urls.append(urljoin(unit_url, unit_path))

        client.response_handler = api.safe_handler
        self.assertEqual(
            hashlib.sha256(client.get(unit_urls[0]).content).hexdigest(),
            hashlib.sha256(client.get(unit_urls[1]).content).hexdigest(),
            unit_urls,
        )