Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request pulp#1568 from pavelpicka/5738-mirror-repo
Browse files Browse the repository at this point in the history
Repository mirror
closes: #6033
https://pulp.plan.io/issues/6033
  • Loading branch information
goosemania authored and pavelpicka committed Feb 12, 2020
2 parents fddc87b + 9713b41 commit afbb107
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/5738.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add mirror mode for sync endpoint.
1 change: 1 addition & 0 deletions CHANGES/6033.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SRPM can be skipped during the sync.
2 changes: 1 addition & 1 deletion docs/_scripts/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Sync repository foo using remote bar
echo "Create a task to sync the repository using the remote."
export TASK_URL=$(http POST $BASE_ADDR$REPO_HREF'sync/' \
remote=$REMOTE_HREF \
remote=$REMOTE_HREF skip:="[\"srpm\"]" \
| jq -r '.task')

# Poll the task (here we use a function defined in docs/_scripts/base.sh)
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/api.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs/workflows/create_sync_publish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,19 @@ Remote GET response:
Sync repository ``foo`` using remote ``bar``
--------------------------------------------

It is possible to skip RPM types by specify list of them in 'skip' parameter.

Supported types to skip are

- SRPM as ``'srpm'``

.. literalinclude:: ../_scripts/sync.sh
:language: bash

You can specify ``mirror=True`` for a mirror mode. It means Pulp won't update
repository using previous repository version but create a new copy of remote
repository as a new repository version.

RepositoryVersion GET response (when sync task complete):

.. code:: json
Expand Down
1 change: 1 addition & 0 deletions pulp_rpm/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
MODULAR_REPODATA = ['modules']
COMPS_REPODATA = ['group']
SKIP_REPODATA = ['group_gz', 'prestodelta']
OPT_SKIP_TYPES = ['srpm']

CR_UPDATE_RECORD_ATTRS = SimpleNamespace(
ID='id',
Expand Down
17 changes: 17 additions & 0 deletions pulp_rpm/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
RelatedField,
RemoteSerializer,
RepositorySerializer,
RepositorySyncURLSerializer,
SingleArtifactContentUploadSerializer,
validate_unknown_fields,
)
Expand All @@ -37,6 +38,7 @@
PULP_UPDATE_RECORD_ATTRS,
PULP_UPDATE_REFERENCE_ATTRS,
PULP_UPDATE_COLLECTION_ATTRS,
OPT_SKIP_TYPES,
CR_UPDATE_REFERENCE_ATTRS
)

Expand Down Expand Up @@ -1103,3 +1105,18 @@ class Meta:
'data_type', 'checksum_type', 'checksum'
)
model = RepoMetadataFile


class RpmRepositorySyncURLSerializer(RepositorySyncURLSerializer):
"""
A serializer for Repository Sync.
"""

skip = serializers.ListField(
help_text=_("List of content types to skip during sync."),
required=False,
default=[],
child=serializers.ChoiceField(
[(name, name) for name in OPT_SKIP_TYPES]
)
)
19 changes: 15 additions & 4 deletions pulp_rpm/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ def repodata_exists(remote, url):
return True


def synchronize(remote_pk, repository_pk):
def synchronize(remote_pk, repository_pk, mirror, skip):
"""
Sync content from the remote repository.
Create a new version of the repository that is synchronized with the remote.
Args:
mirror (bool): Mirror mode
remote_pk (str): The remote PK.
repository_pk (str): The repository PK.
skip (list): List of content types to skip.
Raises:
ValueError: If the remote does not specify a url to sync.
Expand Down Expand Up @@ -144,9 +146,10 @@ def synchronize(remote_pk, repository_pk):
repository=sub_repo)
dv.create()

first_stage = RpmFirstStage(remote, deferred_download, treeinfo=treeinfo)
first_stage = RpmFirstStage(remote, deferred_download, treeinfo=treeinfo, skip=skip)
dv = RpmDeclarativeVersion(first_stage=first_stage,
repository=repository)
repository=repository,
mirror=mirror)
dv.create()


Expand Down Expand Up @@ -189,7 +192,7 @@ class RpmFirstStage(Stage):
that should exist in the new :class:`~pulpcore.plugin.models.RepositoryVersion`.
"""

def __init__(self, remote, deferred_download, new_url=None, treeinfo=None):
def __init__(self, remote, deferred_download, new_url=None, treeinfo=None, skip=None):
"""
The first stage of a pulp_rpm sync pipeline.
Expand All @@ -201,13 +204,15 @@ def __init__(self, remote, deferred_download, new_url=None, treeinfo=None):
Keyword Args:
new_url(str): URL to replace remote url
treeinfo(dict): Treeinfo data
skip(list): List of RPM types to skip
"""
super().__init__()
self.remote = remote
self.deferred_download = deferred_download
self.new_url = new_url
self.treeinfo = treeinfo
self.skip = skip

@staticmethod
async def parse_updateinfo(updateinfo_xml_path):
Expand Down Expand Up @@ -586,6 +591,12 @@ async def run(self):
filelists_xml_path,
other_xml_path)

# avoid SRPM if defined by user
if 'srpm' in self.skip:
packages = {
pkgId: pkg for pkgId, pkg in packages.items() if pkg.arch != 'src'
}

progress_data = {
'message': 'Parsed Packages',
'code': 'parsing.packages',
Expand Down
9 changes: 7 additions & 2 deletions pulp_rpm/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
RpmDistributionSerializer,
RpmRemoteSerializer,
RpmRepositorySerializer,
RpmRepositorySyncURLSerializer,
RpmPublicationSerializer,
UpdateRecordSerializer,
)
Expand Down Expand Up @@ -115,19 +116,23 @@ def sync(self, request, pk):
Dispatches a sync task.
"""
repository = self.get_object()
serializer = RepositorySyncURLSerializer(
serializer = RpmRepositorySyncURLSerializer(
data=request.data,
context={'request': request}
)
serializer.is_valid(raise_exception=True)
remote = serializer.validated_data.get('remote')
mirror = serializer.validated_data.get('mirror')
skip = serializer.validated_data.get('skip')

result = enqueue_with_reservation(
tasks.synchronize,
[repository, remote],
kwargs={
'mirror': mirror,
'remote_pk': remote.pk,
'repository_pk': repository.pk
'repository_pk': repository.pk,
'skip': skip
}
)
return OperationPostponedResponse(result, request)
Expand Down

0 comments on commit afbb107

Please sign in to comment.