예제 #1
0
    def test_removed_content_not_published(self):
        """Ensure content removed from a repository doesn't get published again."""
        remote = self._create_remote()
        repo = self._create_repo_and_sync_with_remote(remote)
        pub = self._create_publication(repo)
        distro = self._create_distribution_from_publication(pub)

        url = urljoin(PULP_CONTENT_BASE_URL, f"{distro.base_path}/simple/")
        proper, msgs = ensure_simple(url, {"shelf-reader": self.releases})
        self.assertTrue(proper, msg=msgs)

        removed_content = random.choice(get_content(repo.to_dict())[PYTHON_CONTENT_NAME])
        modify_repo(cfg, repo.to_dict(), add_units=[removed_content])
        repo = self.repo_api.read(repo.pulp_href)
        pub = self._create_publication(repo)
        distro = self._create_distribution_from_publication(pub)

        if removed_content["filename"] == PYTHON_WHEEL_FILENAME:
            remaining_release = [PYTHON_EGG_FILENAME]
        else:
            remaining_release = [PYTHON_WHEEL_FILENAME]
        url = urljoin(PULP_CONTENT_BASE_URL, f"{distro.base_path}/simple/")
        proper, msgs = ensure_simple(url, {"shelf-reader": remaining_release})

        self.assertTrue(proper, msg=msgs)
예제 #2
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.
        """
        remote = self._create_remote()
        repo = self._create_repo_and_sync_with_remote(remote)
        # Step 1
        for python_content in get_content(repo.to_dict())[PYTHON_CONTENT_NAME]:
            modify_repo(cfg, repo.to_dict(), add_units=[python_content])

        version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        repo = self.repo_api.read(repo.pulp_href)
        # Step 2, 3
        pub_latest = self._create_publication(repo)
        self.assertEqual(pub_latest.repository_version, version_hrefs[-1])
        # Step 4, 5
        pub_version = self._create_publication(repo, version=non_latest)
        self.assertEqual(pub_version.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {"repository": repo.pulp_href, "repository_version": non_latest}
            self.publications_api.create(body)
예제 #3
0
    def test_removed_content_not_published(self):
        """Ensure content removed from a repository doesn't get published again."""
        repo, _, _, distro = create_workflow(self.repo_api,
                                             self.pub_api,
                                             remote_api=self.rem_api,
                                             distro_api=self.dis_api,
                                             cleanup=self.addCleanup)

        proper, msgs = self.ensure_simple(distro.base_path,
                                          {"shelf-reader": self.releases})
        self.assertTrue(proper, msg=msgs)

        cfg = config.get_config()
        removed_content = random.choice(
            get_content(repo.to_dict())[PYTHON_CONTENT_NAME])
        modify_repo(cfg, repo.to_dict(), remove_units=[removed_content])

        publication = create_publication(self.pub_api,
                                         repo,
                                         cleanup=self.addCleanup)
        distro = create_distribution(self.dis_api,
                                     publication,
                                     cleanup=self.addCleanup)

        if removed_content["filename"] == PYTHON_WHEEL_FILENAME:
            remaining_release = [PYTHON_EGG_FILENAME]
        else:
            remaining_release = [PYTHON_WHEEL_FILENAME]
        proper, msgs = self.ensure_simple(distro.base_path,
                                          {"shelf-reader": remaining_release})

        self.assertTrue(proper, msg=msgs)
예제 #4
0
    def test_workflow_01(self):
        """
        Verify workflow 1
        """
        created_contents = []
        for pkg, filename in zip(self.PACKAGES_URLS,
                                 PYTHON_FIXTURES_FILENAMES):
            content_response = self.content_api.create(
                **gen_python_content_attrs(gen_artifact(pkg), filename))
            created_contents.extend(
                monitor_task(content_response.task).created_resources)
            created_contents = [
                self.content_api.read(href).to_dict()
                for href in created_contents
            ]

        repo = self._create_repository()
        # Add content
        modify_repo(cfg, repo.to_dict(), add_units=created_contents)
        repo = self.repo_api.read(repo.pulp_href)
        pub = self._create_publication(repo)
        distro = self._create_distribution_from_publication(pub)

        self.addCleanup(delete_orphans, cfg)
        self.check_consume(distro.to_dict())
