Skip to content

Commit b28d107

Browse files
committed
Added set/unset_label support to pkg/updaterecord/modulemd* views.
closes pulp#3896.
1 parent bcd4cf5 commit b28d107

File tree

7 files changed

+83
-8
lines changed

7 files changed

+83
-8
lines changed

CHANGES/3896.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Added permissions for set/unset_label on RPM content-types.
2+
3+
The types that support this new call include:
4+
* Package
5+
* UpdateRecord
6+
* Modulemd
7+
* ModulemdDefaults
8+
* ModulemdObsoletes

pulp_rpm/app/viewsets/advisory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class UpdateRecordViewSet(NoArtifactContentUploadViewSet):
5353
"effect": "allow",
5454
},
5555
{
56-
"action": ["create"],
56+
"action": ["create", "set_label", "unset_label"],
5757
"principal": "authenticated",
5858
"effect": "allow",
5959
"condition": [

pulp_rpm/app/viewsets/modulemd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ModulemdViewSet(SingleArtifactContentUploadViewSet):
5353
"effect": "allow",
5454
},
5555
{
56-
"action": ["create"],
56+
"action": ["create", "set_label", "unset_label"],
5757
"principal": "authenticated",
5858
"effect": "allow",
5959
"condition": [
@@ -99,7 +99,7 @@ class ModulemdDefaultsViewSet(SingleArtifactContentUploadViewSet):
9999
"effect": "allow",
100100
},
101101
{
102-
"action": ["create"],
102+
"action": ["create", "set_label", "unset_label"],
103103
"principal": "authenticated",
104104
"effect": "allow",
105105
"condition": [
@@ -129,7 +129,7 @@ class ModulemdObsoleteViewSet(SingleArtifactContentUploadViewSet):
129129
"effect": "allow",
130130
},
131131
{
132-
"action": ["create"],
132+
"action": ["create", "set_label", "unset_label"],
133133
"principal": "authenticated",
134134
"effect": "allow",
135135
},

pulp_rpm/app/viewsets/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PackageViewSet(SingleArtifactContentUploadViewSet):
6060
"effect": "allow",
6161
},
6262
{
63-
"action": ["create"],
63+
"action": ["create", "set_label", "unset_label"],
6464
"principal": "authenticated",
6565
"effect": "allow",
6666
"condition": [

pulp_rpm/tests/functional/api/test_crud_content_unit.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
from textwrap import dedent
44

55
import pytest
6-
from pulpcore.client.pulp_rpm import RpmModulemdDefaults, RpmModulemd
6+
from pulpcore.client.pulp_rpm import RpmModulemdDefaults, RpmModulemd, SetLabel, UnsetLabel
77

88
from pulp_rpm.tests.functional.constants import (
9+
RPM_ADVISORY_CONTENT_NAME,
910
RPM_KICKSTART_FIXTURE_URL,
1011
RPM_MODULAR_FIXTURE_URL,
12+
RPM_MODULAR_DEFAULTS_CONTENT_NAME,
13+
RPM_MODULAR_MODULES_CONTENT_NAME,
14+
RPM_MODULES_OBSOLETE_CONTENT_NAME,
15+
RPM_PACKAGE_CONTENT_NAME,
1116
RPM_PACKAGE_FILENAME,
1217
RPM_PACKAGE_FILENAME2,
1318
RPM_REPO_METADATA_FIXTURE_URL,
@@ -91,6 +96,66 @@ def test_crud_content_unit(
9196
assert version.content_summary.added["rpm.package"]["count"] == 1
9297

9398

99+
@pytest.mark.parallel
100+
def test_set_unset_search_labels(
101+
get_content,
102+
init_and_sync,
103+
rpm_advisory_api,
104+
rpm_modulemd_api,
105+
rpm_modulemd_defaults_api,
106+
rpm_modulemd_obsoletes_api,
107+
rpm_package_api,
108+
):
109+
"""
110+
Sync a repository and test the set/unset/search label calls for
111+
content-types which support that.
112+
"""
113+
114+
def _do_test(binding, content_type_name, repo_content, repo_vers):
115+
a_content = binding.read(repo_content["present"][content_type_name][0]["pulp_href"])
116+
117+
# Set label
118+
sl = SetLabel(key="key_1", value="value_1")
119+
binding.set_label(a_content.pulp_href, sl)
120+
a_content = binding.read(a_content.pulp_href)
121+
labels = a_content.pulp_labels
122+
assert "key_1" in labels
123+
124+
# Search for key_1
125+
rslt = binding.list(pulp_label_select="key_1", repository_version=rv)
126+
assert 1 == rslt.count
127+
128+
# Change an existing label
129+
sl = SetLabel(key="key_1", value="XXX")
130+
binding.set_label(a_content.pulp_href, sl)
131+
a_content = binding.read(a_content.pulp_href)
132+
labels = a_content.pulp_labels
133+
assert labels["key_1"] == "XXX"
134+
135+
# Unset a label
136+
sl = UnsetLabel(key="key_1")
137+
binding.unset_label(a_content.pulp_href, sl)
138+
content2 = binding.read(a_content.pulp_href)
139+
assert "key_1" not in content2.pulp_labels
140+
141+
# Set up and sync a repository with the desired content-types
142+
repository, _ = init_and_sync(url=RPM_MODULAR_FIXTURE_URL)
143+
repository_content = get_content(repository)
144+
rv = repository.latest_version_href
145+
146+
# Test set/unset/search for each type-of-content
147+
# We don't do this via pytest-parameterization so that we only sync the repo *once*.
148+
content_type_tuples = [
149+
(rpm_package_api, RPM_PACKAGE_CONTENT_NAME),
150+
(rpm_advisory_api, RPM_ADVISORY_CONTENT_NAME),
151+
(rpm_modulemd_api, RPM_MODULAR_MODULES_CONTENT_NAME),
152+
(rpm_modulemd_defaults_api, RPM_MODULAR_DEFAULTS_CONTENT_NAME),
153+
(rpm_modulemd_obsoletes_api, RPM_MODULES_OBSOLETE_CONTENT_NAME),
154+
]
155+
for t in content_type_tuples:
156+
_do_test(t[0], t[1], repository_content, rv)
157+
158+
94159
@pytest.mark.parallel
95160
@pytest.mark.parametrize(
96161
"url",

pulp_rpm/tests/functional/api/test_upload.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ def test_single_request_unit_and_duplicate_unit(
4242
# Single unit upload
4343
file_to_use = os.path.join(RPM_UNSIGNED_FIXTURE_URL, RPM_PACKAGE_FILENAME)
4444

45+
labels = {"key_1": "value_1"}
4546
with NamedTemporaryFile() as file_to_upload:
4647
file_to_upload.write(requests.get(file_to_use).content)
47-
upload_attrs = {"file": file_to_upload.name}
48+
upload_attrs = {"file": file_to_upload.name, "pulp_labels": labels}
4849
upload = rpm_package_api.create(**upload_attrs)
4950

5051
content = monitor_task(upload.task).created_resources[0]
5152
package = rpm_package_api.read(content)
5253
assert package.location_href == RPM_PACKAGE_FILENAME
54+
assert package.pulp_labels == labels
5355

5456
# Duplicate unit
5557
with NamedTemporaryFile() as file_to_upload:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"jsonschema>=4.6,<5.0",
3333
"libcomps>=0.1.20.post1,<0.2",
3434
"productmd~=1.33.0",
35-
"pulpcore>=3.71.0,<3.85",
35+
"pulpcore>=3.73.0,<3.85",
3636
"solv~=0.7.21",
3737
"aiohttp_xmlrpc~=1.5.0",
3838
"importlib-resources~=6.4.0",

0 commit comments

Comments
 (0)