Пример #1
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_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)

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

        # Step 1
        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])
        for rpm_content in client.get(RPM_CONTENT_PATH)['results']:
            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(cfg, publisher, repo)

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

        # Step 4
        publication = publish(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
            }
            client.post(urljoin(publisher['_href'], 'publish/'), body)
Пример #2
0
    def test_all(self):
        """Test whether the content present in a repo version is immutable.

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Attempt to update the content of a repository version.
        3. Assert that an HTTP exception is raised.
        4. Assert that the repository version was not updated.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

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

        sync(cfg, remote, repo)

        latest_version_href = client.get(repo['_href'])['_latest_version_href']
        with self.assertRaises(HTTPError):
            client.post(latest_version_href)
        repo = client.get(repo['_href'])
        self.assertEqual(latest_version_href, repo['_latest_version_href'])
Пример #3
0
    def test_all(self):
        """Verify whether the sync of a repository updates its version.

        This test explores the design choice stated in the `Pulp #3308`_ that a
        new repository version is created even if the sync does not add or
        remove any content units. Even without any changes to the remote if a
        new sync occurs, a new repository version is created.

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

        Do the following:

        1. Create a repository, and a remote.
        2. Sync the repository an arbitrary number of times.
        3. Verify that the repository version is equal to the previous number
           of syncs.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

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

        number_of_syncs = randint(1, 10)
        for _ in range(number_of_syncs):
            sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        path = urlsplit(repo['_latest_version_href']).path
        latest_repo_version = int(path.split('/')[-2])
        self.assertEqual(latest_repo_version, number_of_syncs)
Пример #4
0
    def test_exclude_unavailable_projects(self):
        """
        Test that sync doesn't fail if some of the excluded projects aren't available.

        Do the following:

        1. Update the remote to exclude a specifier that is smaller than the previous one.
        2. Sync the remote again.
        3. Assert that the content counts in the repo have increased again, to the count
           of the smaller excludes specifier.

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

        body = gen_python_remote(
            includes=PYTHON_MD_PROJECT_SPECIFIER,
            excludes=PYTHON_UNAVAILABLE_PROJECT_SPECIFIER
        )
        remote = self.client.post(PYTHON_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        self.assertEqual(
            get_content_summary(repo)[PYTHON_CONTENT_NAME],
            PYTHON_MD_PACKAGE_COUNT - PYTHON_UNAVAILABLE_PACKAGE_COUNT
        )
Пример #5
0
    def test_include_unavailable_projects(self):
        """
        Test that the sync doesn't fail if some included projects aren't available.

        Do the following:

        1. Create a remote.
        2. Sync the remote.
        3. Assert that the content counts in the repo match the correct count for the specifier.

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

        body = gen_python_remote(includes=PYTHON_UNAVAILABLE_PROJECT_SPECIFIER)
        remote = self.client.post(PYTHON_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        self.assertEqual(
            get_content_summary(repo)[PYTHON_CONTENT_NAME],
            PYTHON_UNAVAILABLE_PACKAGE_COUNT
        )
Пример #6
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)))
Пример #7
0
 def test_01_create_task(self):
     """Create a task."""
     repo = self.client.post(REPO_PATH, gen_repo())
     self.addCleanup(self.client.delete, repo['_href'])
     attrs = {'description': utils.uuid4()}
     response = self.client.patch(repo['_href'], attrs)
     self.task.update(self.client.get(response['task']))
Пример #8
0
def populate_pulp(cfg, url=DOCKER_V2_FEED_URL):
    """Add docker contents to Pulp.

    :param pulp_smash.config.PulpSmashConfig: Information about a Pulp application.
    :param url: The docker repository URL. Defaults to
        :data:`pulp_smash.constants.DOCKER_FIXTURE_URL`
    :returns: A list of dicts, where each dict describes one file content in Pulp.
    """
    client = api.Client(cfg, api.json_handler)
    remote = {}
    repo = {}
    try:
        remote.update(
            client.post(
                DOCKER_REMOTE_PATH,
                gen_remote(url, upstream_name=DOCKER_UPSTREAM_NAME)

            )
        )
        repo.update(client.post(REPO_PATH, gen_repo()))
        sync(cfg, remote, repo)
    finally:
        if remote:
            client.delete(remote['_href'])
        if repo:
            client.delete(repo['_href'])
    return client.get(DOCKER_CONTENT_PATH)['results']
