From e7f433bf5cacd6c6d81d42a71067df23d7f22c3c Mon Sep 17 00:00:00 2001 From: Lubos Mjachky Date: Wed, 29 Jun 2022 17:28:42 +0200 Subject: [PATCH] Do not create tags for manifests when pushing by digest closes #852 --- CHANGES/852.bugfix | 1 + pulp_container/app/registry_api.py | 30 ++++++++++++------- .../tests/functional/api/test_push_content.py | 12 ++++++-- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 CHANGES/852.bugfix diff --git a/CHANGES/852.bugfix b/CHANGES/852.bugfix new file mode 100644 index 000000000..dce1d8845 --- /dev/null +++ b/CHANGES/852.bugfix @@ -0,0 +1 @@ +Fixed a bug that caused untagged manifests to be tagged by their digest during the push operation. diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index 2685daf94..cc9215211 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -988,23 +988,31 @@ def put(self, request, path, pk=None): objs=thru, ignore_conflicts=True, batch_size=1000 ) - tag = models.Tag(name=pk, tagged_manifest=manifest) - try: - tag.save() - except IntegrityError: - tag = models.Tag.objects.get(name=tag.name, tagged_manifest=manifest) - tag.touch() + # a manifest cannot tagged by its digest - an identifier specified in the 'pk' parameter + if not pk.startswith("sha256:"): + tag = models.Tag(name=pk, tagged_manifest=manifest) + try: + tag.save() + except IntegrityError: + tag = models.Tag.objects.get(name=tag.name, tagged_manifest=manifest) + tag.touch() + + tags_to_remove = models.Tag.objects.filter( + pk__in=repository.latest_version().content.all(), name=tag + ).exclude(tagged_manifest=manifest) + add_content_units = [str(tag.pk), str(manifest.pk)] + remove_content_units = [str(pk) for pk in tags_to_remove.values_list("pk")] + else: + add_content_units = [str(manifest.pk)] + remove_content_units = [] - tags_to_remove = models.Tag.objects.filter( - pk__in=repository.latest_version().content.all(), name=tag - ).exclude(tagged_manifest=manifest) dispatched_task = dispatch( add_and_remove, exclusive_resources=[repository], kwargs={ "repository_pk": str(repository.pk), - "add_content_units": [str(tag.pk), str(manifest.pk)], - "remove_content_units": [str(pk) for pk in tags_to_remove.values_list("pk")], + "add_content_units": add_content_units, + "remove_content_units": remove_content_units, }, ) diff --git a/pulp_container/tests/functional/api/test_push_content.py b/pulp_container/tests/functional/api/test_push_content.py index 0ad6ec905..9f18f6e3f 100644 --- a/pulp_container/tests/functional/api/test_push_content.py +++ b/pulp_container/tests/functional/api/test_push_content.py @@ -453,7 +453,11 @@ def test_push_manifest_list_v2s2(self): self.addCleanup(self.distributions_api.delete, distribution.pulp_href) repo_version = self.pushrepository_api.read(distribution.repository).latest_version_href - latest_tag = self.tags_api.list(repository_version_added=repo_version).results[0] + + tags = self.tags_api.list(repository_version=repo_version).results + assert len(tags) == 1 + + latest_tag = tags[0] assert latest_tag.name == self.v2s2_tag manifest_list = self.manifests_api.read(latest_tag.tagged_manifest) @@ -500,7 +504,11 @@ def test_push_manifest_list_oci(self): self.addCleanup(self.distributions_api.delete, distribution.pulp_href) repo_version = self.pushrepository_api.read(distribution.repository).latest_version_href - latest_tag = self.tags_api.list(repository_version_added=repo_version).results[0] + + tags = self.tags_api.list(repository_version=repo_version).results + assert len(tags) == 1 + + latest_tag = tags[0] assert latest_tag.name == self.oci_tag manifest_list = self.manifests_api.read(latest_tag.tagged_manifest)