Skip to content

Commit

Permalink
Added set/unset_label support to pkg/updaterecord/modulemd* views.
Browse files Browse the repository at this point in the history
closes pulp#3896.
  • Loading branch information
ggainey committed Mar 5, 2025
1 parent bcd4cf5 commit 4a3f7ce
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGES/3896.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Added permissions for set/unset_label on RPM content-types.

The types that support this new call include:
* Package
* UpdateRecord
* Modulemd
* ModulemdDefaults
* ModulemdObsoletes
2 changes: 1 addition & 1 deletion pulp_rpm/app/viewsets/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UpdateRecordViewSet(NoArtifactContentUploadViewSet):
"effect": "allow",
},
{
"action": ["create"],
"action": ["create", "set_label", "unset_label"],
"principal": "authenticated",
"effect": "allow",
"condition": [
Expand Down
6 changes: 3 additions & 3 deletions pulp_rpm/app/viewsets/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ModulemdViewSet(SingleArtifactContentUploadViewSet):
"effect": "allow",
},
{
"action": ["create"],
"action": ["create", "set_label", "unset_label"],
"principal": "authenticated",
"effect": "allow",
"condition": [
Expand Down Expand Up @@ -99,7 +99,7 @@ class ModulemdDefaultsViewSet(SingleArtifactContentUploadViewSet):
"effect": "allow",
},
{
"action": ["create"],
"action": ["create", "set_label", "unset_label"],
"principal": "authenticated",
"effect": "allow",
"condition": [
Expand Down Expand Up @@ -129,7 +129,7 @@ class ModulemdObsoleteViewSet(SingleArtifactContentUploadViewSet):
"effect": "allow",
},
{
"action": ["create"],
"action": ["create", "set_label", "unset_label"],
"principal": "authenticated",
"effect": "allow",
},
Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/viewsets/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PackageViewSet(SingleArtifactContentUploadViewSet):
"effect": "allow",
},
{
"action": ["create"],
"action": ["create", "set_label", "unset_label"],
"principal": "authenticated",
"effect": "allow",
"condition": [
Expand Down
67 changes: 66 additions & 1 deletion pulp_rpm/tests/functional/api/test_crud_content_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
from textwrap import dedent

import pytest
from pulpcore.client.pulp_rpm import RpmModulemdDefaults, RpmModulemd
from pulpcore.client.pulp_rpm import RpmModulemdDefaults, RpmModulemd, SetLabel, UnsetLabel

from pulp_rpm.tests.functional.constants import (
RPM_ADVISORY_CONTENT_NAME,
RPM_KICKSTART_FIXTURE_URL,
RPM_MODULAR_FIXTURE_URL,
RPM_MODULAR_DEFAULTS_CONTENT_NAME,
RPM_MODULAR_MODULES_CONTENT_NAME,
RPM_MODULES_OBSOLETE_CONTENT_NAME,
RPM_PACKAGE_CONTENT_NAME,
RPM_PACKAGE_FILENAME,
RPM_PACKAGE_FILENAME2,
RPM_REPO_METADATA_FIXTURE_URL,
Expand Down Expand Up @@ -91,6 +96,66 @@ def test_crud_content_unit(
assert version.content_summary.added["rpm.package"]["count"] == 1


@pytest.mark.parallel
def test_set_unset_search_labels(
get_content,
init_and_sync,
rpm_advisory_api,
rpm_modulemd_api,
rpm_modulemd_defaults_api,
rpm_modulemd_obsoletes_api,
rpm_package_api,
):
"""
Sync a repository and test the set/unset/search label calls for
content-types which support that.
"""

def _do_test(binding, content_type_name, repo_content, repo_vers):
a_content = binding.read(repo_content["present"][content_type_name][0]["pulp_href"])

# Set label
sl = SetLabel(key="key_1", value="value_1")
binding.set_label(a_content.pulp_href, sl)
a_content = binding.read(a_content.pulp_href)
labels = a_content.pulp_labels
assert "key_1" in labels

# Search for key_1
rslt = binding.list(pulp_label_select="key_1", repository_version=rv)
assert 1 == rslt.count

# Change an existing label
sl = SetLabel(key="key_1", value="XXX")
binding.set_label(a_content.pulp_href, sl)
a_content = binding.read(a_content.pulp_href)
labels = a_content.pulp_labels
assert labels["key_1"] == "XXX"

# Unset a label
sl = UnsetLabel(key="key_1")
binding.unset_label(a_content.pulp_href, sl)
content2 = binding.read(a_content.pulp_href)
assert "key_1" not in content2.pulp_labels

# Set up and sync a repository with the desired content-types
repository, _ = init_and_sync(url=RPM_MODULAR_FIXTURE_URL)
repository_content = get_content(repository)
rv = repository.latest_version_href

# Test set/unset/search for each type-of-content
# We don't do this via pytest-parameterization so that we only sync the repo *once*.
content_type_tuples = [
(rpm_package_api, RPM_PACKAGE_CONTENT_NAME),
(rpm_advisory_api, RPM_ADVISORY_CONTENT_NAME),
(rpm_modulemd_api, RPM_MODULAR_MODULES_CONTENT_NAME),
(rpm_modulemd_defaults_api, RPM_MODULAR_DEFAULTS_CONTENT_NAME),
(rpm_modulemd_obsoletes_api, RPM_MODULES_OBSOLETE_CONTENT_NAME),
]
for t in content_type_tuples:
_do_test(t[0], t[1], repository_content, rv)


@pytest.mark.parallel
@pytest.mark.parametrize(
"url",
Expand Down
9 changes: 8 additions & 1 deletion pulp_rpm/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,14 @@ def test_core_metadata(init_and_sync, rpm_package_api, get_content):
diff = dictdiffer.diff(
package_dict,
RPM_COMPLEX_PACKAGE_DATA,
ignore={"time_file", "pulp_created", "pulp_last_updated", "pulp_href", "prn"},
ignore={
"time_file",
"pulp_created",
"pulp_last_updated",
"pulp_href",
"prn",
"pulp_labels",
},
)
assert list(diff) == [], list(diff)

Expand Down
4 changes: 3 additions & 1 deletion pulp_rpm/tests/functional/api/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ def test_single_request_unit_and_duplicate_unit(
# Single unit upload
file_to_use = os.path.join(RPM_UNSIGNED_FIXTURE_URL, RPM_PACKAGE_FILENAME)

labels = {"key_1": "value_1"}
with NamedTemporaryFile() as file_to_upload:
file_to_upload.write(requests.get(file_to_use).content)
upload_attrs = {"file": file_to_upload.name}
upload_attrs = {"file": file_to_upload.name, "pulp_labels": labels}
upload = rpm_package_api.create(**upload_attrs)

content = monitor_task(upload.task).created_resources[0]
package = rpm_package_api.read(content)
assert package.location_href == RPM_PACKAGE_FILENAME
assert package.pulp_labels == labels

# Duplicate unit
with NamedTemporaryFile() as file_to_upload:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"jsonschema>=4.6,<5.0",
"libcomps>=0.1.20.post1,<0.2",
"productmd~=1.33.0",
"pulpcore>=3.71.0,<3.85",
"pulpcore>=3.73.0,<3.85",
"solv~=0.7.21",
"aiohttp_xmlrpc~=1.5.0",
"importlib-resources~=6.4.0",
Expand Down

0 comments on commit 4a3f7ce

Please # to comment.