예제 #1
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})
예제 #2
0
    def test_all(self):
        """Test whether content unit used by a repo version can be deleted.

        Do the following:

        1. Sync content to a repository.
        2. Attempt to delete a content unit present in a repository version.
           Assert that a HTTP exception was raised.
        3. Assert that number of content units present on the repository
           does not change after the attempt to delete one content unit.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

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

        sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        content = get_content(repo)
        with self.assertRaises(HTTPError):
            client.delete(choice(content)['_href'])
        self.assertEqual(len(content), len(get_content(repo)))
예제 #3
0
    def test_different_repository(self):
        """Test ``base_version`` for different repositories.

        Do the following:

        1. Create a new repository A and sync it.
        2. Create a new repository B and a new version for this repository
           specify repository A version 1 as the ``base_version``.
        3. Check that repository A version 1 and repository B version 1 have
           the same content.
        """
        # create repo A
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # get repo A version 1 to be used as base_version
        base_version = get_versions(repo)[0]['_href']

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

        # create a version for repo B using repo A version 1 as base_version
        self.client.post(
            repo['_versions_href'],
            {'base_version': base_version}
        )
        repo = self.client.get(repo['_href'])

        # assert that base_version of repo B points to version 1 of repo A
        self.assertEqual(get_versions(repo)[0]['base_version'], base_version)

        # assert that content on version 1 of repo A is equal to content on
        # version 1 repo B
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )

        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
예제 #4
0
 def test_delete_first_version(self):
     """Delete the first repository version."""
     delete_version(self.repo, self.repo_version_hrefs[0])
     with self.assertRaises(HTTPError):
         get_content(self.repo, self.repo_version_hrefs[0])
     for repo_version_href in self.repo_version_hrefs[1:]:
         artifact_paths = get_artifact_paths(self.repo, repo_version_href)
         self.assertIn(self.content[0]['artifact'], artifact_paths)
예제 #5
0
 def test_delete_middle_version(self):
     """Delete a middle version."""
     index = randint(1, len(self.repo_version_hrefs) - 2)
     delete_version(self.repo, self.repo_version_hrefs[index])
     with self.assertRaises(HTTPError):
         get_content(self.repo, self.repo_version_hrefs[index])
     for repo_version_href in self.repo_version_hrefs[index + 1:]:
         artifact_paths = get_artifact_paths(self.repo, repo_version_href)
         self.assertIn(self.content[index]['artifact'], artifact_paths)
예제 #6
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'])
예제 #7
0
파일: utils.py 프로젝트: pulp/pulp_deb
def get_deb_content_unit_paths(repo):
    """Return the relative path of content units present in a deb repository.

    :param repo: A dict of information about the repository.
    :returns: A dict of list with the paths of units present in a given repository
        for different content types. Paths are given as pairs with the remote and the
        local version.
    """
    def _rel_path(package, component=''):
        sourcename = package['source'] or package['package_name']
        if sourcename.startswith('lib'):
            prefix = sourcename[0:4]
        else:
            prefix = sourcename[0]
        return os.path.join(
            'pool',
            component,
            prefix,
            sourcename,
            '{}_{}_{}.deb'.format(package['package_name'],
                                  package['version'],
                                  package['architecture'])
        )
        return os.path.join(
            'pool',

        )

    return {
        DEB_PACKAGE_NAME: [
            (content_unit['relative_path'], _rel_path(content_unit))
            for content_unit in get_content(repo)[DEB_PACKAGE_NAME]
        ],
    }
예제 #8
0
    def test_all(self):
        """Verify publisher and remote can be used with different repos.

        This test explores the design choice stated in `Pulp #3341`_ that
        remove the FK from publishers and remotes to repository.
        Allowing remotes and publishers to be used with different
        repositories.

        .. _Pulp #3341: https://pulp.plan.io/issues/3341

        Do the following:

        1. Create a remote, and a publisher.
        2. Create 2 repositories.
        3. Sync both repositories using the same remote.
        4. Assert that the two repositories have the same contents.
        5. Publish both repositories using the same publisher.
        6. Assert that each generated publication has the same publisher, but
           are associated with different repositories.
        """
        cfg = config.get_config()

        # Create a remote and publisher.
        client = api.Client(cfg, api.json_handler)
        body = gen_file_remote()
        remote = client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

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

        # Create and sync repos.
        repos = []
        for _ in range(2):
            repo = client.post(REPO_PATH, gen_repo())
            self.addCleanup(client.delete, repo['_href'])
            sync(cfg, remote, repo)
            repos.append(client.get(repo['_href']))

        # Compare contents of repositories.
        contents = []
        for repo in repos:
            contents.append(get_content(repo)[FILE_CONTENT_NAME])
        self.assertEqual(
            {content['_href'] for content in contents[0]},
            {content['_href'] for content in contents[1]},
        )

        # Publish repositories.
        publications = []
        for repo in repos:
            publications.append(publish(cfg, publisher, repo))
        self.assertEqual(
            publications[0]['publisher'],
            publications[1]['publisher']
        )
        self.assertNotEqual(
            publications[0]['repository_version'],
            publications[1]['repository_version']
        )
예제 #9
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})
예제 #10
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})
예제 #11
0
def get_rpm_content_unit_paths(repo):
    """Return the relative path of content units present in a rpm repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    # The "relative_path" is actually a file path and name
    return [content_unit['relative_path'] for content_unit in get_content(repo)]