Пример #9
0
    def test_single_request_upload(self):
        """Test single request upload."""
        cfg = config.get_config()
        # Pulp does not support single request upload for a RPM already present
        # in Pulp.
        delete_orphans(cfg)
        file = {'file': utils.http_get(RPM_UNSIGNED_URL)}
        client = api.Client(cfg, api.page_handler)
        repo = client.post(REPO_PATH, gen_repo())

        self.addCleanup(client.delete, repo['_href'])
        client.post(
            urljoin(BASE_PATH, 'rpm/upload/'),
            files=file,
            data={'repository': repo['_href']}
        )
        repo = client.get(repo['_href'])

        # Assertion about repo version.
        self.assertIsNotNone(repo['_latest_version_href'], repo)

        # Assertions about artifcats.
        artifact = client.get(ARTIFACTS_PATH)
        self.assertEqual(len(artifact), 1, artifact)
        self.assertEqual(
            artifact[0]['sha256'],
            hashlib.sha256(file['file']).hexdigest(),
            artifact
        )

        # Assertion about content unit.
        content = client.get(RPM_CONTENT_PATH)
        self.assertEqual(len(content), 1, content)
Пример #10
0
    def test_all(self):
        """Sync/publish a repo that ``updateinfo.xml`` contains references.

        This test targets the following issue:

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

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

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

        self.assertIsNotNone(repo['_latest_version_href'])

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

        publication = publish(self.cfg, repo)
        self.addCleanup(self.client.delete, publication['_href'])
Пример #11
0
    def test_sync(self):
        """Sync repositories with the docker 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'])

        remote = self.client.post(DOCKER_REMOTE_PATH, gen_docker_remote())
        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'])

        # 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'])
Пример #12
0
    def test_content(self):
        """Test pagination for repository versions."""
        # Add content to Pulp, create a repo, and add content to repo. We
        # sample 21 contents, because with page_size set to 10, this produces 3
        # pages, where the three three pages have unique combinations of values
        # for the "previous" and "next" links.
        populate_pulp(self.cfg, urljoin(FILE_MANY_FIXTURE_URL, 'PULP_MANIFEST'))
        sample_size = min(FILE_MANY_FIXTURE_COUNT, 21)
        contents = sample(self.client.get(FILE_CONTENT_PATH), sample_size)
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        def add_content():
            """Repeatedly pop an item from ``contents``, and add to repo."""
            while True:
                try:
                    content = contents.pop()
                    self.client.post(
                        repo['_versions_href'],
                        {'add_content_units': [content['_href']]}
                    )
                except IndexError:
                    break

        threads = tuple(Thread(target=add_content) for _ in range(8))
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()

        # Verify pagination works for getting repo versions.
        repo = self.client.get(repo['_href'])
        repo_versions = get_versions(repo, {'page_size': 10})
        self.assertEqual(len(repo_versions), sample_size, repo_versions)
Пример #13
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']
        )
Пример #14
0
def populate_pulp(cfg, remote=None):
    """
    Add python content to Pulp.

    Args:
        cfg (pulp_smash.config.PulpSmashConfig): Information about a Pulp application
        remote (dict): A dict of information about the remote.

    Returns:
        list: A list of dicts, where each dict describes one python content in Pulp.

    """
    if remote is None:
        remote = gen_python_remote()
    client = api.Client(cfg, api.json_handler)
    repo = {}
    try:
        remote.update(client.post(PYTHON_REMOTE_PATH, remote))
        repo.update(client.post(REPO_PATH, gen_repo()))
        sync(cfg, remote, repo)
    finally:
        if remote:
            client.delete(remote['_href'])
        if repo:
            client.delete(repo['_href'])
    return client.get(PYTHON_CONTENT_PATH)['results']
Пример #15
0
def populate_pulp(cfg, url=None):
    """Add file contents to Pulp.

    :param pulp_smash.config.PulpSmashConfig: Information about a Pulp
        application.
    :param url: The URL to a file repository's ``PULP_MANIFEST`` file. Defaults
        to :data:`pulp_smash.constants.FILE_FEED_URL` + ``PULP_MANIFEST``.
    :returns: A list of dicts, where each dict describes one file content in
        Pulp.
    """
    if url is None:
        url = urljoin(FILE_FIXTURE_URL, 'PULP_MANIFEST')
    client = api.Client(cfg, api.json_handler)
    remote = {}
    repo = {}
    try:
        remote.update(client.post(FILE_REMOTE_PATH, gen_remote(url)))
        repo.update(client.post(REPO_PATH, gen_repo()))
        sync(cfg, remote, repo)
    finally:
        if remote:
            client.delete(remote['_href'])
        if repo:
            client.delete(repo['_href'])
    return client.get(FILE_CONTENT_PATH)['results']