예제 #5
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.
        3. Remove all content - one by one.
        3. Verify that the repository version is equal to the number of operations.
        """
        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"])

        sync(cfg, remote, repo)
        repo = client.get(repo["pulp_href"])
        for file_content in get_content(repo)[FILE_CONTENT_NAME]:
            modify_repo(cfg, repo, remove_units=[file_content])
        repo = client.get(repo["pulp_href"])
        path = urlsplit(repo["latest_version_href"]).path
        latest_repo_version = int(path.split("/")[-2])
        self.assertEqual(latest_repo_version, 4)
예제 #6
0
    def test_04_add_content(self):
        """Add content to the repository.

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

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

        self.assertIsNotNone(repo["latest_version_href"])

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

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

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

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

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

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

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
예제 #7
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. Create distribution.
        6. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        7. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(self.cfg,
                        self.repo.to_dict(),
                        remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

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

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

        # Step 5
        body = gen_distribution()
        body["base_path"] = "pulp_post_upgrade_test"
        body["publication"] = publication.pulp_href

        distribution_response = self.distributions.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = self.distributions.read(created_resources[0])

        # Step 6
        self.assertEqual(publication.repository_version, non_latest)

        # Step 7
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)

        # Step 8
        url = self.cfg.get_content_host_base_url(
        ) + "/pulp/content/pulp_post_upgrade_test/"
        self.assertEqual(url, distribution.base_url, url)