예제 #12
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, {})
예제 #13
0
 def test_filter_valid_content(self):
     """Filter repository versions by valid content."""
     content = choice(self.contents)
     repo_versions = get_versions(self.repo, {'content': content['_href']})
     for repo_version in repo_versions:
         self.assertIn(
             self.client.get(content['_href']),
             get_content(self.repo, repo_version['_href'])
         )
예제 #14
0
파일: test_sync.py 프로젝트: pulp/pulp_rpm
    def test_all(self):
        """Sync two fixture content with same NEVRA and different checksum.

        Make sure we end up with the most recently synced content.

        Do the following:

        1. Create a repository
        2. Create two remotes with same content but different checksums.
            Sync the remotes one after the other.
               a. Sync remote with packages with SHA256: ``RPM_UNSIGNED_FIXTURE_URL``.
               b. Sync remote with packages with SHA512: ``RPM_SHA512_FIXTURE_URL``.
        3. Make sure the latest content is only kept.

        This test targets the following issues:

        * `Pulp #4297 <https://pulp.plan.io/issues/4297>`_
        * `Pulp #3954 <https://pulp.plan.io/issues/3954>`_
        """
        # Step 1
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        # Step 2.

        for body in [
            gen_rpm_remote(),
            gen_rpm_remote(url=RPM_SHA512_FIXTURE_URL)
        ]:
            remote = self.client.post(RPM_REMOTE_PATH, body)
            self.addCleanup(self.client.delete, remote['_href'])
            # Sync the repository.
            sync(self.cfg, remote, repo)

        # Step 3
        repo = self.client.get(repo['_href'])
        added_content = get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        removed_content = get_removed_content(repo)[RPM_PACKAGE_CONTENT_NAME]

        # 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(added_content),
            RPM_PACKAGES_COUNT,
            added_content
        )
        self.assertEqual(
            len(removed_content),
            RPM_PACKAGES_COUNT,
            removed_content
        )

        # Verifying whether the packages with first checksum is removed and second
        # is added.
        self.assertEqual(added_content[0]['checksum_type'], 'sha512')
        self.assertEqual(removed_content[0]['checksum_type'], 'sha256')
예제 #15
0
    def test_base_version_other_parameters(self):
        """Test ``base_version`` can be used together with other parameters.

        ``add_content_units`` and ``remove_content_units``.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_1_content = [
            self.remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # create repo version 2 from version 1
        base_version = get_versions(repo)[0]['_href']
        added_content = self.remove_created_key(self.content.pop())
        removed_content = choice(version_1_content)
        self.client.post(
            repo['_versions_href'],
            {
                'base_version': base_version,
                'add_content_units': [added_content['_href']],
                'remove_content_units': [removed_content['_href']]
            }
        )
        repo = self.client.get(repo['_href'])
        version_2_content = [
            self.remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]

        # assert that base_version of the version 2 points to version 1
        self.assertEqual(get_versions(repo)[1]['base_version'], base_version)

        # assert that the removed content is not present on repo version 2
        self.assertNotIn(removed_content, version_2_content)

        # assert that the added content is present on repo version 2
        self.assertIn(added_content, version_2_content)

        # assert that the same amount of units are present in both versions
        self.assertEqual(len(version_1_content), len(version_2_content))
예제 #16
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})
예제 #17
0
파일: utils.py 프로젝트: pulp/pulp_rpm
def get_rpm_package_paths(repo):
    """Return the relative path of content units present in a RPM repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    return [
        content_unit['location_href']
        for content_unit in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        if 'location_href' in content_unit
    ]
예제 #18
0
def get_container_image_paths(repo, version_href=None):
    """Return the relative path of content units present in a container repository.

    :param repo: A dict of information about the repository.
    :param version_href: The repository version to read.
    :returns: A list with the paths of units present in a given repository.
    """
    return [
        content_unit["_artifact"] for content_unit in get_content(
            repo, version_href)[CONTAINER_CONTENT_NAME]
    ]
