Skip to content

Commit

Permalink
Add lazy sync support
Browse files Browse the repository at this point in the history
Add support for lazy download policies

Update _gen_verbose_remote to add download policy field. Add constant
DOWNLOAD_POLICIES.

closes #4212
https://pulp.plan.io/issues/4212

re #4182
https://pulp.plan.io/issues/4182
  • Loading branch information
dralley committed Jan 18, 2019
1 parent 08caeb4 commit 9590647
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 2 additions & 3 deletions docs/workflows/create_sync_publish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create a repository ``foo``
Create a new remote ``bar``
---------------------------

``$ http POST http://localhost:8000/pulp/api/v3/remotes/rpm/ name='bar' url='https://repos.fedorapeople.org/pulp/pulp/fixtures/rpm-unsigned/'``
``$ http POST http://localhost:8000/pulp/api/v3/remotes/rpm/ name='bar' url='https://repos.fedorapeople.org/pulp/pulp/fixtures/rpm-unsigned/' policy='on_demand'``

.. code:: json
Expand All @@ -30,8 +30,7 @@ Create a new remote ``bar``
...
}
``$ export REMOTE_HREF=$(http :8000/pulp/api/v3/remotes/rpm/ | jq -r '.results[] | select(.name ==
"bar") | ._href')``
``$ export REMOTE_HREF=$(http :8000/pulp/api/v3/remotes/rpm/ | jq -r '.results[] | select(.name == "bar") | ._href')``

Sync repository ``foo`` using remote ``bar``
--------------------------------------------
Expand Down
19 changes: 12 additions & 7 deletions pulp_rpm/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import createrepo_c as cr

from pulpcore.plugin.models import Artifact, ProgressBar, Repository, RepositoryVersion
from pulpcore.plugin.models import Artifact, ProgressBar, Remote, Repository, RepositoryVersion
from pulpcore.plugin.stages import (
DeclarativeArtifact,
DeclarativeContent,
Expand Down Expand Up @@ -59,17 +59,21 @@ def synchronize(remote_pk, repository_pk):
log.info(_('Synchronizing: repository={r} remote={p}').format(
r=repository.name, p=remote.name))

download_artifacts = (remote.policy == Remote.IMMEDIATE)
first_stage = RpmFirstStage(remote)
with WorkingDirectory():
with RepositoryVersion.create(repository) as new_version:
loop = asyncio.get_event_loop()
remove_duplicates_stage = RemoveDuplicates(new_version, **dupe_criteria)
stages = [
first_stage,
QueryExistingArtifacts(), ArtifactDownloader(), ArtifactSaver(),
stages = [first_stage]

if download_artifacts:
stages.extend([QueryExistingArtifacts(), ArtifactDownloader(), ArtifactSaver()])

stages.extend([
QueryExistingContentUnits(), ErratumContentUnitSaver(), remove_duplicates_stage,
ContentUnitAssociation(new_version), EndStage()
]
])
pipeline = create_pipeline(stages)
loop.run_until_complete(pipeline)

Expand Down Expand Up @@ -192,8 +196,9 @@ async def __call__(self, in_q, out_q):
"""
with ProgressBar(message='Downloading and Parsing Metadata') as pb:
downloader = self.remote.get_downloader(url=urljoin(self.remote.url,
'repodata/repomd.xml'))
downloader = self.remote.get_downloader(
url=urljoin(self.remote.url, 'repodata/repomd.xml')
)
# TODO: decide how to distinguish between a mirror list and a normal repo
result = await downloader.run()
pb.increment()
Expand Down
2 changes: 2 additions & 0 deletions pulp_rpm/tests/functional/api/test_crud_remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from requests.exceptions import HTTPError

from pulp_smash import api, config, utils
from pulp_smash.pulp3.constants import DOWNLOAD_POLICIES

from pulp_rpm.tests.functional.constants import RPM_REMOTE_PATH
from pulp_rpm.tests.functional.utils import gen_rpm_remote, skip_if
Expand Down Expand Up @@ -126,6 +127,7 @@ def _gen_verbose_remote():
attrs.update({
'password': utils.uuid4(),
'username': utils.uuid4(),
'policy': choice(DOWNLOAD_POLICIES),
'validate': choice((False, True)),
})
return attrs

0 comments on commit 9590647

Please sign in to comment.