Skip to content

Commit

Permalink
Add support for repository remotes
Browse files Browse the repository at this point in the history
fixes pulp#101
  • Loading branch information
mdellweg committed Jun 6, 2023
1 parent 797a776 commit 54e2454
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES/101.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support to assign a remote to a repository.
1 change: 1 addition & 0 deletions pulp_gem/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class GemRepository(Repository):

TYPE = "gem"
CONTENT_TYPES = [GemContent]
REMOTE_TYPES = [GemRemote]

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
24 changes: 15 additions & 9 deletions pulp_gem/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,34 @@ class GemRepositoryViewSet(RepositoryViewSet, ModifyRepositoryActionMixin):
queryset = GemRepository.objects.all()
serializer_class = GemRepositorySerializer

# This decorator is necessary since a sync operation is asyncrounous and returns
# the id and href of the sync task.
@extend_schema(
description="Trigger an asynchronous task to sync content.",
summary="Sync from remote",
description="Trigger an asynchronous task to sync gem content.",
summary="Sync from a remote",
responses={202: AsyncOperationResponseSerializer},
)
@action(detail=True, methods=["post"], serializer_class=RepositorySyncURLSerializer)
def sync(self, request, pk):
"""
Dispatches a sync task.
"""
repository = self.get_object()
serializer = RepositorySyncURLSerializer(data=request.data, context={"request": request})
serializer = RepositorySyncURLSerializer(
data=request.data, context={"request": request, "repository_pk": pk}
)
serializer.is_valid(raise_exception=True)
remote = serializer.validated_data.get("remote")

repository = self.get_object()
remote = serializer.validated_data.get("remote", repository.remote)
mirror = serializer.validated_data.get("mirror", True)

result = dispatch(
tasks.synchronize,
exclusive_resources=[repository, remote],
kwargs={"remote_pk": remote.pk, "repository_pk": repository.pk, "mirror": mirror},
shared_resources=[remote],
exclusive_resources=[repository],
kwargs={
"remote_pk": str(remote.pk),
"repository_pk": str(repository.pk),
"mirror": mirror,
},
)
return OperationPostponedResponse(result, request)

Expand Down
18 changes: 15 additions & 3 deletions pulp_gem/tests/functional/api/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ def do_sync(gem_repository_api_client, gem_repository_factory, gem_remote_factor
def _do_sync(repo=None, remote=None, url=GEM_FIXTURE_URL, policy="immediate"):
if repo is None:
repo = gem_repository_factory()
if remote is None:
remote = gem_remote_factory(url=url, policy=policy)

result = gem_repository_api_client.sync(repo.pulp_href, {"remote": remote.pulp_href})
if repo.remote is None:
if remote is None:
remote = gem_remote_factory(url=url, policy=policy)
sync_args = {"remote": remote.pulp_href}
else:
sync_args = {}

result = gem_repository_api_client.sync(repo.pulp_href, sync_args)
monitor_task(result.task)
repo = gem_repository_api_client.read(repo.pulp_href)
return repo, remote
Expand All @@ -33,7 +38,9 @@ def _do_sync(repo=None, remote=None, url=GEM_FIXTURE_URL, policy="immediate"):
def test_download_policies(
download_policy,
do_sync,
gem_repository_api_client,
gem_repository_version_api_client,
monitor_task,
):
"""Sync repositories with the different ``download_policy``.
Expand All @@ -58,6 +65,11 @@ def test_download_policies(
assert added_summary == GEM_FIXTURE_SUMMARY

# Sync the repository again.
update_task = gem_repository_api_client.partial_update(
repo.pulp_href, {"remote": remote.pulp_href}
).task
monitor_task(update_task)
repo = gem_repository_api_client.read(repo.pulp_href)
repo2, _ = do_sync(repo=repo, remote=remote)
assert repo2.latest_version_href == repo.latest_version_href

Expand Down

0 comments on commit 54e2454

Please sign in to comment.