예제 #19
0
def get_ansible_content_paths(repo):
    """Return the relative path of content units present in an ansible repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    # FIXME
    return [
        content_unit["relative_path"]
        for content_unit in get_content(repo)[ANSIBLE_ROLE_NAME]
    ]
예제 #20
0
    def test_create_only_using_repoversion(self):
        """Create a publication only using repository version."""
        repo = self.create_sync_repo()
        for file_content in get_content(repo)[FILE_CONTENT_NAME]:
            modify_repo(self.cfg, repo, remove_units=[file_content])
        version_href = self.client.get(repo['versions_href'])[1]['pulp_href']
        publication = create_file_publication(self.cfg, repo, version_href)
        self.addCleanup(self.client.delete, publication['pulp_href'])

        self.assertEqual(publication['repository_version'], version_href,
                         publication)
예제 #21
0
 def test_filter_valid_content(self):
     """Filter repository versions by valid content."""
     content = choice(self.contents)
     repo_versions = get_versions(self.repo,
                                  {"content": content["pulp_href"]})
     for repo_version in repo_versions:
         self.assertIn(
             self.client.get(content["pulp_href"]),
             get_content(self.repo,
                         repo_version["pulp_href"])[FILE_CONTENT_NAME],
         )
예제 #22
0
    def test_all(self):
        """Sync two repositories and check view filter."""
        # Test content doesn't exists.
        non_existant_content_href = (
            "/pulp/api/v3/content/file/files/c4ed74cf-a806-490d-a25f-94c3c3dd2dd7/"
        )

        with self.assertRaises(ApiException) as ctx:
            self.repo_ver_api.list(content=non_existant_content_href)

        self.assertEqual(ctx.exception.status, 400)

        # No repository version exists.
        self.assertEqual(self.repo_ver_api.list().count, 0)

        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        repo_second = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo_second.pulp_href)

        remote = self.remote_api.create(gen_file_remote())
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        body = gen_file_remote(url=FILE2_FIXTURE_MANIFEST_URL)
        remote_second = self.remote_api.create(body)
        self.addCleanup(self.remote_api.delete, remote_second.pulp_href)

        repo_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        repo_sync_data_second = RepositorySyncURL(
            remote=remote_second.pulp_href)

        sync_response = self.repo_api.sync(repo.pulp_href, repo_sync_data)
        monitor_task(sync_response.task)

        sync_response_second = self.repo_api.sync(repo_second.pulp_href,
                                                  repo_sync_data_second)
        monitor_task(sync_response_second.task)

        # Update repository data and get one content unit from first repository.
        repo = self.repo_api.read(repo.pulp_href)
        content_href = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][0]["pulp_href"]

        rv_total = len(self.repo_ver_api.list().to_dict()["results"])
        rv_search = self.repo_ver_api.list(
            content=content_href).to_dict()["results"]

        # Test only one repostiory version has selected content.
        self.assertEqual(len(rv_search), 1)
        # Test if repositories version with content matches.
        self.assertEqual(rv_search[0]["pulp_href"], repo.latest_version_href)
        # Test total number of repository version. Two for each repository.
        self.assertEqual(rv_total, 4)
예제 #23
0
    def test_delete_last_version(self):
        """Delete the last repository version.

        Create a new repository version from the second-to-last repository
        version. Verify that the content unit from the old last repository
        version is not in the new last repository version.
        """
        # Delete the last repo version.
        delete_version(self.repo, self.repo_version_hrefs[-1])
        with self.assertRaises(HTTPError):
            get_content(self.repo, self.repo_version_hrefs[-1])

        # Make new repo version from new last repo version.
        self.client.post(self.repo['_versions_href'],
                         {'add_content_units': [self.content[-1]['_href']]})
        self.repo = self.client.get(self.repo['_href'])
        artifact_paths = get_artifact_paths(self.repo)

        self.assertNotIn(self.content[-2]['artifact'], artifact_paths)
        self.assertIn(self.content[-1]['artifact'], artifact_paths)
예제 #24
0
파일: utils.py 프로젝트: ianballou/pulp_rpm
def get_rpm_package_paths(repo):
    """Return the relative path of content units present in a RPM repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    return [
        content_unit['location_href']
        for content_unit in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]
        if 'location_href' in content_unit
    ]
