Skip to content
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

#646: Add filters to select by related pulp_deb content types #647

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

sdherr
Copy link
Contributor

@sdherr sdherr commented Sep 30, 2022

These new filters allow you to ask the questions "What Packages are in the current version of this Release?" or "What ReleaseComponents contain this Package?" Examples:

/pulp/api/v3/content/deb/packages/?release=<release_uuid>,<repo_version_href>
/pulp/api/v3/content/deb/packages/?release_component=<release_component_uuid>,<repo_version_href>
/pulp/api/v3/content/deb/releases/?package=<package_uuid>,<repo_version_href>
/pulp/api/v3/content/deb/release_components/?package=<package_uuid>,<repo_version_href>

It also provides a simple framework by which any similar types of filters can be added, and an explanation about why it works the way it does.

Copy link
Collaborator

@quba42 quba42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this submission. I think I understand what this feature is getting at. I cannot promise that we will get around to testing, reviewing, and merging this very soon, but we will try our best to do so by the next Y-release.

To make the linting turn green, you will need to squish all your commits into one and change the commit message similar to:

Add filters to select by related pulp_deb content types

closes #646

@quba42 quba42 added the .feature CHANGES/<issue_number>.feature label Oct 19, 2022
@sdherr
Copy link
Contributor Author

sdherr commented Nov 9, 2022

Thanks, I have squashed the commits and updated the commit message.

@sdherr
Copy link
Contributor Author

sdherr commented Jan 26, 2023

@quba42 Ping, I believe this is ready for merging. We have been using this patch successfully for several months now.

@stale
Copy link

stale bot commented Apr 26, 2023

This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!

@stale
Copy link

stale bot commented Apr 26, 2023

This pull request is no longer marked for closure.

@sdherr
Copy link
Contributor Author

sdherr commented Apr 28, 2023

Reworked to ensure that the filter args are always hrefs, never uuids, and that a versionless repo href is acceptable too if you just want the latest version.

REPO_VERSION_HREF="/pulp/api/v3/repositories/deb/apt/55c5fbfd-a339-468c-81eb-a4e5ac35a751/versions/6/"
REPO_HREF="/pulp/api/v3/repositories/deb/apt/55c5fbfd-a339-468c-81eb-a4e5ac35a751/"
PACKAGE_HREF="/pulp/api/v3/content/deb/packages/d4241dcb-3718-4b94-bfa2-4a7acf5c36a9/"
RELEASE_HREF="/pulp/api/v3/content/deb/releases/722e5015-1cd6-4ae2-bdad-12cfc720d565/"
RELEASE_COMPONENT_HREF="/pulp/api/v3/content/deb/release_components/7006389b-992d-4c5a-8162-a4dd0b7eec07/"

# find releases that contains a particular package in a repo version
http :8080/pulp/api/v3/content/deb/releases/?package="$PACKAGE_HREF,$REPO_VERSION_HREF"
http :8080/pulp/api/v3/content/deb/releases/?package="$PACKAGE_HREF,$REPO_HREF"
# find release components...
http :8080/pulp/api/v3/content/deb/release_components/?package="$PACKAGE_HREF,$REPO_VERSION_HREF"
http :8080/pulp/api/v3/content/deb/release_components/?package="$PACKAGE_HREF,$REPO_HREF"

# find packages that are in a particular release in a repo version
http :8080/pulp/api/v3/content/deb/packages/?release="$RELEASE_HREF,$REPO_VERSION_HREF"
http :8080/pulp/api/v3/content/deb/packages/?release="$RELEASE_HREF,$REPO_HREF"
# find packages that are in a particular release_component in a repo version
http :8080/pulp/api/v3/content/deb/packages/?release_component="$RELEASE_COMPONENT_HREF,$REPO_VERSION_HREF"
http :8080/pulp/api/v3/content/deb/packages/?release_component="$RELEASE_COMPONENT_HREF,$REPO_HREF"

@sdherr sdherr requested a review from quba42 May 8, 2023 17:18
Copy link
Collaborator

@quba42 quba42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies, but it looks like this change is rather badly affected by my refactor in #741 and by extension currently broken on latest main branch. It needs to be rebased and reworked. I already noted one needed change below, but more importantly ReleaseComponents no longer have a foreign key to Releases and are instead associated only loosely by both having the same distribution string (and there can be only one Release per distribution within a single repository version).

