-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content app auto-distributes latest publication #1328
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Content app auto-distributes latest publication if distribution's ``repository`` field is set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,12 @@ | |
) | ||
from requests.exceptions import HTTPError | ||
|
||
from pulpcore.client.pulp_file import ( | ||
DistributionsFileApi, | ||
PublicationsFileApi, | ||
RemotesFileApi, | ||
RepositoriesFileApi, | ||
) | ||
from pulpcore.tests.functional.api.using_plugin.constants import ( | ||
FILE_CONTENT_NAME, | ||
FILE_DISTRIBUTION_PATH, | ||
|
@@ -28,6 +34,8 @@ | |
from pulpcore.tests.functional.api.using_plugin.utils import ( | ||
create_file_publication, | ||
gen_file_remote, | ||
gen_file_client, | ||
monitor_task, | ||
) | ||
from pulpcore.tests.functional.api.using_plugin.utils import set_up_module as setUpModule # noqa | ||
from pulpcore.tests.functional.api.using_plugin.utils import skip_if | ||
|
@@ -268,33 +276,44 @@ class ContentServePublicationDistributionTestCase(unittest.TestCase): | |
This test targets the following issue: | ||
|
||
`Pulp #4847 <https://pulp.plan.io/issues/4847>`_ | ||
`Pulp #8760 <https://pulp.plan.io/issues/8760>`_ | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Create class-wide variables.""" | ||
cls.cfg = config.get_config() | ||
cls.client = api.Client(cls.cfg) | ||
cls.file_client = gen_file_client() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice bindings tests, ty! |
||
cls.repo_api = RepositoriesFileApi(cls.file_client) | ||
cls.remote_api = RemotesFileApi(cls.file_client) | ||
cls.pub_api = PublicationsFileApi(cls.file_client) | ||
cls.dis_api = DistributionsFileApi(cls.file_client) | ||
|
||
def test_content_served(self): | ||
"""Verify that content is served over publication distribution.""" | ||
repo = self.client.post(FILE_REPO_PATH, gen_repo()) | ||
self.addCleanup(self.client.delete, repo["pulp_href"]) | ||
repo, *_, distribution = self.serve_content_workflow(cleanup=self.addCleanup) | ||
|
||
remote = self.client.post(FILE_REMOTE_PATH, gen_file_remote()) | ||
self.addCleanup(self.client.delete, remote["pulp_href"]) | ||
self.assert_content_served(repo.to_dict(), distribution.to_dict()) | ||
|
||
sync(self.cfg, remote, repo) | ||
repo = self.client.get(repo["pulp_href"]) | ||
def test_autopublish_content_served(self): | ||
"""Verify autopublished content is served over publication distributions.""" | ||
body = {"repository": {"autopublish": True, "manifest": "PULP_MANIFEST"}} | ||
repo, _, distro = self.serve_content_workflow( | ||
publish=False, bodies=body, cleanup=self.addCleanup | ||
) | ||
|
||
publication = create_file_publication(self.cfg, repo) | ||
self.addCleanup(self.client.delete, publication["pulp_href"]) | ||
self.assert_content_served(repo.to_dict(), distro.to_dict()) | ||
|
||
distribution = self.client.post( | ||
FILE_DISTRIBUTION_PATH, gen_distribution(publication=publication["pulp_href"]) | ||
) | ||
self.addCleanup(self.client.delete, distribution["pulp_href"]) | ||
def test_nonpublished_content_not_served(self): | ||
"""Verify content that hasn't been published is not served.""" | ||
*_, distro = self.serve_content_workflow(publish=False, cleanup=self.addCleanup) | ||
|
||
with self.assertRaises(HTTPError): | ||
self.download_pulp_manifest(distro.to_dict()) | ||
|
||
def assert_content_served(self, repo, distribution): | ||
"""Asserts content served at distribution is correct.""" | ||
pulp_manifest = parse_pulp_manifest(self.download_pulp_manifest(distribution)) | ||
|
||
self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest) | ||
|
@@ -314,6 +333,33 @@ def download_pulp_manifest(self, distribution): | |
unit_url = reduce(urljoin, (distribution["base_url"], "PULP_MANIFEST")) | ||
return self.client.get(unit_url) | ||
|
||
def serve_content_workflow(self, publish=True, bodies=None, cleanup=None): | ||
"""Creates the workflow for serving content.""" | ||
all_bodies = bodies or {} | ||
repo_body = gen_repo(**all_bodies.get("repository", {})) | ||
remote_body = gen_file_remote(**all_bodies.get("remote", {})) | ||
repo = self.repo_api.create(repo_body) | ||
remote = self.remote_api.create(remote_body) | ||
sync(self.cfg, remote.to_dict(), repo.to_dict()) | ||
repo = self.repo_api.read(repo.pulp_href) | ||
if publish: | ||
pub = create_file_publication(self.cfg, repo.to_dict()) | ||
pub = self.pub_api.read(pub["pulp_href"]) | ||
dis_body = {"publication": pub.pulp_href} | ||
else: | ||
dis_body = {"repository": repo.pulp_href} | ||
distro_response = self.dis_api.create(gen_distribution(**dis_body)) | ||
distro = self.dis_api.read(monitor_task(distro_response.task).created_resources[0]) | ||
if cleanup: | ||
cleanup(self.repo_api.delete, repo.pulp_href) | ||
cleanup(self.remote_api.delete, remote.pulp_href) | ||
cleanup(self.dis_api.delete, distro.pulp_href) | ||
if publish: | ||
cleanup(self.pub_api.delete, pub.pulp_href) | ||
if publish: | ||
return repo, remote, pub, distro | ||
return repo, remote, distro | ||
|
||
|
||
def parse_pulp_manifest(pulp_manifest): | ||
"""Parse pulp manifest.""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an index for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example of how to do it:
https://github.com/pulp/pulpcore/pull/1261/files#diff-b6921076eabe69f8f887286bbac04f5abb8c91b5e2e747b99ea932c5abf17135R408-R410
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've backed off on this, we should investigate indexes but we should probably try to measure the impact rather than adding them speculatively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added task to keep track of this: https://pulp.plan.io/issues/8777
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to exclude publications where
complete=False
as well here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah great point!