예제 #25
0
    def test_sync_collections_from_pulp(self):
        """Test sync collections from pulp server."""
        cfg = config.get_config()
        client = api.Client(cfg)
        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo["pulp_href"])

        remote = client.post(
            ANSIBLE_COLLECTION_REMOTE_PATH,
            gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL))
        self.addCleanup(client.delete, remote["pulp_href"])

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

        distribution = client.post(
            ANSIBLE_DISTRIBUTION_PATH,
            gen_distribution(repository=repo["pulp_href"]))
        self.addCleanup(client.delete, distribution["pulp_href"])

        second_repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, second_repo["pulp_href"])

        url = reduce(
            urljoin,
            (
                cfg.get_base_url(),
                "pulp_ansible/galaxy/",
                distribution["base_path"] + "/",
                "api/v2/collections",
            ),
        )

        pulp_remote = client.post(ANSIBLE_COLLECTION_REMOTE_PATH,
                                  gen_ansible_remote(url=url))
        self.addCleanup(client.delete, pulp_remote["pulp_href"])

        sync(cfg, pulp_remote, second_repo)
        second_repo = client.get(second_repo["pulp_href"])

        self.assertEqual(get_content(repo), get_content(second_repo))
예제 #26
0
    def test_clean_specific_orphans(self):
        """Test whether the `content_hrefs` param removes specific orphans but not others"""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/")
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        # Create two orphaned content units.
        content_a = get_content(repo.to_dict())[FILE_CONTENT_NAME][0]["pulp_href"]
        content_b = get_content(repo.to_dict())[FILE_CONTENT_NAME][1]["pulp_href"]
        content_to_remove = dict(remove_content_units=[content_a, content_b])
        repo_api.modify(repo.pulp_href, content_to_remove)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)

        cleanup_dict = {"content_hrefs": [content_a], "orphan_protection_time": 0}
        orphans_response = self.orphans_cleanup_api.cleanup(cleanup_dict)
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)
예제 #27
0
    def test_same_repository(self):
        """Test ``base_version`` for the same repository.

        Do the following:

        1. Create a repository.
        2. Sync the repository (this creates repository version 1).
        3. Add a new content unit a new repository version (this create
           repository version 2).
        4. Create a new repository version using version 1 as ``base_version``
           (this creates version 3).
        5. Check that version 1 and version 3 have the same content.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            [self.remove_created_key(item) for item in get_content(repo)])
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        content = self.content.pop()

        # create repo version 2
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [content['_href']]})
        repo = self.client.get(repo['_href'])

        # create repo version 3 from version 1
        base_version = get_versions(repo)[0]['_href']
        self.client.post(repo['_versions_href'],
                         {'base_version': base_version})
        repo = self.client.get(repo['_href'])

        # assert that base_version of the version 3 points to version 1
        self.assertEqual(get_versions(repo)[2]['base_version'], base_version)

        # assert that content on version 1 is equal to content on version 3
        version_content.append(
            [self.remove_created_key(item) for item in get_content(repo)])
        self.assertEqual(version_content[0], version_content[1],
                         version_content)
예제 #28
0
def get_plugin_template_content_unit_paths(repo):
    """Return the relative path of content units present in a plugin_template repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    # FIXME: The "relative_path" is actually a file path and name
    # It's just an example -- this needs to be replaced with an implementation that works
    # for repositories of this content type.
    return [
        content_unit['relative_path'] for content_unit in get_content(repo)
    ]
예제 #29
0
    def test_delete_last_version(self):
        """Delete the last repository version.

        Create a new repository version from the second-to-last repository
        version. Verify that the content unit from the old last repository
        version is not in the new last repository version.
        """
        # Delete the last repo version.
        delete_version(self.repo, self.repo_version_hrefs[-1])
        with self.assertRaises(HTTPError):
            get_content(self.repo, self.repo_version_hrefs[-1])

        # Make new repo version from new last repo version.
        self.client.post(
            self.repo['_versions_href'],
            {'add_content_units': [self.content[-1]['_href']]}
        )
        self.repo = self.client.get(self.repo['_href'])
        artifact_paths = get_artifact_paths(self.repo)
        self.assertNotIn(self.content[-2]['artifact'], artifact_paths)
        self.assertIn(self.content[-1]['artifact'], artifact_paths)
예제 #30
0
def get_python_content_paths(repo):
    """
    Return the relative path of content units present in a file repository.

    Args:
        repo (dict): A dict of information about the repository.

    Returns:
        list: The paths of units present in a given repository.

    """
    return [content_unit['filename'] for content_unit in get_content(repo)]
예제 #31
0
파일: utils.py 프로젝트: pulp/pulp_docker
def get_docker_image_paths(repo, version_href=None):
    """Return the relative path of content units present in a file repository.

    :param repo: A dict of information about the repository.
    :param version_href: The repository version to read.
    :returns: A list with the paths of units present in a given repository.
    """
    return [
        content_unit['_artifact']
        for content_unit
        in get_content(repo, version_href)[DOCKER_CONTENT_NAME]
    ]