예제 #8
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 without supplying a repository_version (i.e.
           take 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()

        delete_orphans()

        client = api.Client(cfg, api.json_handler)
        body = gen_remote(fixture_u1.url, cookbooks={fixture_u1.example1_name: ""})
        remote = client.post(COOKBOOK_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote["pulp_href"])

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

        sync(cfg, remote, repo, mirror=True)
        repo = client.get(repo["pulp_href"])
        repo_content = get_cookbook_content(repo)
        self.assertTrue(repo_content)

        # Step 1
        repo = client.post(COOKBOOK_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo["pulp_href"])
        for cookbook in repo_content:
            modify_repo(cfg, repo, add_units=[cookbook])

        version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = create_publication(cfg, repo)

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

        # Step 4
        publication = create_publication(cfg, repo, version_href=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(COOKBOOK_PUBLICATION_PATH, body)
예제 #9
0
    def setUp(self):
        """Create a repository and give it new versions."""
        self.repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, self.repo["pulp_href"])

        for content in self.contents[:10]:  # slice is arbitrary upper bound
            modify_repo(self.cfg, self.repo, add_units=[content])
            sleep(1)
        self.repo = self.client.get(self.repo["pulp_href"])
예제 #10
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(
                [
                    remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['pulp_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[1]['base_version'])

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

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

        # create a version for repo B using repo A version 1 as base_version
        modify_repo(self.cfg, repo, base_version=base_version)
        repo = self.client.get(repo['pulp_href'])

        # assert that base_version of repo B points to version 1 of repo A
        self.assertEqual(get_versions(repo)[1]['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(
                [
                    remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['pulp_href'],
            )
        )

        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
예제 #11
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(
                [
                    remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['pulp_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[1]['base_version'])

        content = self.content.pop()

        # create repo version 2
        modify_repo(self.cfg, repo, add_units=[content])
        repo = self.client.get(repo['pulp_href'])

        # create repo version 3 from version 1
        base_version = get_versions(repo)[1]['pulp_href']
        modify_repo(self.cfg, repo, base_version=base_version)
        repo = self.client.get(repo['pulp_href'])

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

        # assert that content on version 1 is equal to content on version 3
        version_content.append(
            sorted(
                [
                    remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['pulp_href'],
            )
        )
        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
예제 #12
0
    def test_add_and_clear_all_units(self):
        """Test addition and removal of all units for a given repository version."""
        content = choice(self.content)
        modify_repo(self.cfg, self.repo, add_units=[content], remove_units=["*"])
        self.repo = self.client.get(self.repo["pulp_href"])

        added_content = get_content(self.repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(added_content), 1, added_content)

        self.assertEqual(remove_created_key(content), remove_created_key(added_content[0]))
예제 #13
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)
예제 #14
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 and repository parameters unset.
        for key, val in self.distribution.items():
            if key in ["content_guard", "repository"]:
                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
        )
예제 #15
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_deb_remote()
        remote = client.post(DEB_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote["pulp_href"])

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

        sync(cfg, remote, repo)

        # Step 1
        repo = client.get(repo["pulp_href"])
        for deb_generic_content in get_content(repo)[DEB_GENERIC_CONTENT_NAME]:
            modify_repo(cfg, repo, remove_units=[deb_generic_content])
        for deb_package in get_content(repo)[DEB_PACKAGE_NAME]:
            modify_repo(cfg, repo, remove_units=[deb_package])
        version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

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

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

        # Step 4
        publication = self.Meta.create_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(self.Meta.PUBLICATION_PATH, body)
예제 #16
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)
예제 #17
0
    def test_base_version_exception(self):
        """Exception is raised when non-existent ``base_version`` is used.

        Do the following:

        1. Create a repository B and an attempt to specify a non-existent
           ``base_version``.
        3. Assert that an HTTP exception is raised.
        """
        repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])

        with self.assertRaises(HTTPError):
            modify_repo(self.cfg, repo, base_version=utils.uuid4())
예제 #18
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(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo["pulp_href"])

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

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

        # Create an orphan content unit.
        modify_repo(self.cfg, repo, remove_units=[content])

        if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact is present on disk.
            artifact_path = os.path.join(
                MEDIA_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)[1]["pulp_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)

        if settings.DEFAULT_FILE_STORAGE == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact was removed from disk.
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
예제 #19
0
    def test_clear_all_units(self):
        """Test clear all units of a given repository version."""
        added_content = sorted(
            [content["pulp_href"] for content in get_content(self.repo)[FILE_CONTENT_NAME]]
        )

        modify_repo(self.cfg, self.repo, remove_units=["*"])
        self.repo = self.client.get(self.repo["pulp_href"])
        removed_content = sorted(
            [content["pulp_href"] for content in get_removed_content(self.repo)[FILE_CONTENT_NAME]]
        )
        self.assertEqual(added_content, removed_content)
        content = get_content(self.repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), 0, content)
예제 #20
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.client.post(FILE_REMOTE_PATH, gen_file_remote())
     cls.repository = cls.client.post(FILE_REPO_PATH, gen_repo())
     response = sync(cls.cfg, cls.remote, cls.repository)
     cls.created_repo_version = response['pulp_href']
     cls.repository = cls.client.get(cls.repository['pulp_href'])
     for file_content in get_content(cls.repository)[FILE_CONTENT_NAME]:
         modify_repo(cls.cfg, cls.repository, remove_units=[file_content])
     attrs = {'description': utils.uuid4()}
     response = cls.client.patch(cls.repository['pulp_href'], attrs)
     cls.repo_update_task = cls.client.get(response['task'])
예제 #21
0
    def test_add_content_with_base_version(self):
        """Test modify repository with base_version
        """
        delete_orphans(self.cfg)

        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)
예제 #22
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))
예제 #23
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.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(self.cfg,
                        self.repo.to_dict(),
                        remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

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

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

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

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)
예제 #24
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)
예제 #25
0
    def sync_merge_and_download_check(self, policy):
        """
        Merge two repos synced from same source and publish.

        1. sync repo and repo2 from the same source
        2. Add all content units from repo2 to repo
        3. publish and create distribution for repo
        4. Perform download check
        """
        cfg = config.get_config()
        delete_orphans(cfg)
        client = api.Client(cfg, api.json_handler)
        repo = self.create_and_sync_repo(cfg, client, policy)
        repo2 = self.create_and_sync_repo(cfg, client, policy)

        cb_content = get_cookbook_content(repo2)
        modify_repo(cfg, repo, add_units=cb_content)

        repo = client.get(repo["pulp_href"])
        distribution = self.create_distribution(cfg, client, repo)
        self.download_check(cfg, client, repo, distribution, policy)