Right now I am getting django.core.exceptions.FieldError: Cannot resolve keyword 'deb_releasecomponent' into field. when filtering for Releases that have a particular package in a particular repo.

Querrying for release_components that have a particular package still works.

In the return direction filter for packages in a particular release or release_component I also get errors.

I am sorry I did not think of, and communicate this sooner. 😦

pulp_deb/app/viewsets/content.py Outdated Show resolved Hide resolved
@sdherr sdherr force-pushed the component-filter branch 2 times, most recently from 0b9c4d5 to e87ae29 Compare May 11, 2023 20:56
@sdherr
Copy link
Contributor Author

sdherr commented May 11, 2023

@quba42 Right you are, I have updated the patch to work properly against the Release model changes. Here's an updated test scenario:

# setup a test case that mirrors the docstring on ContentRelationshipFilter
# we have a couple packages
PACKAGE_ONE="/pulp/api/v3/content/deb/packages/273ba34b-5173-4056-9c0a-cc93a4ef032d/"
PACKAGE_TWO="/pulp/api/v3/content/deb/packages/499c4296-1ce8-40c4-9246-ea9d422e633f/"

# create a repo
http :8080/pulp/api/v3/repositories/deb/apt/ name=test-repo
REPO="/pulp/api/v3/repositories/deb/apt/c0e374a6-b8ad-4ac7-bf01-d03a4c076246/"

# create a couple releases
http :8080/pulp/api/v3/content/deb/releases/ distribution=one codename=one suite=one
RELEASE_ONE="/pulp/api/v3/content/deb/releases/3e08a29d-1c9e-455d-9a20-57de815f0a14/"
http :8080/pulp/api/v3/content/deb/releases/ distribution=two codename=two suite=two
RELEASE_TWO="/pulp/api/v3/content/deb/releases/09996f70-5d77-42be-b1c5-2c8d737ef216/"

# create a couple release components
http :8080/pulp/api/v3/content/deb/release_components/ component=main distribution=one codename=one suite=one
RC_ONE="/pulp/api/v3/content/deb/release_components/097221f5-0e80-403a-8c53-840a2c5e15d7/"
http :8080/pulp/api/v3/content/deb/release_components/ component=main distribution=two codename=two suite=two
RC_TWO="/pulp/api/v3/content/deb/release_components/a095423c-3603-441e-910e-cb919d4b67c9/"

# create three package release components
http :8080/pulp/api/v3/content/deb/package_release_components/ package="$PACKAGE_ONE" release_component="$RC_ONE"
PRC_ONE="/pulp/api/v3/content/deb/package_release_components/1c337ac8-1597-435d-b421-23586bcb890d/"
http :8080/pulp/api/v3/content/deb/package_release_components/ package="$PACKAGE_TWO" release_component="$RC_ONE"
PRC_TWO="/pulp/api/v3/content/deb/package_release_components/de0231e8-6954-4616-8167-c0df59dead2f/"
http :8080/pulp/api/v3/content/deb/package_release_components/ package="$PACKAGE_TWO" release_component="$RC_TWO"
PRC_THREE="/pulp/api/v3/content/deb/package_release_components/6592df8c-2a4a-4180-8b3f-baf6092025de/"

# add everything to the repo
http :8080${REPO}modify/ add_content_units:="[\"$RELEASE_ONE\", \"$RELEASE_TWO\", \"$RC_ONE\", \"$RC_TWO\", \"$PRC_ONE\", \"$PRC_TWO\", \"$PRC_THREE\", \"$PACKAGE_ONE\", \"$PACKAGE_TWO\"]"

# unmap package_two from release_component_one
http :8080${REPO}modify/ remove_content_units:="[\"$PRC_TWO\"]"

# test filters
# find releases that contain a particular package
http :8080/pulp/api/v3/content/deb/releases/?package="$PACKAGE_TWO,$REPO"
http :8080/pulp/api/v3/content/deb/releases/?package="$PACKAGE_TWO,${REPO}versions/2/"
http :8080/pulp/api/v3/content/deb/releases/?package="$PACKAGE_TWO,${REPO}versions/1/"