예제 #32
0
    def test_01_create(self):
        """Create a publication distribution.

        Do the following:

        1. Create a repository and 3 repository versions with at least 1 file
           content in it. Create a publication using the second repository
           version.
        2. Create a distribution with 'publication' field set to
           the publication from step (1).
        3. Assert the distribution got created correctly with the correct
           base_path, name, and publication. Assert that content guard is
           unset.
        4. Assert that publication has a 'distributions' reference to the
           distribution (it's backref).

        """
        self.repo.update(self.client.post(FILE_REPO_PATH, gen_repo()))
        self.remote.update(
            self.client.post(FILE_REMOTE_PATH, gen_file_remote()))
        # create 3 repository versions
        sync(self.cfg, self.remote, self.repo)
        self.repo = self.client.get(self.repo["pulp_href"])
        for file_content in get_content(self.repo)[FILE_CONTENT_NAME]:
            modify_repo(self.cfg, self.repo, remove_units=[file_content])

        self.repo = self.client.get(self.repo["pulp_href"])

        versions = get_versions(self.repo)

        self.publication.update(
            create_file_publication(self.cfg, self.repo,
                                    versions[1]["pulp_href"]))

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

        self.publication = self.client.get(self.publication["pulp_href"])

        # content_guard is the only parameter unset.
        for key, val in self.distribution.items():
            if key == "content_guard":
                self.assertIsNone(val, self.distribution)
            else:
                self.assertIsNotNone(val, self.distribution)

        self.assertEqual(self.distribution["publication"],
                         self.publication["pulp_href"], self.distribution)

        self.assertEqual(self.publication["distributions"][0],
                         self.distribution["pulp_href"], self.publication)
예제 #33
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest
           ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        body = gen_rpm_remote()
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        sync(self.cfg, remote, repo)

        publisher = self.client.post(RPM_PUBLISHER_PATH, gen_rpm_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Step 1
        repo = self.client.get(repo['_href'])
        for rpm_content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]:
            self.client.post(repo['_versions_href'],
                             {'add_content_units': [rpm_content['_href']]})
        version_hrefs = tuple(ver['_href'] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(self.cfg, publisher, repo)

        # Step 3
        self.assertEqual(publication['repository_version'], version_hrefs[-1])

        # Step 4
        publication = publish(self.cfg, publisher, repo, non_latest)

        # Step 5
        self.assertEqual(publication['repository_version'], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                'repository': repo['_href'],
                'repository_version': non_latest
            }
            self.client.post(urljoin(publisher['_href'], 'publish/'), body)
예제 #34
0
def get_docker_image_paths(repo):
    """Return the relative path of content units present in a docker repository.

    :param repo: A dict of information about the repository.
    :returns: A list with the paths of units present in a given repository.
    """
    # FIXME: The "relative_path" is only valid for the file plugin.
    # It's just an example -- this needs to be replaced with an implementation that works
    # for repositories of this content type.
    return [
        content_unit['relative_path'] for content_unit in get_content(repo)
    ]
예제 #35
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphaned content units can be cleaned up."""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/")
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)
        content = choice(get_content(repo.to_dict())[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        repo_api.modify(repo.pulp_href, dict(remove_content_units=[content["pulp_href"]]))

        artifacts_api = ArtifactsApi(core_client)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact is present on disk.
            relative_path = artifacts_api.read(content["artifact"]).file
            artifact_path = os.path.join(self.media_root, relative_path)
            cmd = ("ls", artifact_path)
            self.cli_client.run(cmd, sudo=True)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content["pulp_href"], content_units_href)

        orphans_response = self.orphans_api.delete()
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]

        if self.orphan_protection_time == 0:
            self.assertNotIn(content["pulp_href"], content_units_href)

            if self.storage == "pulpcore.app.models.storage.FileSystem":
                # Verify that the artifact was removed from disk.
                with self.assertRaises(CalledProcessError):
                    self.cli_client.run(cmd)
예제 #36
0
def get_file_content_paths(repo, version_href=None):
    """Return the relative path of content units present in a file repository.

    :param repo: A dict of information about the repository.
    :param version_href: The repository version to read.
    :returns: A list with the paths of units present in a given repository.
    """
    # The "relative_path" is actually a file path and name
    return [
        content_unit["relative_path"]
        for content_unit in get_content(repo, version_href)[FILE_CONTENT_NAME]
    ]
예제 #37
0
    def test_sync(self):
        """Sync repositories with the gem 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.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        body = gen_gem_remote()
        remote = self.client.post(GEM_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)), GEM_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), GEM_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)), GEM_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), 0)
