-
Notifications
You must be signed in to change notification settings - Fork 143
Add sync optimization support to pulp_file #7553
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add backend support for sync-optimization for the file plugin | ||
|
|
||
| We can't actually use it yet due to zero-downtime upgrade restrictions |
16 changes: 16 additions & 0 deletions
16
pulp_file/app/migrations/0020_filerepository_last_sync_details.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("file", "0019_add_filegitremote"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="filerepository", | ||
| name="last_sync_details", | ||
| field=models.JSONField(default=dict), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| FILE_SYNC_OPTIMIZATION = True | ||
ggainey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| from pulp_file.app.tasks.synchronizing import _should_optimize_sync | ||
|
|
||
|
|
||
| class TestShouldOptimizeSync: | ||
| """Tests for the _should_optimize_sync function.""" | ||
|
|
||
| BASE_DETAILS = { | ||
| "remote_pk": "00000000-0000-0000-0000-000000000001", | ||
| "url": "http://example.com/PULP_MANIFEST", | ||
| "download_policy": "on_demand", | ||
| "mirror": False, | ||
| "most_recent_version": 1, | ||
| "manifest_checksum": "abc123", | ||
| } | ||
|
|
||
| def _details(self, **overrides): | ||
| d = self.BASE_DETAILS.copy() | ||
| d.update(overrides) | ||
| return d | ||
|
|
||
| def test_no_previous_sync(self): | ||
| """First sync should never be skipped.""" | ||
| assert _should_optimize_sync(self._details(), {}) is False | ||
|
|
||
| def test_identical_sync(self): | ||
| """Sync with identical details should be skipped.""" | ||
| assert _should_optimize_sync(self._details(), self._details()) is True | ||
|
|
||
| def test_manifest_checksum_changed(self): | ||
| """Sync should not be skipped if the manifest checksum changed.""" | ||
| last = self._details() | ||
| current = self._details(manifest_checksum="def456") | ||
| assert _should_optimize_sync(current, last) is False | ||
|
|
||
| def test_url_changed(self): | ||
| """Sync should not be skipped if the remote URL changed.""" | ||
| last = self._details() | ||
| current = self._details(url="http://other.com/PULP_MANIFEST") | ||
| assert _should_optimize_sync(current, last) is False | ||
|
|
||
| def test_repository_modified(self): | ||
| """Sync should not be skipped if the repository was modified since last sync.""" | ||
| last = self._details(most_recent_version=1) | ||
| current = self._details(most_recent_version=2) | ||
| assert _should_optimize_sync(current, last) is False | ||
|
|
||
| def test_download_policy_to_immediate(self): | ||
| """Sync should not be skipped when switching from deferred to immediate.""" | ||
| last = self._details(download_policy="on_demand") | ||
| current = self._details(download_policy="immediate") | ||
| assert _should_optimize_sync(current, last) is False | ||
|
|
||
| def test_download_policy_immediate_to_on_demand(self): | ||
| """Switching from immediate to on_demand does not require re-sync.""" | ||
| last = self._details(download_policy="immediate") | ||
| current = self._details(download_policy="on_demand") | ||
| assert _should_optimize_sync(current, last) is True | ||
|
|
||
| def test_download_policy_stays_immediate(self): | ||
| """Staying on immediate should allow optimization.""" | ||
| last = self._details(download_policy="immediate") | ||
| current = self._details(download_policy="immediate") | ||
| assert _should_optimize_sync(current, last) is True | ||
|
|
||
| def test_mirror_enabled(self): | ||
| """Sync should not be skipped when switching to mirror mode.""" | ||
| last = self._details(mirror=False) | ||
| current = self._details(mirror=True) | ||
| assert _should_optimize_sync(current, last) is False | ||
|
|
||
| def test_mirror_disabled(self): | ||
| """Switching from mirror to additive does not require re-sync.""" | ||
| last = self._details(mirror=True) | ||
| current = self._details(mirror=False) | ||
| assert _should_optimize_sync(current, last) is True | ||
|
|
||
| def test_mirror_stays_true(self): | ||
| """Staying in mirror mode should allow optimization.""" | ||
| last = self._details(mirror=True) | ||
| current = self._details(mirror=True) | ||
| assert _should_optimize_sync(current, last) is True | ||
|
|
||
| def test_remote_pk_changed(self): | ||
| """Sync should not be skipped if a different remote is used.""" | ||
| last = self._details() | ||
| current = self._details(remote_pk="00000000-0000-0000-0000-000000000002") | ||
| assert _should_optimize_sync(current, last) is False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We're now going to have this in both FileRepo and RpmRepo. We should discuss (not for this PR!) moving this into the base-class, so it's available for every plugin.
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.
Potentially, but every plugin has to define its own fields to check anyway so it's borderline whether it would be worthwhile. Also not every repository is syncable.
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.
Hm, ok fair.