Skip to content

Commit 9142c61

Browse files
committed
Add files attribute to RpmUnit [RHELDST-21555]
This commit adds an attribute, files, to RpmUnit which maps to the 'files.file' pulp field and holds a list of files provided by the RPM. The immediate use case for this is in ubi-manifest to identify available files which may match those listed as dependencies, avoiding unnecessary pulp searches.
1 parent a38c822 commit 9142c61

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

pubtools/pulplib/_impl/model/unit/rpm.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import datetime
22

33
from pubtools.pulplib._impl.model.validate import optional_list_of
4-
from .base import Unit, unit_type
54

6-
from ..attr import pulp_attrib
7-
from ..common import schemaless_init
85
from ... import compat_attr as attr
6+
from ..attr import pulp_attrib
7+
from ..common import PulpObject, schemaless_init
98
from ..convert import (
109
frozenlist_or_none_converter,
1110
frozenlist_or_none_sorted_converter,
12-
tolerant_timestamp,
1311
timestamp_converter,
12+
tolerant_timestamp,
1413
)
15-
from ..validate import optional_str, instance_of
16-
from ..common import PulpObject
14+
from ..validate import instance_of, optional_str
15+
from .base import Unit, unit_type
1716

1817

1918
@attr.s(kw_only=True, frozen=True)
@@ -238,6 +237,17 @@ class RpmUnit(Unit):
238237
List of capabilities that this RPM provides or ``None`` if this information is unavailable.
239238
"""
240239

240+
files = pulp_attrib(
241+
default=None,
242+
type=list,
243+
converter=frozenlist_or_none_converter,
244+
pulp_field="files.file",
245+
validator=optional_list_of(str),
246+
)
247+
"""
248+
List of files that this RPM provides or ``None`` if this information is unavailable.
249+
"""
250+
241251
@md5sum.validator
242252
def _check_md5(self, _, value):
243253
self._check_sum(value, "MD5", 32)

tests/unit/test_rpm_deps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def test_rpm_requires_provides():
2929
"release": "1",
3030
"epoch": "0",
3131
"flags": "LT",
32-
}
32+
},
33+
# We should also expect inclusion of files/scriptlets in requires.
34+
{
35+
"name": "/some/script.sh",
36+
},
3337
],
3438
}
3539
)
@@ -42,10 +46,12 @@ def test_rpm_requires_provides():
4246
provides_item.epoch == "0"
4347
provides_item.flags == "EQ"
4448

45-
assert len(unit.requires) == 1
49+
assert len(unit.requires) == 2
4650
requires_item = unit.requires[0]
4751
requires_item.name == "test-requires"
4852
requires_item.version == "1.0"
4953
requires_item.release == "1"
5054
requires_item.epoch == "0"
5155
requires_item.flags == "LT"
56+
requires_item = unit.requires[1]
57+
requires_item.name == "/some/script.sh"

tests/unit/test_rpm_unit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def test_user_metadata_fields():
1919
"cdn_path": "/some/path/to/my.rpm",
2020
"cdn_published": "2021-04-01T01:08:26",
2121
},
22+
"files": {
23+
"file": [
24+
"/usr/bin/some/script.sh",
25+
"/usr/bin/another/script/provided.py",
26+
],
27+
},
2228
}
2329
)
2430

@@ -32,6 +38,7 @@ def test_user_metadata_fields():
3238
content_type_id="rpm",
3339
cdn_path="/some/path/to/my.rpm",
3440
cdn_published=datetime.datetime(2021, 4, 1, 1, 8, 26),
41+
files=["/usr/bin/some/script.sh", "/usr/bin/another/script/provided.py"],
3542
)
3643

3744

0 commit comments

Comments
 (0)