예제 #38
0
    def test_different_repository(self):
        """Test ``base_version`` for different repositories.

        Do the following:

        1. Create a new repository A and sync it.
        2. Create a new repository B and a new version for this repository
           specify repository A version 1 as the ``base_version``.
        3. Check that repository A version 1 and repository B version 1 have
           the same content.
        """
        # create repo A
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            [self.remove_created_key(item) for item in get_content(repo)])
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # get repo A version 1 to be used as base_version
        base_version = get_versions(repo)[0]['_href']

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

        # create a version for repo B using repo A version 1 as base_version
        self.client.post(repo['_versions_href'],
                         {'base_version': base_version})
        repo = self.client.get(repo['_href'])

        # assert that base_version of repo B points to version 1 of repo A
        self.assertEqual(get_versions(repo)[0]['base_version'], base_version)

        # assert that content on version 1 of repo A is equal to content on
        # version 1 repo B
        version_content.append(
            [self.remove_created_key(item) for item in get_content(repo)])

        self.assertEqual(version_content[0], version_content[1],
                         version_content)
예제 #39
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)
예제 #40
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})
예제 #41
0
    def test_base_version_other_parameters(self):
        """Test ``base_version`` can be used together with other parameters.

        ``add_content_units`` and ``remove_content_units``.
        """
        # create repo version 1
        self.skipTest("Temporarily skipping while we figure out a better testing strategy.")
        repo = self.create_sync_repo()
        version_1_content = [
            remove_created_key(item) for item in get_content(repo)[FILE_CONTENT_NAME]
        ]
        self.assertIsNone(get_versions(repo)[1]["base_version"])

        # create repo version 2 from version 1
        base_version = get_versions(repo)[1]["pulp_href"]
        added_content = remove_created_key(self.content.pop())
        removed_content = choice(version_1_content)
        modify_repo(
            self.cfg,
            repo,
            base_version=base_version,
            add_units=[added_content],
            remove_units=[removed_content],
        )
        repo = self.client.get(repo["pulp_href"])
        version_2_content = [
            remove_created_key(item) for item in get_content(repo)[FILE_CONTENT_NAME]
        ]

        # assert that base_version of the version 2 points to version 1
        self.assertEqual(get_versions(repo)[2]["base_version"], base_version)

        # assert that the removed content is not present on repo version 2
        self.assertNotIn(removed_content, version_2_content)

        # assert that the added content is present on repo version 2
        self.assertIn(added_content, version_2_content)

        # assert that the same amount of units are present in both versions
        self.assertEqual(len(version_1_content), len(version_2_content))