Пример #16
0
    def test_all(self):
        """Test whether sync/publish for content already in Pulp."""
        cfg = config.get_config()
        client = api.Client(cfg, api.page_handler)

        # step 1. delete orphans to assure that no content is present on disk,
        # or database.
        delete_orphans(cfg)

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

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

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

        for _ in range(2):
            sync(cfg, remote, repo)
            repo = client.get(repo['_href'])
            publish(cfg, publisher, repo)
Пример #17
0
    def test_file_decriptors(self):
        """Test whether file descriptors are closed properly.

        This test targets the following issue:
        `Pulp #4073 <https://pulp.plan.io/issues/4073>`_

        Do the following:
        1. Check if 'lsof' is installed. If it is not, skip this test.
        2. Create and sync a repo.
        3. Run the 'lsof' command to verify that files in the
           path ``/var/lib/pulp/`` are closed after the sync.
        4. Assert that issued command returns `0` opened files.
        """
        cli_client = cli.Client(self.cfg, cli.echo_handler)

        # check if 'lsof' is available
        if cli_client.run(('which', 'lsof')).returncode != 0:
            raise unittest.SkipTest('lsof package is not present')

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

        remote = self.client.post(DEB_REMOTE_PATH, gen_deb_remote())
        self.addCleanup(self.client.delete, remote['_href'])

        sync(self.cfg, remote, repo)

        cmd = 'lsof -t +D {}'.format(MEDIA_PATH).split()
        response = cli_client.run(cmd).stdout
        self.assertEqual(len(response), 0, response)
