-
Notifications
You must be signed in to change notification settings - Fork 90
Allow users to specify distribution and component when modifying content #1492
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
Open
daviddavis
wants to merge
1
commit into
pulp:main
Choose a base branch
from
daviddavis:repository-modify-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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,4 @@ | ||
| Allow `repositories/deb/apt/{pulp_id}/modify/` requests to assign added packages using the optional | ||
| `distribution` and `component` parameters. Supplying either parameter creates the corresponding | ||
| release component, release architecture, and package-release-component content; omitting both | ||
| preserves the existing package-only behavior. | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,13 +14,26 @@ | |
| ContentArtifact, | ||
| CreatedResource, | ||
| PulpTemporaryFile, | ||
| RepositoryVersion, | ||
| Upload, | ||
| UploadChunk, | ||
| ) | ||
| from pulpcore.plugin.tasking import add_and_remove, general_create | ||
| from pulpcore.plugin.util import get_url | ||
|
|
||
| from pulp_deb.app.models import AptRepository, Package, PackageReleaseComponent | ||
| from pulp_deb.app.constants import ( | ||
| DEFAULT_COMPONENT, | ||
| DEFAULT_DISTRIBUTION, | ||
| ) | ||
| from pulp_deb.app.models import ( | ||
| AptRepository, | ||
| Package, | ||
| PackageReleaseComponent, | ||
| ReleaseArchitecture, | ||
| ReleaseComponent, | ||
| SourcePackage, | ||
| SourcePackageReleaseComponent, | ||
| ) | ||
| from pulp_deb.app.models.signing_service import ( | ||
| AptPackageSigningService, | ||
| DebPackageSigningResult, | ||
|
|
@@ -29,6 +42,103 @@ | |
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _prepare_package_removals(repo, remove_content_units, base_version_pk, distribution, component): | ||
| """Expand the removal list to include the release component relationships of each package. | ||
|
|
||
| Removing a (source) package also requires removing its PackageReleaseComponent / | ||
| SourcePackageReleaseComponent links. When a distribution/component is given, the removal is | ||
| scoped to that component: a package is only removed from the repository if the scope held its | ||
| last relationship, so packages linked elsewhere or not linked at all are kept. | ||
|
Comment on lines
+48
to
+51
Collaborator
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. This describes my preferred behavior, and I tested this is in fact what happens. Also tested that removing a package without providing distribution and/or component, removes it and all PRCs referencing it from the repo as in the past. So all things removal look good to me. 👍 |
||
| """ | ||
| # "*" removes all content, so there is nothing to resolve here. | ||
| if not remove_content_units or "*" in remove_content_units: | ||
| return | ||
|
|
||
| repository_version = ( | ||
| RepositoryVersion.objects.get(pk=base_version_pk) | ||
| if base_version_pk | ||
| else repo.latest_version() | ||
| ) | ||
| # A distribution/component narrows the removal to a single release component. | ||
| scoped = distribution is not None or component is not None | ||
| if scoped: | ||
| distribution = distribution or DEFAULT_DISTRIBUTION | ||
| component = component or DEFAULT_COMPONENT | ||
|
|
||
| for model, relationship_model, relationship_field in ( | ||
| (Package, PackageReleaseComponent, "package"), | ||
| (SourcePackage, SourcePackageReleaseComponent, "source_package"), | ||
| ): | ||
| units = model.objects.filter(pk__in=remove_content_units) | ||
| relationships = relationship_model.objects.filter( | ||
| **{ | ||
| f"{relationship_field}__in": units, | ||
| "pk__in": repository_version.content, | ||
| } | ||
| ) | ||
| if scoped: | ||
| scoped_relationships = relationships.filter( | ||
| release_component__distribution=distribution, | ||
| release_component__component=component, | ||
| ) | ||
| # Relationships named in the request are removed alongside the scoped ones. | ||
| removed_relationship_ids = set( | ||
| relationship_model.objects.filter(pk__in=remove_content_units).values_list( | ||
| "pk", flat=True | ||
| ) | ||
| ) | ||
| removed_relationship_ids.update(scoped_relationships.values_list("pk", flat=True)) | ||
| still_linked = relationships.exclude(pk__in=removed_relationship_ids) | ||
| orphaned_unit_ids = { | ||
| str(pk) | ||
| for pk in scoped_relationships.values_list(f"{relationship_field}_id", flat=True) | ||
| } - {str(pk) for pk in still_linked.values_list(f"{relationship_field}_id", flat=True)} | ||
| kept_unit_ids = { | ||
| str(pk) for pk in units.values_list("pk", flat=True) | ||
| } - orphaned_unit_ids | ||
| remove_content_units[:] = [ | ||
| content_id for content_id in remove_content_units if content_id not in kept_unit_ids | ||
| ] | ||
| relationships = scoped_relationships | ||
| remove_content_units.extend(str(pk) for pk in relationships.values_list("pk", flat=True)) | ||
|
|
||
|
|
||
| def _prepare_package_additions(add_content_units, distribution, component): | ||
| """Expand the addition list with the metadata needed to publish the packages in a component. | ||
|
|
||
| For each (source) package being added under a distribution/component, ensure the matching | ||
| ReleaseComponent, ReleaseArchitecture and *ReleaseComponent relationships exist and add them | ||
| to the content being added. | ||
| """ | ||
| packages = list(Package.objects.filter(pk__in=add_content_units)) | ||
| source_packages = list(SourcePackage.objects.filter(pk__in=add_content_units)) | ||
| if not (packages or source_packages) or (distribution is None and component is None): | ||
| return | ||
|
|
||
| distribution = distribution or DEFAULT_DISTRIBUTION | ||
| component = component or DEFAULT_COMPONENT | ||
| release_component, _ = ReleaseComponent.objects.get_or_create( | ||
| distribution=distribution, component=component | ||
| ) | ||
| add_content_units.append(str(release_component.pk)) | ||
| # Each binary package needs its architecture and a link to the release component. | ||
| for package in packages: | ||
| if package.architecture != "all": | ||
| architecture, _ = ReleaseArchitecture.objects.get_or_create( | ||
| distribution=distribution, architecture=package.architecture | ||
| ) | ||
| package_component, _ = PackageReleaseComponent.objects.get_or_create( | ||
| release_component=release_component, package=package | ||
| ) | ||
| add_content_units.extend([str(architecture.pk), str(package_component.pk)]) | ||
| # Source packages only need a link to the release component. | ||
| for source_package in source_packages: | ||
| source_package_component, _ = SourcePackageReleaseComponent.objects.get_or_create( | ||
| release_component=release_component, source_package=source_package | ||
| ) | ||
| add_content_units.append(str(source_package_component.pk)) | ||
|
|
||
|
|
||
| def _save_file(fileobj, final_package): | ||
| with fileobj.file.open() as fd: | ||
| final_package.write(fd.read()) | ||
|
|
@@ -205,10 +315,19 @@ def _sign_package(package, signing_service, signing_fingerprint, package_release | |
|
|
||
|
|
||
| def signed_add_and_remove( | ||
| repository_pk, add_content_units, remove_content_units, base_version_pk=None, overwrite=True | ||
| repository_pk, | ||
| add_content_units, | ||
| remove_content_units, | ||
| base_version_pk=None, | ||
| overwrite=True, | ||
| distribution=None, | ||
| component=None, | ||
| ): | ||
| repo = AptRepository.objects.get(pk=repository_pk) | ||
|
|
||
| _prepare_package_removals(repo, remove_content_units, base_version_pk, distribution, component) | ||
| _prepare_package_additions(add_content_units, distribution, component) | ||
|
|
||
| if repo.package_signing_service: | ||
| log.info( | ||
| f"Signing packages for repository {repo.name} with {repo.package_signing_service}." | ||
|
|
@@ -260,6 +379,7 @@ async def _bounded_sign(pkg_tuple): | |
| new_prc, _ = PackageReleaseComponent.objects.get_or_create( | ||
| release_component=prc.release_component, | ||
| package_id=new_id, | ||
| index_architecture=prc.index_architecture, | ||
| _pulp_domain=prc._pulp_domain, | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.