예제 #42
0
    def test_base_version_other_parameters(self):
        """Test ``base_version`` can be used together with other parameters.

        ``add_content_units`` and ``remove_content_units``.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_1_content = [
            remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # create repo version 2 from version 1
        base_version = get_versions(repo)[0]['pulp_href']
        added_content = remove_created_key(self.content.pop())
        removed_content = choice(version_1_content)
        self.client.post(
            repo['versions_href'], {
                'base_version': base_version,
                'add_content_units': [added_content['pulp_href']],
                'remove_content_units': [removed_content['pulp_href']]
            })
        repo = self.client.get(repo['pulp_href'])
        version_2_content = [
            remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]

        # assert that base_version of the version 2 points to version 1
        self.assertEqual(get_versions(repo)[1]['base_version'], base_version)

        # assert that the removed content is not present on repo version 2
        self.assertNotIn(removed_content, version_2_content)

        # assert that the added content is present on repo version 2
        self.assertIn(added_content, version_2_content)

        # assert that the same amount of units are present in both versions
        self.assertEqual(len(version_1_content), len(version_2_content))
예제 #43
0
    def test_sync_with_retention(self):
        """Verify functionality with sync.

        Do the following:

        1. Create a repository, and a remote.
        2. Sync the remote.
        3. Assert that the correct number of units were added and are present
           in the repo.
        4. Change the "retain_package_versions" on the repository to 1 (retain the latest
           version only).
        5. Sync the remote one more time.
        6. Assert that repository version is different from the previous one.
        7. Assert the repository version we end with has only one version of each package.
        """
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        remote = self.remote_api.create(gen_rpm_remote())
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        self.sync(repository=repo, remote=remote, optimize=False)
        repo = self.repo_api.read(repo.pulp_href)

        # Test that, by default, everything is retained / nothing is tossed out.
        self.assertDictEqual(get_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY)

        # Set the retention policy to retain only 1 version of each package
        repo_data = repo.to_dict()
        repo_data.update({"retain_package_versions": 1})
        self.repo_api.update(repo.pulp_href, repo_data)
        repo = self.repo_api.read(repo.pulp_href)

        self.sync(repository=repo, remote=remote, optimize=False)
        repo = self.repo_api.read(repo.pulp_href)

        # Test that only one version of each package is present
        self.assertTrue(
            self.check_retention_policy(get_content(repo.to_dict())[PULP_TYPE_PACKAGE], 1)
        )
        # Test that (only) 4 RPMs were removed (no advisories etc. touched)
        self.assertDictEqual(get_removed_content_summary(repo.to_dict()), {PULP_TYPE_PACKAGE: 4})
        # Test that the versions that were removed are the versions we expect.
        versions_for_packages = self.versions_for_packages(
            get_removed_content(repo.to_dict())[PULP_TYPE_PACKAGE]
        )
        self.assertDictEqual(
            versions_for_packages,
            {"duck": ["0.6", "0.7"], "kangaroo": ["0.2"], "walrus": ["0.71"]},
            versions_for_packages,
        )
예제 #44
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest
           ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        body = gen_rpm_remote()
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        sync(self.cfg, remote, repo)

        # Step 1
        repo = self.client.get(repo['_href'])
        for rpm_content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]:
            self.client.post(
                repo['_versions_href'],
                {'add_content_units': [rpm_content['_href']]}
            )
        version_hrefs = tuple(ver['_href'] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(self.cfg, repo)

        # Step 3
        self.assertEqual(publication['repository_version'], version_hrefs[-1])

        # Step 4
        publication = publish(self.cfg, repo, non_latest)

        # Step 5
        self.assertEqual(publication['repository_version'], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                'repository': repo['_href'],
                'repository_version': non_latest
            }
            self.client.post(RPM_PUBLICATION_PATH, body)
예제 #45
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

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

        sync(cfg, remote, repo)

        # Step 1
        repo = client.get(repo["pulp_href"])
        for file_content in get_content(repo)[FILE_CONTENT_NAME]:
            client.post(repo["versions_href"],
                        {"add_content_units": [file_content["pulp_href"]]})
        version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = create_file_publication(cfg, repo)

        # Step 3
        self.assertEqual(publication["repository_version"], version_hrefs[-1])

        # Step 4
        publication = create_file_publication(cfg, repo, non_latest)

        # Step 5
        self.assertEqual(publication["repository_version"], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                "repository": repo["pulp_href"],
                "repository_version": non_latest
            }
            client.post(FILE_PUBLICATION_PATH, body)
예제 #46
0
    def test_all(self):
        """Test of addtive mode."""
        client = gen_rpm_client()
        repo_api = RepositoriesRpmApi(client)
        remote_api = RemotesRpmApi(client)

        # 1. create repo, remote and sync them
        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_rpm_remote(url=RPM_UNSIGNED_FIXTURE_URL)
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # 2. create another remote and re-sync
        body = gen_rpm_remote(url=SRPM_UNSIGNED_FIXTURE_URL)
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # 3. Check content counts
        repo = repo_api.read(repo.pulp_href)
        present_package_count = len(
            get_content(repo.to_dict())[PULP_TYPE_PACKAGE])
        present_advisory_count = len(
            get_content(repo.to_dict())[PULP_TYPE_ADVISORY])
        self.assertEqual(
            RPM_PACKAGE_COUNT + SRPM_UNSIGNED_FIXTURE_PACKAGE_COUNT,
            present_package_count)
        self.assertEqual(
            RPM_ADVISORY_COUNT + SRPM_UNSIGNED_FIXTURE_ADVISORY_COUNT,
            present_advisory_count)
예제 #47
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)['pulp_file.file']
        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, {})
예제 #48
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, {})
예제 #49
0
def get_python_content_paths(repo, version_href=None):
    """Return the relative path of content units present in a python repository.

    :param repo: A dict of information about the repository.
    :param version_href: The repository version to read.
    :returns: A dict of lists with the paths of units present in a given repository.
        Paths are given as pairs with the remote and the local version for different content types.
    """
    return {
        PYTHON_CONTENT_NAME:
        [(content_unit["filename"], content_unit["filename"]) for content_unit
         in get_content(repo, version_href)[PYTHON_CONTENT_NAME]],
    }
예제 #50
0
    def test_clear_all_units_using_base_version(self):
        """Test clear all units using base version."""
        for content in self.content:
            modify_repo(self.cfg, self.repo, add_units=[content])

        self.repo = self.client.get(self.repo["pulp_href"])
        base_version = get_versions(self.repo)[0]["pulp_href"]

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

        content_last_version = get_content(self.repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_last_version), 0, content_last_version)
예제 #51
0
    def test_add_content_with_base_version(self):
        """Test modify repository with base_version"""
        delete_orphans()

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

        files = {"file": utils.http_get(FILE_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)

        # create first content unit.
        content_attrs = {"artifact": artifact["pulp_href"], "relative_path": utils.uuid4()}
        content = self.client.using_handler(api.task_handler).post(FILE_CONTENT_PATH, content_attrs)
        repo_version = modify_repo(self.cfg, repo, add_units=[content])
        repo = self.client.get(repo["pulp_href"])

        self.assertEqual(get_content(repo)[FILE_CONTENT_NAME][0], content)

        files = {"file": utils.http_get(FILE2_URL)}
        artifact = self.client.post(ARTIFACTS_PATH, files=files)

        # create second content unit.
        second_content_attrs = {
            "artifact": artifact["pulp_href"],
            "relative_path": content_attrs["relative_path"],
        }
        content2 = self.client.using_handler(api.task_handler).post(
            FILE_CONTENT_PATH, second_content_attrs
        )
        modify_repo(self.cfg, repo, add_units=[content2])
        repo = self.client.get(repo["pulp_href"])

        self.assertEqual(get_content(repo)[FILE_CONTENT_NAME][0], content2)

        modify_repo(self.cfg, repo, base_version=repo_version["pulp_href"], add_units=[content2])
        repo = self.client.get(repo["pulp_href"])

        self.assertEqual(get_content(repo)[FILE_CONTENT_NAME][0], content2)
예제 #52
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphan content units can be clean up.

        Do the following:

        1. Create, and sync a repo.
        2. Remove a content unit from the repo. This will create a second
           repository version, and create an orphan content unit.
        3. Assert that content unit that was removed from the repo and its
           artifact are present on disk.
        4. Delete orphans.
        5. Assert that the orphan content unit was cleaned up, and its artifact
           is not present on disk.
        """
        repo = self.api_client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo['_href'])

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

        sync(self.cfg, remote, repo)
        repo = self.api_client.get(repo['_href'])
        content = choice(get_content(repo)[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        self.api_client.post(
            repo['_versions_href'],
            {'remove_content_units': [content['_href']]}
        )

        # Verify that the artifact is present on disk.
        artifact_path = self.api_client.get(content['_artifact'])['file']
        cmd = ('ls', artifact_path)
        self.cli_client.run(cmd, sudo=True)

        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo)[0]['_href'])
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertIn(content, content_units)

        delete_orphans()
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertNotIn(content, content_units)

        # Verify that the artifact was removed from disk.
        with self.assertRaises(CalledProcessError):
            self.cli_client.run(cmd)