# find release components...
http :8080/pulp/api/v3/content/deb/release_components/?package="$PACKAGE_TWO,$REPO"
http :8080/pulp/api/v3/content/deb/release_components/?package="$PACKAGE_TWO,${REPO}versions/2/"
http :8080/pulp/api/v3/content/deb/release_components/?package="$PACKAGE_TWO,${REPO}versions/1/"

# find packages that are in a particular release in a repo version
http :8080/pulp/api/v3/content/deb/packages/?release="$RELEASE_ONE,$REPO"
http :8080/pulp/api/v3/content/deb/packages/?release="$RELEASE_ONE,${REPO}versions/2/"
http :8080/pulp/api/v3/content/deb/packages/?release="$RELEASE_ONE,${REPO}versions/1/"

# find packages that are in a particular release_component in a repo version
http :8080/pulp/api/v3/content/deb/packages/?release_component="$RC_ONE,$REPO"
http :8080/pulp/api/v3/content/deb/packages/?release_component="$RC_ONE,${REPO}versions/2/"
http :8080/pulp/api/v3/content/deb/packages/?release_component="$RC_ONE,${REPO}versions/1/"

@sdherr sdherr requested a review from quba42 May 11, 2023 20:59
@quba42
Copy link
Collaborator

quba42 commented May 17, 2023

I performed a round of testing with a real repository using:

REMOTE_OPTIONS='--url=http://deb.tuxedocomputers.com/ubuntu/ --distribution=bionic --distribution=focal --component=main --architecture=i386 --architecture=amd64 --policy=on_demand'
ENTITIES_NAME='package_filter_test'
PULP_URL=http://localhost:5001
PULP_CLI_CMD=pulp -p oci-env  # requires relevant entry in ~/.config/pulp/cli.toml
HTTP_CMD=http --auth admin:password

${PULP_CLI_CMD} deb remote create --name=${ENTITIES_NAME} ${REMOTE_OPTIONS}
${PULP_CLI_CMD} deb repository create --name=${ENTITIES_NAME} --remote=${ENTITIES_NAME}
${PULP_CLI_CMD} deb repository sync --name=${ENTITIES_NAME}
APT_PUBLICATION_HREF=$(${PULP_CLI_CMD} deb publication create --structured --repository=${ENTITIES_NAME} | jq -r .pulp_href)
${PULP_CLI_CMD} deb distribution create --name=${ENTITIES_NAME} --base-path=${ENTITIES_NAME} --publication=${APT_PUBLICATION_HREF}