Пример #18
0
    def test_all(self):
        """Verify multi-resourcing locking.

        Do the following:

        1. Create a repository, and a remote.
        2. Update the remote to point to a different url.
        3. Immediately run a sync. The sync should fire after the update and
           sync from the second url.
        4. Assert that remote url was updated.
        5. Assert that the number of units present in the repository is
           according to the updated url.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

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

        url = {'url': FILE_FIXTURE_MANIFEST_URL}
        client.patch(remote['_href'], url)

        sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        remote = client.get(remote['_href'])
        self.assertEqual(remote['url'], url['url'])
        self.assertDictEqual(get_content_summary(repo), FILE_FIXTURE_SUMMARY)
Пример #19
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
        )
Пример #20
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'])
Пример #21
0
    def setUpClass(cls):
        """
        Create class-wide variables.
        """
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)

        cls.remote = {}
        cls.repo = cls.client.post(REPO_PATH, gen_repo())
Пример #22
0
    def setUpClass(cls):
        """Create class-wide variables.

        In order to create a publisher a repository has to be created first.
        """
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)
        cls.publisher = {}
        cls.repo = cls.client.post(REPO_PATH, gen_repo())
Пример #23
0
    def test_rpm(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.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        # Create a remote with the standard test fixture url.
        body = gen_rpm_remote()
        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'])

        # Check that we have the correct content counts.
        self.assertIsNotNone(repo['_latest_version_href'])
        self.assertDictEqual(
            get_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )
        self.assertDictEqual(
            get_added_content_summary(repo),
            RPM_FIXTURE_SUMMARY
        )

        # Sync the repository again.
        latest_version_href = repo['_latest_version_href']
        sync(self.cfg, remote, repo)
        repo = self.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_SUMMARY
        )
        self.assertDictEqual(get_added_content_summary(repo), {})
Пример #24
0
    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')
Пример #25
0
    def test_02_create_same_name(self):
        """Try to create a second repository with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/PulpQE/pulp-smash/issues/1055>`_.
        """
        body = gen_repo()
        body['name'] = self.repo['name']
        with self.assertRaises(HTTPError):
            self.client.post(REPO_PATH, body)
Пример #26
0
    def create_sync_repo(self):
        """Create, and sync a repo."""
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

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

        sync(self.cfg, remote, repo)
        return self.client.get(repo['_href'])
Пример #27
0
 def create_repos():
     """Repeatedly create repos and append to ``repos_hrefs``."""
     # "It's better to beg for forgiveness than to ask for permission."
     while True:
         repo_href = self.client.post(REPO_PATH, gen_repo())['_href']
         with repo_hrefs_lock:
             if len(repo_hrefs) < number_to_create:
                 repo_hrefs.append(repo_href)
             else:
                 self.client.delete(repo_href)
                 break
Пример #28
0
 def test_clean_orphan_artifact(self):
     """Test whether orphan artifacts units can be clean up."""
     repo = self.api_client.post(REPO_PATH, gen_repo())
     self.addCleanup(self.api_client.delete, repo['_href'])
     files = {'file': utils.http_get(FILE2_URL)}
     artifact = self.api_client.post(ARTIFACTS_PATH, files=files)
     cmd = self.sudo + ('ls', artifact['file'])
     self.cli_client.run(cmd)
     delete_orphans()
     with self.assertRaises(CalledProcessError):
         self.cli_client.run(cmd)
Пример #29
0
 def setUp(self):
     """Create a repository and give it new versions."""
     self.repo = self.client.post(REPO_PATH, gen_repo())
     self.addCleanup(self.client.delete, self.repo['_href'])
     for content in self.contents[:10]:  # slice is arbitrary upper bound
         self.client.post(
             self.repo['_versions_href'],
             {'add_content_units': [content['_href']]}
         )
         sleep(1)
     self.repo = self.client.get(self.repo['_href'])
Пример #30
0
    def test_all(self):
        """Verify the set up of parameters related to auto distribution.

        This test targets the following issues:

        * `Pulp #3295 <https://pulp.plan.io/issues/3295>`_
        * `Pulp #3392 <https://pulp.plan.io/issues/3392>`_
        * `Pulp #3394 <https://pulp.plan.io/issues/3394>`_
        * `Pulp #3671 <https://pulp.plan.io/issues/3671>`_
        * `Pulp Smash #883 <https://github.com/PulpQE/pulp-smash/issues/883>`_
        * `Pulp Smash #917 <https://github.com/PulpQE/pulp-smash/issues/917>`_
        """
        # Create a repository and a publisher.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

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

        # Create a distribution.
        self.try_create_distribution(publisher=publisher['_href'])
        self.try_create_distribution(repository=repo['_href'])
        body = gen_distribution()
        body['publisher'] = publisher['_href']
        body['repository'] = repo['_href']
        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])

        # Update the distribution.
        self.try_update_distribution(distribution, publisher=None)
        self.try_update_distribution(distribution, repository=None)
        distribution = self.client.patch(distribution['_href'], {
            'publisher': None,
            'repository': None,
        })
        self.assertIsNone(distribution['publisher'], distribution)
        self.assertIsNone(distribution['repository'], distribution)

        # Publish the repository. Assert that distribution does not point to
        # the new publication (because publisher and repository are unset).
        remote = self.client.post(
            FILE_REMOTE_PATH,
            gen_remote(FILE_FIXTURE_MANIFEST_URL),
        )
        self.addCleanup(self.client.delete, remote['_href'])

        sync(self.cfg, remote, repo)

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

        distribution = self.client.get(distribution['_href'])
        self.assertNotEqual(distribution['publication'], publication['_href'])
Пример #31
0
    def test_sync(self):
        """Sync repositories with the container 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 the same from the previous one.
        """
        repository_api = RepositoriesContainerApi(self.client_api)
        repository = repository_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(repository_api.delete, repository.pulp_href)

        remote_api = RemotesContainerApi(self.client_api)
        remote = remote_api.create(gen_container_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)

        self.assertEqual(repository.latest_version_href,
                         f"{repository.pulp_href}versions/0/")
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)

        # Sync the repository.
        sync_response = repository_api.sync(repository.pulp_href,
                                            repository_sync_data)
        monitor_task(sync_response.task)
        repository = repository_api.read(repository.pulp_href)
        self.assertIsNotNone(repository.latest_version_href)

        # Sync the repository again.
        latest_version_href = repository.latest_version_href
        sync_response = repository_api.sync(repository.pulp_href,
                                            repository_sync_data)
        monitor_task(sync_response.task)
        repository = repository_api.read(repository.pulp_href)
        self.assertEqual(latest_version_href, repository.latest_version_href)
Пример #32
0
    def test_all(self):
        """Verify whether task report shows repository version was created."""
        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'])

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

        call_report = sync(cfg, remote, repo)
        for key in ('repositories', 'versions'):
            self.assertIn(
                key,
                call_report['pulp_href'],
                call_report
            )
    def create_install_scenario(self, body, collection_name):
        """Create Install scenario."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

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

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

        # Create a distribution.
        body = gen_distribution()
        body["base_path"] = "pulp_post_upgrade_test"
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_create.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])

        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = "ansible-galaxy collection install {} -c -s {} -p {}".format(
                collection_name, distribution.client_url, temp_dir)

            directory = "{}/ansible_collections/{}".format(
                temp_dir, collection_name.replace(".", "/"))

            self.assertTrue(not path.exists(directory),
                            "Directory {} already exists".format(directory))

            subprocess.run(cmd.split())

            self.assertTrue(path.exists(directory),
                            "Could not find directory {}".format(directory))
Пример #34
0
    def do_test(self, url):
        """Sync a repository given ``url`` on the remote."""
        repo_api = RepositoriesRpmApi(self.client)
        remote_api = RemotesRpmApi(self.client)

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

        body = gen_rpm_remote(url=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)
        try:
            task_result = monitor_task(sync_response.task)
        except PulpTaskError as exc:
            task_result = exc.task.to_dict()
        return task_result
