Skip to content

Commit

Permalink
Test if a manifest references an artifact when syncing
Browse files Browse the repository at this point in the history
closes #1400
  • Loading branch information
lubosmj committed Oct 30, 2023
1 parent b3ce4e4 commit 7151b1b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES/1400.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed re-sync failures after reclaiming disk space.
4 changes: 3 additions & 1 deletion pulp_container/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ async def create_listed_manifest(self, manifest_data):
)
manifest_url = urljoin(self.remote.url, relative_url)
manifest = await sync_to_async(
Manifest.objects.prefetch_related("contentartifact_set").filter(digest=digest).first
Manifest.objects.prefetch_related("contentartifact_set")
.filter(digest=digest, _artifacts__isnull=False)
.first
)()
if manifest:

Expand Down
45 changes: 35 additions & 10 deletions pulp_container/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
)
from pulp_container.tests.functional.constants import PULP_FIXTURE_1

from pulpcore.client.pulpcore import RepositoriesReclaimSpaceApi

from pulpcore.client.pulp_container import (
ContainerContainerRepository,
ContainerContainerRemote,
Expand All @@ -35,6 +37,10 @@ def setUpClass(cls):
cls.cfg = config.get_config()
cls.client_api = gen_container_client()

cls.repository_api = RepositoriesContainerApi(cls.client_api)
cls.remote_api = RemotesContainerApi(cls.client_api)
cls.reclaim_api = RepositoriesReclaimSpaceApi(cls.client_api)

def test_sync(self):
"""Sync repositories with the container plugin.
Expand All @@ -51,30 +57,49 @@ def test_sync(self):
5. Sync the remote one more time.
6. Assert that repository version is the same from the previous one.
"""
repository_api = RepositoriesContainerApi(self.client_api)
repository = repository_api.create(ContainerContainerRepository(**gen_repo()))
self.addCleanup(repository_api.delete, repository.pulp_href)
repository = self.repository_api.create(ContainerContainerRepository(**gen_repo()))
self.addCleanup(self.repository_api.delete, repository.pulp_href)

remote_api = RemotesContainerApi(self.client_api)
remote = remote_api.create(gen_container_remote())
self.addCleanup(remote_api.delete, remote.pulp_href)
remote = self.remote_api.create(gen_container_remote())
self.addCleanup(self.remote_api.delete, remote.pulp_href)

self.assertEqual(repository.latest_version_href, f"{repository.pulp_href}versions/0/")
repository_sync_data = ContainerRepositorySyncURL(remote=remote.pulp_href)

# Sync the repository.
sync_response = repository_api.sync(repository.pulp_href, repository_sync_data)
sync_response = self.repository_api.sync(repository.pulp_href, repository_sync_data)
monitor_task(sync_response.task)
repository = repository_api.read(repository.pulp_href)
repository = self.repository_api.read(repository.pulp_href)
self.assertIsNotNone(repository.latest_version_href)

# Sync the repository again.
latest_version_href = repository.latest_version_href
sync_response = repository_api.sync(repository.pulp_href, repository_sync_data)
sync_response = self.repository_api.sync(repository.pulp_href, repository_sync_data)
monitor_task(sync_response.task)
repository = repository_api.read(repository.pulp_href)
repository = self.repository_api.read(repository.pulp_href)
self.assertEqual(latest_version_href, repository.latest_version_href)

def test_sync_reclaim(self):
"""Check if re-syncing the content after the reclamation ends with no error."""
repository = self.repository_api.create(ContainerContainerRepository(**gen_repo()))
self.addCleanup(self.repository_api.delete, repository.pulp_href)

remote = self.remote_api.create(gen_container_remote())
self.addCleanup(self.remote_api.delete, remote.pulp_href)

repository_sync_data = ContainerRepositorySyncURL(remote=remote.pulp_href)

# Sync the repository.
sync_response = self.repository_api.sync(repository.pulp_href, repository_sync_data)
monitor_task(sync_response.task)

# Reclaim the space
monitor_task(self.reclaim_api.reclaim({"repo_hrefs": ["*"]}).task)

# Re-sync the reclaimed repository
sync_response = self.repository_api.sync(repository.pulp_href, repository_sync_data)
monitor_task(sync_response.task)


class SyncInvalidURLTestCase(PulpTestCase):
"""Sync a repository with an invalid url on the Remote."""
Expand Down

0 comments on commit 7151b1b

Please sign in to comment.