예제 #53
0
파일: utils.py 프로젝트: pulp/pulp_python
def get_python_content_paths(repo):
    """
    Return the relative path of content units present in a file repository.

    Args:
        repo (dict): A dict of information about the repository.

    Returns:
        list: The paths of units present in a given repository.

    """
    return [
        content_unit['filename']
        for content_unit in get_content(repo)[PYTHON_CONTENT_NAME]
    ]
예제 #54
0
파일: utils.py 프로젝트: pulp/pulp_deb
def get_deb_verbatim_content_unit_paths(repo):
    """Return the relative path of content units present in a deb repository.

    :param repo: A dict of information about the repository.
    :returns: A dict of list with the paths of units present in a given repository
        for different content types. Paths are given as pairs with the remote and the
        local version.
    """
    return {
        DEB_RELEASE_NAME: [
            (content_unit['relative_path'], content_unit['relative_path'])
            for content_unit in get_content(repo)[DEB_RELEASE_NAME]
        ],

        DEB_PACKAGE_NAME: [
            (content_unit['relative_path'], content_unit['relative_path'])
            for content_unit in get_content(repo)[DEB_PACKAGE_NAME]
        ],

        DEB_GENERIC_CONTENT_NAME: [
            (content_unit['relative_path'], content_unit['relative_path'])
            for content_unit in get_content(repo)[DEB_GENERIC_CONTENT_NAME]
        ],
    }
예제 #55
0
    def test_same_repository(self):
        """Test ``base_version`` for the same repository.

        Do the following:

        1. Create a repository.
        2. Sync the repository (this creates repository version 1).
        3. Add a new content unit a new repository version (this create
           repository version 2).
        4. Create a new repository version using version 1 as ``base_version``
           (this creates version 3).
        5. Check that version 1 and version 3 have the same content.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        content = self.content.pop()

        # create repo version 2
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [content['_href']]}
        )
        repo = self.client.get(repo['_href'])

        # create repo version 3 from version 1
        base_version = get_versions(repo)[0]['_href']
        self.client.post(
            repo['_versions_href'],
            {'base_version': base_version}
        )
        repo = self.client.get(repo['_href'])

        # assert that base_version of the version 3 points to version 1
        self.assertEqual(get_versions(repo)[2]['base_version'], base_version)

        # assert that content on version 1 is equal to content on version 3
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
예제 #56
0
파일: test_sync.py 프로젝트: pulp/pulp_rpm
    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']
                )
예제 #57
0
파일: test_sync.py 프로젝트: pulp/pulp_rpm
    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]
        )