Пример #35
0
 def _create_repo_and_versions(self):
     # Create a new file-repo, repo-2
     a_repo = self.repo_api.create(gen_repo())
     self.addCleanup(self.client.delete, a_repo.pulp_href)
     # get a list of all the files from one of our existing repos
     file_list = self.content_api.list()
     # copy files from repositories[0] into 2, one file at a time
     results = file_list.results
     for a_file in results:
         href = a_file.pulp_href
         modify_response = self.repo_api.modify(
             a_repo.pulp_href, {"add_content_units": [href]})
         monitor_task(modify_response.task)
     # get all versions of that repo
     # should now be 4, with 0/1/2/3 files as content
     versions = self.versions_api.list(a_repo.pulp_href, ordering="number")
     self.assertIsNotNone(versions)
     self.assertEqual(4, versions.count)
     return a_repo, versions
Пример #36
0
    def do_sync(self, download_policy):
        """Sync repositories with the different ``download_policy``.

        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 possible units to be downloaded
           were shown.
        6. Sync the remote one more time in order to create another repository
           version.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of units are shown, and after the
           second sync no extra units should be shown, since the same remote
           was synced again.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        remote = self.client.post(RPM_REMOTE_PATH,
                                  gen_rpm_remote(policy=download_policy))
        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.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo),
                             RPM_FIXTURE_SUMMARY)

        # 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.assertDictEqual(get_content_summary(repo), RPM_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo), {})
Пример #37
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.
        """
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        body = gen_plugin_template_remote()
        remote = self.client.post(PLUGIN_TEMPLATE_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.assertDictEqual(get_content_summary(repo),
                             PLUGIN_TEMPLATE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo),
                             PLUGIN_TEMPLATE_FIXTURE_SUMMARY)

        # 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.assertDictEqual(get_content_summary(repo),
                             PLUGIN_TEMPLATE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo), {})
Пример #38
0
    def test_sync_large_repo(self):
        """Sync large EPEL repository."""
        cfg = config.get_config()
        client = api.Client(cfg, api.page_handler)

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

        remote = client.post(RPM_REMOTE_PATH, gen_rpm_remote(url=RPM_EPEL_URL))
        self.addCleanup(client.delete, remote['pulp_href'])

        # Sync the repository.
        self.assertEqual(repo["latest_version_href"], f"{repo['pulp_href']}versions/0/")
        sync(cfg, remote, repo)
        repo = client.get(repo['pulp_href'])
        content_summary = get_content_summary(repo)
        self.assertGreater(
            content_summary[RPM_PACKAGE_CONTENT_NAME], 0, content_summary
        )
Пример #39
0
    def test_sync_modular_repo(self):
        """Test RPM modular content can be synced."""
        cfg = config.get_config()
        client = api.Client(cfg)

        remote = client.post(RPM_REMOTE_PATH,
                             gen_rpm_remote(url=RPM_MODULAR_FIXTURE_URL))
        self.addCleanup(client.delete, remote['pulp_href'])

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

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

        added_content_summary = get_added_content_summary(repo)

        self.assertEqual(added_content_summary, RPM_MODULAR_FIXTURE_SUMMARY,
                         added_content_summary)
Пример #40
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.page_handler)
     cls.remote = {}
     cls.publication = {}
     cls.publisher = {}
     cls.repo = {}
     try:
         cls.repo.update(cls.client.post(REPO_PATH, gen_repo()))
         body = gen_file_remote()
         cls.remote.update(cls.client.post(FILE_REMOTE_PATH, body))
         cls.publisher.update(
             cls.client.post(FILE_PUBLISHER_PATH, gen_file_publisher())
         )
         sync(cls.cfg, cls.remote, cls.repo)
     except Exception:
         cls.tearDownClass()
         raise
Пример #41
0
def populate_pulp(url=REGISTRY_V2_FEED_URL):
    """Add container contents to Pulp.

    :param url: The container repository URL. Defaults to
        :data:`pulp_container.tests.functional.constants.REGISTRY_V2_FEED_URL`
    :returns: A dictionary of created resources.
    """
    container_client = ContainerApiClient(configuration)
    remotes_api = RemotesContainerApi(container_client)
    repositories_api = RepositoriesContainerApi(container_client)

    container_remote = remotes_api.create(gen_container_remote(url))
    sync_data = RepositorySyncURL(remote=container_remote.pulp_href)
    container_repository = repositories_api.create(gen_repo())
    sync_response = repositories_api.sync(container_repository.pulp_href,
                                          sync_data)

    created_resources = monitor_task(sync_response.task)
    return created_resources