REPOSITORY_HREF=$(${PULP_CLI_CMD} deb repository show --name=${ENTITIES_NAME} | jq -r .pulp_href)
PACKAGE_HREF=$(${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/packages/?package=linux-modules-extra-5.15.0-10056-tuxedo | jq -r .results[0].pulp_href)

# find releases that contain a particular package
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/releases/?package="${PACKAGE_HREF},${REPOSITORY_HREF}"
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/releases/?package="${PACKAGE_HREF},${REPOSITORY_HREF}versions/1/"

RELEASE_HREF=$(${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/releases/?package="${PACKAGE_HREF},${REPOSITORY_HREF}" | jq -r .results[0].pulp_href)

# find release_components that contain a particular package
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/release_components/?package="${PACKAGE_HREF},${REPOSITORY_HREF}"
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/release_components/?package="${PACKAGE_HREF},${REPOSITORY_HREF}versions/1/"

RELEASE_COMPONENT_HREF=$(${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/release_components/?package="${PACKAGE_HREF},${REPOSITORY_HREF}" | jq -r .results[0].pulp_href)

# find packages that are in a particular release in a repo version
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/packages/?release="${RELEASE_HREF},${REPOSITORY_HREF}"
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/packages/?release="${RELEASE_HREF},${REPOSITORY_HREF}versions/1/"

# find packages that are in a particular release_component in a repo version
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/packages/?release_component="${RELEASE_COMPONENT_HREF},${REPOSITORY_HREF}"
${HTTP_CMD} get ${PULP_URL}/pulp/api/v3/content/deb/packages/?release_component="${RELEASE_COMPONENT_HREF},${REPOSITORY_HREF}versions/1/"

# Let us remove the Release unit from our repo version:
${HTTP_CMD} post ${PULP_URL}${REPOSITORY_HREF}modify/ remove_content_units:="[\"${RELEASE_HREF}\"]"

# Now re-test all the filter querries

For the most part this all worked exactly like expected. If I remove the release from the repo, and then query for the release that contains my package, I get an empty list as expected. However, I can still querry for the release_component.

However, if I querry for all the packages that are in the release (that is no longer in the latest repo version), I still find all the same packages as before which is a little odd. I will now go have a look at the code.

Copy link
Collaborator

@quba42 quba42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly ready to me. Only found some minor issues below.

I will have another think about how we can/should add tests for this. I don't know to what extent we have any existing tests for filters, but perhaps some existing sync test can be easily extended to assert the filter finds the expected number of packages or the expected release.distribution etc. As we have seen during manual testing, it is definitely possible for some refactor to break this filter so some kind of coverage seems important.

pulp_deb/app/viewsets/content.py Outdated Show resolved Hide resolved
pulp_deb/app/viewsets/content.py Outdated Show resolved Hide resolved
@quba42
Copy link
Collaborator

quba42 commented May 17, 2023

I am going to leave another comment here, because I asked around #pulp-dev on how this might be tested, and the consensus was that it should be possible to add something like packages_api.list(release=f"{release.pulp_href},{repository_version_href}") to an existing sync test, and then make assertions about which packages the filter should return for the test repo used.

An example of something similar in pulp_rpm: https://github.com/pulp/pulp_rpm/blob/main/pulp_rpm/tests/functional/api/test_copy.py#LL375C48-L375C48

Which means we should really figure out #734 since that is holding most of our existing sync tests hostage.

@sdherr
Copy link
Contributor Author

sdherr commented May 17, 2023

For the most part this all worked exactly like expected. If I remove the release from the repo, and then query for the release that contains my package, I get an empty list as expected. However, I can still query for the release_component.

However, if I query for all the packages that are in the release (that is no longer in the latest repo version), I still find all the same packages as before which is a little odd. I will now go have a look at the code.

@quba42 this sounds to me like an invalid repo state. I don't think it makes any sense to remove a Release from a repo and not remove all associated ReleaseComponents / PackageReleaseComponents, and Packages that are not linked elsewhere.

I'm not against the idea of doing an additional check and throwing an error if the Release doesn't exist like you suggested, but I think the ideal fix here would be for the "release delete api" to be more opinionated about what it means to delete a release from a repo.

@sdherr
Copy link
Contributor Author

sdherr commented May 17, 2023

I am going to leave another comment here, because I asked around #pulp-dev on how this might be tested, and the consensus was that it should be possible to add something like packages_api.list(release=f"{release.pulp_href},{repository_version_href}") to an existing sync test, and then make assertions about which packages the filter should return for the test repo used.

An example of something similar in pulp_rpm: https://github.com/pulp/pulp_rpm/blob/main/pulp_rpm/tests/functional/api/test_copy.py#LL375C48-L375C48

Which means we should really figure out #734 since that is holding most of our existing sync tests hostage.

I support the idea of adding tests, at least simple "happy path" tests to ensure this is not broken by a future DB model change. But if this is ready to merge and the sync test PR is not then should we just add a note to that PR to add the tests? Or I'd be happy to circle back later when the testing situation is resolved and add something. Simple "happy path" tests similar to that example in pulp_rpm should be about a 4-line change.

Copy link
Collaborator

@quba42 quba42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I performed another round of testing, and everything looks good to me.

I am fine with merging this as is, and working on a basic "happy path" test on a separate PR. That being said we did merge #734, so it should be possible to start working on a test. I will have another look what test could be relevantly extended.

pulp_deb/app/viewsets/content.py Show resolved Hide resolved
@quba42 quba42 merged commit a0816d5 into pulp:main Jun 1, 2023
@quba42
Copy link
Collaborator

quba42 commented Jun 1, 2023

Created a follow up task to add a test: #780

adamsanaglo pushed a commit to adamsanaglo/pulpcore that referenced this pull request Jul 13, 2023
This aligns our pulp_deb patches with the changes that [have been requested upstream](pulp/pulp_deb#647) (namely, that we pass a full pulp href as the filter args instead of just uuid).

The pulp_deb release filters have also been updated to assume the latest repo_version if you pass a repo href, so we can save ourselves a lookup here.

You can look at the upstream diff to see a non-patch version of the first patch's changes (there is no upstream PR for the second patch):
pulp/pulp_deb#647
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.feature CHANGES/<issue_number>.feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants