Skip to content

Commit

Permalink
Deprecate / phase out use of the is_modular field from the Package model
Browse files Browse the repository at this point in the history
closes #3524
  • Loading branch information
dralley committed May 21, 2024
1 parent a1fae15 commit f109047
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGES/3524.deprecation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate and start phasing out the is_modular flag on Packages - it's not a reliable source of information.
13 changes: 2 additions & 11 deletions pulp_rpm/app/depsolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,9 @@ def _load_from_version(self, repo_version, as_target=False):
"pk"
)

nonmodular_rpms = models.Package.objects.filter(
pk__in=package_ids, is_modular=False
).values(*RPM_FIELDS)
packages = models.Package.objects.filter(pk__in=package_ids).values(*RPM_FIELDS)

for rpm in nonmodular_rpms.iterator(chunk_size=5000):
self._add_unit_to_solver(rpm_to_solvable, rpm, repo, libsolv_repo_name)

modular_rpms = models.Package.objects.filter(pk__in=package_ids, is_modular=True).values(
*RPM_FIELDS
)

for rpm in modular_rpms.iterator(chunk_size=5000):
for rpm in packages.iterator(chunk_size=5000):
self._add_unit_to_solver(rpm_to_solvable, rpm, repo, libsolv_repo_name)

# Load modules into the solver
Expand Down
4 changes: 2 additions & 2 deletions pulp_rpm/app/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Package(Content):
rpm_header_end (BigInteger):
Last byte of the header
is_modular (Bool):
Flag to identify if the package is modular
DEPRECATED: Flag to identify if the package is modular
size_archive (BigInteger):
Size, in bytes, of the archive portion of the original package file
Expand Down Expand Up @@ -229,7 +229,7 @@ class Package(Content):
time_build = models.BigIntegerField(null=True)
time_file = models.BigIntegerField(null=True)

# not part of createrepo_c metadata
# not part of createrepo_c metadata - DEPRECATED
is_modular = models.BooleanField(default=False)

# createrepo_c treats 'nosrc' arch (opensuse specific use) as 'src' so it can seem that two
Expand Down
30 changes: 13 additions & 17 deletions pulp_rpm/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,25 +435,21 @@ def _apply_retention_policy(self, new_version):
), "Cannot apply retention policy to completed repository versions"

if self.retain_package_versions > 0:
# It would be more ideal if, instead of annotating with an age and filtering manually,
# we could use Django to filter the particular Package content we want to delete.
# Something like ".filter(F('age') > self.retain_package_versions)" would be better
# however this is not currently possible with Django. It would be possible with raw
# SQL but the repository version content membership subquery is currently
# django-managed and would be difficult to share.
#
# Instead we have to do the filtering manually.
nonmodular_packages = (
Package.objects.with_age()
.filter(
pk__in=new_version.content.filter(pulp_type=Package.get_pulp_type()),
is_modular=False, # don't want to filter out modular RPMs
)
.only("pk")
)
# This code is likely not as efficient as it could / should be, but it is heavily
# complicated by the lack of a reliable means to determine whether a package is
# modular or not via SQL
packages = new_version.content.filter(pulp_type=Package.get_pulp_type())
modules = new_version.content.filter(pulp_type=Modulemd.get_pulp_type())

modular_packages = set()
for module in Modulemd.objects.filter(pk__in=modules):
modular_packages.update(module.packages.all().values_list("pk", flat=True))

nonmodular_packages = set(packages.values_list("pk", flat=True)) - modular_packages
nonmodular_packages = Package.objects.filter(pk__in=nonmodular_packages)

old_packages = []
for package in nonmodular_packages:
for package in nonmodular_packages.with_age().iterator().only("pk", "age"):
if package.age > self.retain_package_versions:
old_packages.append(package.pk)

Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/serializers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class PackageSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSe
read_only=True,
)
is_modular = serializers.BooleanField(
help_text=_("Flag to identify if the package is modular"),
help_text=_("DEPRECATED: Flag to identify if the package is modular"),
required=False,
read_only=True,
)
Expand Down
1 change: 0 additions & 1 deletion pulp_rpm/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,6 @@ def verification_and_skip_callback(pkg):

# find if a package relates to a modulemd
if dc.content.nevra in self.nevra_to_module.keys():
dc.content.is_modular = True
for dc_modulemd in self.nevra_to_module[dc.content.nevra]:
dc.extra_data["modulemd_relation"].append(dc_modulemd)
dc_modulemd.extra_data["package_relation"].append(dc)
Expand Down
8 changes: 0 additions & 8 deletions pulp_rpm/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,6 @@ def test_core_metadata(init_and_sync, rpm_package_api):
)
assert list(diff) == [], list(diff)

# assert no package is marked modular
for pkg in get_content(repository.to_dict())[RPM_PACKAGE_CONTENT_NAME]:
assert pkg["is_modular"] is False


@pytest.mark.parallel
def test_treeinfo_metadata(init_and_sync, rpm_content_distribution_trees_api):
Expand Down Expand Up @@ -1045,10 +1041,6 @@ def module_obsolete_key(m):
diff = dictdiffer.diff(m1, m2, ignore={"pulp_created", "pulp_href"})
assert list(diff) == [], list(diff)

# assert all package from modular repo is marked as modular
for pkg in get_content(repository.to_dict())[RPM_PACKAGE_CONTENT_NAME]:
assert pkg["is_modular"] is True


@pytest.mark.parallel
def test_additive_mode(init_and_sync):
Expand Down

0 comments on commit f109047

Please sign in to comment.