Пример #42
0
    def test_file_content(self):
        """Test pagination for repository versions."""
        # Add content to Pulp, create a repo, and add content to repo. We
        # sample 21 contents, because with page_size set to 10, this produces 3
        # pages, where the three three pages have unique combinations of values
        # for the "previous" and "next" links.
        populate_pulp(self.cfg, url=FILE_MANY_FIXTURE_MANIFEST_URL)
        sample_size = min(FILE_MANY_FIXTURE_COUNT, 21)
        contents = sample(self.client.get(FILE_CONTENT_PATH), sample_size)
        repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['pulp_href'])

        for content in contents:
            modify_repo(self.cfg, repo, add_units=[content])

        # Verify pagination works for getting repo versions.
        repo = self.client.get(repo['pulp_href'])
        repo_versions = get_versions(repo, {'page_size': 10})
        self.assertEqual(len(repo_versions), sample_size + 1, repo_versions)
Пример #43
0
    def setUpClass(cls):
        """Create class wide-variables."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)
        cls.namespaces_api = PulpContainerNamespacesApi(api_client)

        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)

        cls.repository = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Пример #44
0
    def do_publish(self, download_policy):
        """Publish repository synced with lazy download policy."""
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

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

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

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

        publication = create_file_publication(self.cfg,
                                              repo,
                                              publisher=publisher)
        self.assertIsNotNone(publication['repository_version'], publication)
Пример #45
0
    def test_all(self):
        """
        Sync a repository using a Remote url that does not exist.

        Test that we get a task failure.

        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

        body = gen_ansible_remote(url="http://i-am-an-invalid-url.com/invalid/")
        remote = client.post(ANSIBLE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        with self.assertRaises(exceptions.TaskReportError):
            sync(cfg, remote, repo)
Пример #46
0
    def test_sync(self):
        """Test duplicate content can be synced."""
        cfg = config.get_config()
        client = api.Client(cfg)

        for url in [RPM_REFERENCES_UPDATEINFO_URL, RPM_UNSIGNED_FIXTURE_URL]:
            remote = client.post(RPM_REMOTE_PATH, gen_rpm_remote(url=url))
            self.addCleanup(client.delete, remote['_href'])

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

            client.post(urljoin(remote['_href'], 'sync/'),
                        {'repository': repo['_href']})
            repo = client.get(repo['_href'])

            added_content_summary = get_added_content_summary(repo)
            self.assertEqual(added_content_summary, RPM_FIXTURE_SUMMARY,
                             added_content_summary)
Пример #47
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.page_handler)
     cls.client_echo = api.Client(cls.cfg, api.echo_handler)
     cls.remote = {}
     cls.publication = {}
     cls.repo = {}
     try:
         cls.repo.update(cls.client.post(FILE_REPO_PATH, gen_repo()))
         cls.repo_initial_version = cls.repo["latest_version_href"]
         body = gen_file_remote()
         cls.remote.update(cls.client.post(FILE_REMOTE_PATH, body))
         sync(cls.cfg, cls.remote, cls.repo)
         # update to get latest_version_href
         cls.repo.update(cls.client.get(cls.repo["pulp_href"]))
     except Exception:
         cls.tearDownClass()
         raise
Пример #48
0
    def test_all(self):
        """Sync and publish an RPM repository and verify the checksum."""
        # 1. create repo and remote
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

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

        # 2. Sync it
        repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)

        # 3. Publish and distribute
        publish_data = RpmRpmPublication(repository=repo.pulp_href)
        publish_response = self.publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(self.publications.delete, publication_href)

        body = gen_distribution()
        body["publication"] = publication_href
        distribution_response = self.distributions.create(body)
        created_resources = monitor_task(distribution_response.task)
        distribution = self.distributions.read(created_resources[0])
        self.addCleanup(self.distributions.delete, distribution.pulp_href)

        # 4. check the tag 'sum' is not present in updateinfo.xml
        repomd = ElementTree.fromstring(
            http_get(os.path.join(distribution.base_url,
                                  'repodata/repomd.xml')))

        update_xml_url = self._get_updateinfo_xml_path(repomd)
        update_xml_content = http_get(
            os.path.join(distribution.base_url, update_xml_url))
        update_xml = read_xml_gz(update_xml_content)
        update_info_content = ElementTree.fromstring(update_xml)

        tags = {elem.tag for elem in update_info_content.iter()}
        self.assertNotIn('sum', tags, update_info_content)
