-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update remote artifact urls on sync if the url of the artifact has changed #1623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed an issue where on_demand content might not be downloaded properly if the remote URL was changed (even if re-synced). | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,13 +276,11 @@ async def run(self): | |
The coroutine for this stage. | ||
""" | ||
async for batch in self.batches(): | ||
await sync_to_async(RemoteArtifact.objects.bulk_get_or_create)( | ||
await self._needed_remote_artifacts(batch) | ||
) | ||
await self._handle_remote_artifacts(batch) | ||
for d_content in batch: | ||
await self.put(d_content) | ||
|
||
async def _needed_remote_artifacts(self, batch): | ||
async def _handle_remote_artifacts(self, batch): | ||
""" | ||
Build a list of only :class:`~pulpcore.plugin.models.RemoteArtifact` that need | ||
to be created for the batch. | ||
|
@@ -318,7 +316,8 @@ async def _needed_remote_artifacts(self, batch): | |
# | ||
# We can end up with duplicates (diff pks, same sha256) in the sequence below, | ||
# so we store by-sha256 and then return the final values | ||
needed_ras = {} # { str(<sha256>): RemoteArtifact, ... } | ||
ras_to_create = {} # { str(<sha256>): RemoteArtifact, ... } | ||
ras_to_update = {} | ||
for d_content in batch: | ||
for d_artifact in d_content.d_artifacts: | ||
if not d_artifact.remote: | ||
|
@@ -379,14 +378,25 @@ async def _needed_remote_artifacts(self, batch): | |
async for remote_artifact in sync_to_async_iterable( | ||
content_artifact._remote_artifact_saver_ras | ||
): | ||
if remote_artifact.remote_id == d_artifact.remote.pk: | ||
if d_artifact.url == remote_artifact.url: | ||
break | ||
|
||
if d_artifact.remote.pk == remote_artifact.remote_id: | ||
key = f"{content_artifact.pk}-{remote_artifact.remote_id}" | ||
remote_artifact.url = d_artifact.url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TL;DR: If the relative path of the artifact within the repo has changed, or if the base path of the repo has changed, we update the RemoteArtifact to match the new URL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some specific examples on how this problem can affect plugins:
I'd prefer to change uniqueness constraint of the RemoteArtifact so it also contains the |
||
ras_to_update[key] = remote_artifact | ||
break | ||
else: | ||
remote_artifact = self._create_remote_artifact(d_artifact, content_artifact) | ||
key = f"{str(content_artifact.pk)}-{str(d_artifact.remote.pk)}" | ||
needed_ras[key] = remote_artifact | ||
|
||
return list(needed_ras.values()) | ||
dralley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
key = f"{content_artifact.pk}-{d_artifact.remote.pk}" | ||
ras_to_create[key] = remote_artifact | ||
|
||
if ras_to_create: | ||
await sync_to_async(RemoteArtifact.objects.bulk_create)(list(ras_to_create.values())) | ||
if ras_to_update: | ||
await sync_to_async(RemoteArtifact.objects.bulk_update)( | ||
list(ras_to_update.values()), fields=["url"] | ||
) | ||
|
||
@staticmethod | ||
def _create_remote_artifact(d_artifact, content_artifact): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can we write an automated test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we had a pulp_file fixture that had a different layout but the same content we could test this by:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we cannot, because a change to the layout would yield a different set of content, because
relative_path
is part of it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bmbouter Test added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! +1