예제 #26
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['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})
예제 #27
0
    def test_publish_invalid_repo_version(self):
        """Repo version containing two units with the same name and version can't be created."""
        cfg = config.get_config()
        delete_orphans(cfg)
        client = api.Client(cfg, api.json_handler)

        # Create repo u1 and sync partially
        repo_u1 = client.post(COOKBOOK_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo_u1["pulp_href"])

        body = gen_remote(fixture_u1.url,
                          cookbooks={fixture_u1.example1_name: ""})
        remote_u1 = client.post(COOKBOOK_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote_u1["pulp_href"])

        sync(cfg, remote_u1, repo_u1, mirror=True)
        repo_u1 = client.get(repo_u1["pulp_href"])

        # Create repo u1_diff_digest and sync partially
        repo_u1_diff_digest = client.post(COOKBOOK_REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo_u1_diff_digest["pulp_href"])

        body = gen_remote(fixture_u1_diff_digest.url,
                          cookbooks={fixture_u1.example1_name: ""})
        remote_u1_diff_digest = client.post(COOKBOOK_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote_u1_diff_digest["pulp_href"])

        sync(cfg, remote_u1_diff_digest, repo_u1_diff_digest, mirror=True)
        repo_u1_diff_digest = client.get(repo_u1_diff_digest["pulp_href"])

        # Add a content unit from u1_diff_digest to u1 (duplicate name&version)
        content_u1_diff_digest = get_cookbook_content(repo_u1_diff_digest)
        self.assertTrue(content_u1_diff_digest)
        with self.assertRaisesRegex(TaskReportError,
                                    "would contain multiple versions"):
            modify_repo(cfg, repo_u1, add_units=[content_u1_diff_digest[0]])
예제 #28
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()
        repo_api = deb_repository_api
        remote_api = deb_remote_api
        publication_api = self.Meta.publication_api

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

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.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)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for deb_generic_content in get_content(
                repo.to_dict())[DEB_GENERIC_CONTENT_NAME]:
            modify_repo(cfg,
                        repo.to_dict(),
                        remove_units=[deb_generic_content])
        for deb_package in get_content(repo.to_dict())[DEB_PACKAGE_NAME]:
            modify_repo(cfg, repo.to_dict(), remove_units=[deb_package])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = self.Meta.Publication(repository=repo.pulp_href,
                                             **self._publication_extra_args())
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        self.addCleanup(publication_api.delete, publication_href)
        publication = publication_api.read(publication_href)

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

        # Step 4
        publish_data = self.Meta.Publication(repository_version=non_latest,
                                             **self._publication_extra_args())
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        publication = publication_api.read(publication_href)

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

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publication_api.create(body)
예제 #29
0
    def test_optimize(self):
        """Sync is no-op without changes.

        This test targets the following issue:

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

        If there are no changes, a full sync should not be done.

        Do the following:

        1. Sync (a repo and a remote will be created automatically).
        2. Sync again to get our task dictionary.
        3. Assert an "Optimizing Sync" progress report is present.
        4. Sync again with flag "optimize=False".
        5. Assert "Optimizing Sync" progress report is absent.
        # 6. **Create a new repo version.
        # 7. Sync again (no flag).
        # 8. Assert "Optimizing Sync" progress report is absent.
        9. Update remote to have "policy=immediate".
        10. Sync again.
        11. Assert "Optimizing Sync" progress report is absent.
        12. Create a new (different) remote.
        13. Sync using the new remote.
        14. Assert "Optimizing Sync" progress report is absent.
        # 15. Sync again with the new remote.
        # 16. Assert an "Optimizing Sync" progress report is present.
        """
        # sync
        repo, remote = self.do_test()

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

        # sync, get progress reports from task
        report_list = self.sync(repository=repo, remote=remote)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was optimized
        self.assertTrue(optimized)

        # sync again with flag optimize=False
        report_list = self.sync(repository=repo, remote=remote, optimize=False)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was not optimized
        self.assertFalse(optimized)

        # create a new repo version
        content = choice(get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME])
        modify_repo(config.get_config(), repo.to_dict(), remove_units=[content])

        # sync, get progress reports from task
        report_list = self.sync(repository=repo, remote=remote)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was not optimized
        self.assertFalse(optimized)

        # update remote
        body = {"policy": "immediate"}
        response = self.remote_api.partial_update(remote.pulp_href, body)
        monitor_task(response.task)

        # sync, get progress reports from task
        report_list = self.sync(repository=repo, remote=remote)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was not optimized
        self.assertFalse(optimized)

        # create new remote
        body = gen_rpm_remote()
        body["url"] = RPM_RICH_WEAK_FIXTURE_URL
        new_remote = self.remote_api.create(body)

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

        # sync with new remote
        report_list = self.sync(repository=repo, remote=new_remote)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was not optimized
        self.assertFalse(optimized)

        # sync again with new remote
        report_list = self.sync(repository=repo, remote=new_remote)

        # check for an optimization progress report
        optimized = self.optimize_report(progress_reports=report_list)

        # check that sync was optimized
        self.assertTrue(optimized)
예제 #30
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 = gen_file_client()
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)
        publications = PublicationsFileApi(client)

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

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.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)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for file_content in get_content(repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(cfg, repo.to_dict(), remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)

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

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

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

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publications.create(body)