Пример #49
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 the same as the previous one.
        8. Assert that the same number of are present and that no units were
           added.
        """
        repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])

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

        # Sync the repository.
        self.assertIsNone(repo["latest_version_href"])
        sync(self.cfg, remote, repo)
        repo = self.client.get(repo["pulp_href"])

        self.assertIsNotNone(repo["latest_version_href"])
        self.assertDictEqual(get_content_summary(repo), FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo), FILE_FIXTURE_SUMMARY)

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

        self.assertEqual(latest_version_href, repo["latest_version_href"])
        self.assertDictEqual(get_content_summary(repo), FILE_FIXTURE_SUMMARY)
Пример #50
0
    def test_all(self):
        """Verify remotes can be used with different repos.

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

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

        Do the following:

        1. Create a remote.
        2. Create 2 repositories.
        3. Sync both repositories using the same remote.
        4. Assert that the two repositories have the same contents.
        """
        cfg = config.get_config()

        # Create a remote.
        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"])

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

        # Compare contents of repositories.
        contents = []
        for repo in repos:
            contents.append(get_content(repo)[FILE_CONTENT_NAME])
        self.assertEqual(
            {content["pulp_href"]
             for content in contents[0]},
            {content["pulp_href"]
             for content in contents[1]},
        )
Пример #51
0
    def test_06_second_unit_raises_error(self):
        """
        Create a duplicate content unit with different ``artifacts`` and same ``repo_key_fields``.
        """
        delete_orphans()
        client = gen_rpm_client()
        repo_api = RepositoriesRpmApi(client)

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

        artifact = gen_artifact()

        # create first content unit.
        content_attrs = {
            "artifact": artifact["pulp_href"],
            "relative_path": "test_package"
        }
        response = self.rpm_content_api.create(**content_attrs)
        monitor_task(response.task)

        artifact = gen_artifact(url=RPM_SIGNED_URL2)

        # create second content unit.
        second_content_attrs = {"artifact": artifact["pulp_href"]}
        second_content_attrs["relative_path"] = content_attrs["relative_path"]
        response = self.rpm_content_api.create(**second_content_attrs)
        monitor_task(response.task)

        data = {
            "add_content_units":
            [c.pulp_href for c in self.rpm_content_api.list().results]
        }
        response = repo_api.modify(repo.pulp_href, data)
        with self.assertRaises(PulpTaskError) as cm:
            monitor_task(response.task)
        task = cm.exception.task.to_dict()

        error_message = "Cannot create repository version. Path is duplicated: {}.".format(
            content_attrs["relative_path"])

        self.assertEqual(task["error"]["description"], error_message)
Пример #52
0
    def test_all(self):
        """Sync/publish a repo that ``updateinfo.xml`` contains references.

        This test targets the following issue:

        `Pulp #3998 <https://pulp.plan.io/issues/3998>`_.
        """
        client = gen_rpm_client()
        repo_api = RepositoriesRpmApi(client)
        remote_api = RemotesRpmApi(client)
        publications = PublicationsRpmApi(client)

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

        body = gen_rpm_remote(RPM_REFERENCES_UPDATEINFO_URL)
        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 = RpmRepositorySyncURL(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)

        self.assertIsNotNone(repo.latest_version_href)

        content_summary = get_content_summary(repo.to_dict())
        self.assertDictEqual(content_summary, RPM_FIXTURE_SUMMARY,
                             content_summary)

        publish_data = RpmRpmPublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(
            publish_response.task).created_resources
        publication_href = created_resources[0]

        self.assertIsNotNone(publication_href)

        self.addCleanup(publications.delete, publication_href)
Пример #53
0
    def test_duplicate_file_sync(self):
        """Sync a repository with remotes containing same file names.

        This test does the following.

        1. Create a repository in pulp.
        2. Create two remotes containing the same file.
        3. Check whether the created repo has only one copy of the file.

        This test targets the following issue:

        `Pulp #4738 <https://pulp.plan.io/issues/4738>`_
        """
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

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

        # Step 2
        remote = remote_api.create(gen_file_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)
        remote2 = remote_api.create(
            gen_file_remote(url=FILE2_FIXTURE_MANIFEST_URL))

        self.addCleanup(remote_api.delete, remote2.pulp_href)
        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)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        repository_sync_data = RepositorySyncURL(remote=remote2.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)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Пример #54
0
    def test_install_role(self):
        """Test whether ansible-galaxy can install a Role hosted by Pulp."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        body = gen_ansible_remote(url=ANSIBLE_ELASTIC_FIXTURE_URL)
        remote = self.remote_role_api.create(body)
        self.addCleanup(self.remote_role_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 = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Create a distribution.
        body = gen_distribution()
        body["repository"] = repo.pulp_href
        distribution_create = self.distributions_api.create(body)
        distribution_url = monitor_task(distribution_create.task)
        distribution = self.distributions_api.read(distribution_url[0])

        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

        with tempfile.TemporaryDirectory() as temp_dir:
            cmd = "ansible-galaxy role install {} -c -s {} -p {}".format(
                ANSIBLE_ELASTIC_ROLE_WHITELIST, distribution.client_url,
                temp_dir)

            directory = "{}/{}".format(temp_dir,
                                       ANSIBLE_ELASTIC_ROLE_NAMESPACE_NAME)

            self.assertTrue(not path.exists(directory),
                            "Directory {} already exists".format(directory))

            subprocess.run(cmd.split())

            self.assertTrue(path.exists(directory),
                            "Could not find directory {}".format(directory))
Пример #55
0
    def do_test(self, policy):
        """Verify whether package manager can consume content from Pulp."""
        if not self._has_dnf():
            self.skipTest("This test requires dnf")

        client = api.Client(self.cfg, api.json_handler)
        body = gen_rpm_remote(policy=policy)
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote["pulp_href"])

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

        sync(self.cfg, remote, repo)

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

        body = gen_distribution()
        body["publication"] = publication["pulp_href"]
        distribution = client.using_handler(api.task_handler).post(RPM_DISTRIBUTION_PATH, body)
        self.addCleanup(client.delete, distribution["pulp_href"])

        cli_client = cli.Client(self.cfg)
        cli_client.run(("sudo", "dnf", "config-manager", "--add-repo", distribution["base_url"]))
        repo_id = "*{}_".format(distribution["base_path"])
        cli_client.run(
            (
                "sudo",
                "dnf",
                "config-manager",
                "--save",
                "--setopt={}.gpgcheck=0".format(repo_id),
                repo_id,
            )
        )
        self.addCleanup(cli_client.run, ("sudo", "dnf", "config-manager", "--disable", repo_id))
        rpm_name = "walrus"
        self.pkg_mgr.install(rpm_name)
        self.addCleanup(self.pkg_mgr.uninstall, rpm_name)
        rpm = cli_client.run(("rpm", "-q", rpm_name)).stdout.strip().split("-")
        self.assertEqual(rpm_name, rpm[0])
