Skip to content

Update remote artifact urls on sync if the url of the artifact has changed - #1623

Merged
dralley merged 1 commit into
pulp:masterfrom
dralley:fix-remote-artifact-update
Sep 22, 2021
Merged

dralley merged 1 commit into
pulp:masterfrom
dralley:fix-remote-artifact-update

Conversation

@dralley

@dralley dralley commented Sep 15, 2021

Copy link
Copy Markdown
Contributor

@dralley

dralley commented Sep 15, 2021

Copy link
Copy Markdown
Contributor Author

Discussion needed: https://pulp.plan.io/issues/9395#note-6

@dralley dralley changed the title Update remote artifact urls on sync if the remote or repo changes Update remote artifact urls on sync if the url of the artifact has changed Sep 15, 2021
@dralley
dralley force-pushed the fix-remote-artifact-update branch from c165188 to 36c6d6e Compare September 15, 2021 04:48
@pulpbot

pulpbot commented Sep 15, 2021

Copy link
Copy Markdown
Member

Attached issue: https://pulp.plan.io/issues/9395


if d_artifact.remote.pk == remote_artifact.remote_id:
key = f"{str(content_artifact.pk)}-{str(d_artifact.remote.pk)}"
remote_artifact.url = d_artifact.url

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

@ipanova ipanova Sep 20, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some specific examples on how this problem can affect plugins:

  1. RPM plugin: part of the remote_artifact.url is composed of location_href which is specified in the repodata. It might happen so that it will change in the remote repo , and with the next sync no new RemoteArtifacts will be created because of uniqueness constraint and old RemoteArtifacts would point to an invalid url and as a result user will get 404.
  2. File plugin: create and sync a local_repoA with on_demand policy from https://remote.repos.com/repoA/PULP_MANIFEST. Then update remote.url to point to https://remote.repos.com/exact_copy_of_repoA/PULP_MANIFEST. Imagine that remote.repos.com/repoA. has been removed/broken and only remote.repos.com/exact_copy_of_repoA is left. Re-sync local_repoA. Users will get 404 afterwards because remote_artifact.url will still point to old unavailable url and not new remote_artifacts would be created.
  3. Container plugin: similar to file plugin workflow just the url to the registry would change

I'd prefer to change uniqueness constraint of the RemoteArtifact so it also contains the url in addition to content_artifact and remote however due to outlined by @dralley reasons that this would not be backportable taken by him approach makes sense.

Comment thread pulpcore/plugin/stages/artifact_stages.py
@dralley
dralley marked this pull request as ready for review September 17, 2021 16:36
@mdellweg
mdellweg self-requested a review September 21, 2021 13:29
Comment thread pulpcore/plugin/stages/artifact_stages.py Outdated
break

if d_artifact.remote.pk == remote_artifact.remote_id:
key = f"{str(content_artifact.pk)}-{str(d_artifact.remote.pk)}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that key? The only use of it i see is as a key for the dictionary. So it imposes some uniqueness.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I feel like it shouldn't be necessary if everything is working correctly and there are no duplicates, but at this stage I'm biased towards caution and I don't know if there are any scenarios where duplicates might be expected.

@dralley
dralley force-pushed the fix-remote-artifact-update branch from 36c6d6e to 718d12d Compare September 21, 2021 14:25
Comment thread pulpcore/plugin/stages/artifact_stages.py Outdated
Comment thread CHANGES/9395.bugfix
@@ -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).

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member

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:

  1. sync one of the fixtures with on_demand
  2. change the remote.url to the other fixture
  3. observe the 404
  4. sync
  5. observe the 404's go away

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmbouter Test added

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! +1

@dralley
dralley force-pushed the fix-remote-artifact-update branch from 718d12d to 28f4ad3 Compare September 22, 2021 02:29
@dralley
dralley force-pushed the fix-remote-artifact-update branch from 28f4ad3 to ab74c2a Compare September 22, 2021 02:35

@mdellweg mdellweg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concerns have been addressed.

@ipanova ipanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the test!

@dralley
dralley merged commit 489156e into pulp:master Sep 22, 2021
@dralley
dralley deleted the fix-remote-artifact-update branch September 22, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants