示例#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 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)
示例#2
0
    def test_publish_invalid_repo_version(self):
        """Repo version containing two units with the same name and version can't be published."""
        cfg = config.get_config()
        delete_orphans(cfg)
        client = api.Client(cfg, api.json_handler)

        # Create repo u1 and sync partially
        repo_u1 = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo_u1["_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["_href"])

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

        # Create repo u1_diff_digest and sync partially
        repo_u1_diff_digest = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo_u1_diff_digest["_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["_href"])

        sync(cfg, remote_u1_diff_digest, repo_u1_diff_digest, mirror=True)
        repo_u1_diff_digest = client.get(repo_u1_diff_digest["_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)
        client.post(
            repo_u1["_versions_href"],
            {"add_content_units": [content_u1_diff_digest[0]["_href"]]})

        publisher = client.post(COOKBOOK_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher["_href"])
        with self.assertRaisesRegex(TaskReportError,
                                    "would contain multiple versions"):
            publish(cfg, publisher, repo_u1)
示例#3
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)
        client.post(repo["_versions_href"],
                    {"add_content_units": [cb["_href"] for cb in cb_content]})
        repo = client.get(repo["_href"])
        distribution = self.create_distribution(cfg, client, repo)
        self.download_check(cfg, client, repo, distribution, policy)
示例#4
0
    def verify_ids_and_artifacts(self, repo, policy):
        """
        Verify that content_id and artifact presence corresponds to the policy.

        Verify that cookbook content_id is of the right type (based in the
        format; content_type_id is hidden by the serializer). Artifacts must be
        present in 'immediate' mode, otherwise not.
        """
        for cookbook in get_cookbook_content(repo):
            if policy == "immediate":
                self.assertEqual(
                    len(cookbook["content_id"]),
                    64,
                    msg=f"{cookbook} does not have a SHA256 content_id",
                )
                self.assertIsNotNone(cookbook["artifact"])
            else:
                self.assertEqual(
                    len(cookbook["content_id"]),
                    36,
                    msg=f"{cookbook} does not have a UUID conten_id",
                )
                self.assertIsNone(cookbook["artifact"])
示例#5
0
 def verify_counts(self, repo, all_count, added_count, removed_count):
     self.assertEqual(len(get_cookbook_content(repo)), all_count)
     self.assertEqual(len(get_cookbook_added_content(repo)), added_count)
     self.assertEqual(len(get_cookbook_removed_content(repo)),
                      removed_count)
示例#6
0
    def test_sync_repo_isolation(self):
        """Sync two repositories with same content but different artifacts.

        The two repo fixtures u1 and u1_diff_digest contain the same cookbooks
        by name and version, but differ in the digest of the artifact. Ensure
        that syncing these two remotes to two repos respectively does not mixup
        cookbooks.
        """
        client = api.Client(self.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"])

        self.assert_initial_repo(repo_u1)

        example1_count = fixture_u1.cookbook_count([fixture_u1.example1_name])
        self.sync_and_inspect_task_report(remote_u1, repo_u1, example1_count)

        repo_u1 = client.get(repo_u1["pulp_href"])
        self.verify_counts(repo_u1,
                           all_count=example1_count,
                           added_count=example1_count,
                           removed_count=0)

        # Create repo u1_diff_digest and do a full sync
        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)
        remote_u1_diff_digest = client.post(COOKBOOK_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote_u1_diff_digest["pulp_href"])

        self.assert_initial_repo(repo_u1_diff_digest)

        # u1 and u1_diff_digest must not share content: all cookbooks are added
        cookbook_count = fixture_u1_diff_digest.cookbook_count()
        self.sync_and_inspect_task_report(remote_u1_diff_digest,
                                          repo_u1_diff_digest, cookbook_count)

        repo_u1_diff_digest = client.get(repo_u1_diff_digest["pulp_href"])
        self.verify_counts(
            repo_u1_diff_digest,
            all_count=cookbook_count,
            added_count=cookbook_count,
            removed_count=0,
        )

        # Full sync u1
        client.patch(remote_u1["pulp_href"], {"cookbooks": {}})
        all_cookbook_count = fixture_u1.cookbook_count()
        self.sync_and_inspect_task_report(remote_u1, repo_u1,
                                          all_cookbook_count - example1_count)
        repo_u1 = client.get(repo_u1["pulp_href"])
        self.verify_counts(
            repo_u1,
            all_count=all_cookbook_count,
            added_count=all_cookbook_count - example1_count,
            removed_count=0,
        )

        # Verify that the same cookbooks (w.r.t. name and version) differ by content_id
        content_u1_diff_digest = get_cookbook_content(repo_u1_diff_digest)
        self.assertTrue(content_u1_diff_digest)
        for c_u1 in get_cookbook_content(repo_u1):
            for c_u1_diff_digest in content_u1_diff_digest:
                if (c_u1["name"] == c_u1_diff_digest["name"]
                        and c_u1["version"] == c_u1_diff_digest["version"]):
                    artifact_u1 = client.get(c_u1["artifact"])
                    self.assertEqual(c_u1["content_id"], artifact_u1["sha256"])
                    artifact_u1_diff_digest = client.get(
                        c_u1_diff_digest["artifact"])
                    self.assertEqual(c_u1_diff_digest["content_id"],
                                     artifact_u1_diff_digest["sha256"])
                    self.assertNotEqual(c_u1["content_id"],
                                        c_u1_diff_digest["content_id"])
                    break
            else:
                self.fail(
                    f"Found no matching cookbook for {c_u1} in u1_diff_digest")