Пример #56
0
    def test_sync(self):
        """Sync repositories with the docker 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_docker_remote()
        remote = client.post(DOCKER_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)), DOCKER_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), DOCKER_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)), DOCKER_FIXTURE_COUNT)
        self.assertEqual(len(get_added_content(repo)), 0)
    def setUpClass(cls):
        """Sync pulp/test-fixture-1 so we can copy content from it."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)

        cls.from_repo = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.from_repo.pulp_href, sync_data)
        monitor_task(sync_response.task)

        cls.latest_from_version = cls.repositories_api.read(
            cls.from_repo.pulp_href
        ).latest_version_href
Пример #58
0
    def test_all(self):
        """Test whether sync/publish for content already in Pulp."""
        cfg = config.get_config()
        client = api.Client(cfg, api.page_handler)

        # step 1. delete orphans to assure that no content is present on disk,
        # or database.
        delete_orphans(cfg)

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

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

        for _ in range(2):
            sync(cfg, remote, repo)
            repo = client.get(repo['pulp_href'])
            create_file_publication(cfg, repo)
Пример #59
0
    def sync_repository_with_whitelisted_tags(self, whitelist_tags):
        """Sync a new repository with the whitelisted tags passed as an argument."""
        self.repository = self.repositories_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(self.repositories_api.delete,
                        self.repository.pulp_href)

        remote_data = gen_container_remote(
            upstream_name=DOCKERHUB_PULP_FIXTURE_1,
            whitelist_tags=whitelist_tags)
        remote = self.remotes_api.create(remote_data)
        self.addCleanup(self.remotes_api.delete, remote.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)

        sync_response = self.repositories_api.sync(self.repository.pulp_href,
                                                   repository_sync_data)
        monitor_task(sync_response.task)
        repository = self.repositories_api.read(self.repository.pulp_href)
        self.assertIsNotNone(repository.latest_version_href)
Пример #60
0
    def test_single_request_upload(self):
        """Test single request upload."""
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])
        self.single_request_upload(repo=repo)
        repo = self.client.get(repo["pulp_href"])

        # Assertion about repo version.
        self.assertIsNotNone(repo["latest_version_href"], repo)

        # Assertions about artifacts.
        artifact = self.client.get(ARTIFACTS_PATH)
        self.assertEqual(len(artifact), 1, artifact)
        self.assertEqual(artifact[0]["sha256"],
                         hashlib.sha256(self.file["file"]).hexdigest(),
                         artifact)

        # Assertion about content unit.
        content = self.client.get(DEB_PACKAGE_PATH)
        self.assertEqual(len(content), 1, content)