Repository navigation
Match Pulp entities exactly when removing a product - #1248
Conversation
Product removal looked up Pulp distributions with a name__startswith
search on "{owner}-{product}", so it also matched the distributions of
every product whose name starts with the same string, and deleted them.
Removing "user/almalinux" wiped the distributions of
"user/almalinux-extras" as well.
The guard that was supposed to skip repositories missing from Pulp
compared a repository name against a distribution name. Pulp names a
distribution "{repo_name}-distro", so the comparison never matched and
the product repositories were never deleted at all.
Both are fixed by building the exact distribution name to repository
mapping from the product repositories and narrowing the prefix search
down to it. Repository and distribution are now deleted together, so
repositories absent from Pulp are still skipped.
The sign key repository of a community product is a file repository and
was never cleaned up either, since only the RPM distribution endpoint
was queried. Both endpoints are checked now.
Fixes AlmaLinux/build-system#506
Matching a distribution by its "{repo_name}-distro" name leaves behind
whatever does not follow the convention, and matching a repository by
its href from our db leaves behind whatever the db does not know about.
Removal now lists the product repositories and distributions from pulp,
picks the repositories by the exact names the product has, and picks the
distributions by the repository they serve, falling back to the name.
The sign key file repository is listed the same way.
|
Follow-up after testing on a real Pulp: the The first version still identified a distribution by its name ( Removal now asks Pulp instead:
The regression test now gives the
|
Summary
Fixes AlmaLinux/build-system#506 — product removal could delete Pulp entities belonging to other products.
remove_product()fetched distributions with aname__startswithsearch onpulp_base_distro_name({owner}-{product}) and then deleted every href in the result. That prefix also matches every product whose name starts with the same string, so removinguser/almalinuxdeleted the distributions ofuser/almalinux-extrastoo.While fixing that, two related problems in the same block:
{repo_name}-distro(PulpClient.create_rpm_distro), so the comparison never matched,continuealways fired, and the product's Pulp repositories were never deleted — only its distributions.{owner}-{product}-sign-key-repo) is a Pulp file repository. Only the RPM distribution endpoint was queried, so it and its distribution were left behind on every removal.Changes
alws/crud/products.py—remove_product()builds an exact{repo.name}-distro→ repository mapping fromdb_product.repositoriesand filters the prefix-search result through it. The RPM and file distribution endpoints are queried concurrently, and each repository is deleted together with its distribution, so the "in DB but not in Pulp" case is still handled — now via the distribution's actual existence instead of a comparison that could never be true.alws/utils/pulp_client.py— newget_file_distros(), the file-distribution counterpart ofget_rpm_distros(), using the same paginated__get_entitiespath.tests/test_api/test_products.py— regression test: simulates both distribution endpoints, asserts every product repository and distribution (including the sign key file repo) is deleted, and that a similarly-named product's distributions in both endpoints are untouched.tests/fixtures/pulp.py— newget_file_distrosfixture;test_user_product_removeneeds it now that removal queries that endpoint.Testing
./run-tests.sh— 85 passed, 10 skipped.The new test was verified to fail against the unfixed code:
That run also showed the second bug directly — only distribution hrefs were collected, no repository hrefs.