Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 30
Extend sync_to|from to accept a Diff#80
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
glennmatthews
merged 6 commits into
networktocode:main
from
FragmentedPacket:76-sync-diffNov 22, 2021
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ffc6694
Allow Diff object to be passed into sync_to/from. Update tests and ex…
FragmentedPacket 0d19468
Update examples/01-multiple-data-sources/README.md
FragmentedPacket 9f88513
Update diffsync/__init__.py
FragmentedPacket 1482248
Update diffsync/__init__.py
FragmentedPacket 4b804b8
Add better testing. Add new exception if provided diff_class and diff…
FragmentedPacket 0bb0f0e
Pylint fails within the pipeline, but not locally.
FragmentedPacket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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
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 |
|---|---|---|
| @@ -40,8 +40,10 @@ def main(): | ||
| print(diff.str()) | ||
| if args.sync: | ||
| if not args.diff: | ||
| diff = None | ||
| print("Updating the list of countries in Nautobot ...") | ||
| nautobot.sync_from(local, flags=flags, diff_class=AlphabeticalOrderDiff) | ||
| nautobot.sync_from(local, flags=flags, diff_class=AlphabeticalOrderDiff, diff=diff) | ||
FragmentedPacket marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if __name__ == "__main__": | ||
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 |
|---|---|---|
| @@ -20,7 +20,7 @@ | ||
| import pytest | ||
| from diffsync import DiffSync, DiffSyncModel, DiffSyncFlags, DiffSyncModelFlags | ||
| from diffsync.exceptions import ObjectAlreadyExists, ObjectNotFound, ObjectCrudException | ||
| from diffsync.exceptions import DiffClassMismatch, ObjectAlreadyExists, ObjectNotFound, ObjectCrudException | ||
| from .conftest import Site, Device, Interface, TrackedDiff, BackendA, PersonA | ||
| @@ -468,6 +468,57 @@ def callback(stage, current, total): | ||
| assert last_value == {"current": expected, "total": expected} | ||
| def test_diffsync_sync_to_w_different_diff_class_raises(backend_a, backend_b): | ||
| diff = backend_b.diff_to(backend_a) | ||
| with pytest.raises(DiffClassMismatch) as failure: | ||
| backend_b.sync_to(backend_a, diff_class=TrackedDiff, diff=diff) | ||
| assert failure.value.args[0] == "The provided diff's class (Diff) does not match the diff_class: TrackedDiff" | ||
| def test_diffsync_sync_to_w_diff_no_mocks(backend_a, backend_b): | ||
| diff = backend_b.diff_to(backend_a) | ||
| assert diff.has_diffs() | ||
| # Perform full sync | ||
| backend_b.sync_to(backend_a, diff=diff) | ||
| # Assert there are no diffs after synchronization | ||
| post_diff = backend_b.diff_to(backend_a) | ||
| assert not post_diff.has_diffs() | ||
| def test_diffsync_sync_to_w_diff(backend_a, backend_b): | ||
| diff = backend_b.diff_to(backend_a) | ||
| assert diff.has_diffs() | ||
| # Mock diff_from to make sure it's not called when passing in an existing diff | ||
| backend_b.diff_from = mock.Mock() | ||
FragmentedPacket marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| backend_b.diff_to = mock.Mock() | ||
| backend_a.diff_from = mock.Mock() | ||
| backend_a.diff_to = mock.Mock() | ||
| # Perform full sync | ||
| backend_b.sync_to(backend_a, diff=diff) | ||
| # Assert none of the diff methods have been called | ||
| assert not backend_b.diff_from.called | ||
FragmentedPacket marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| assert not backend_b.diff_to.called | ||
| assert not backend_a.diff_from.called | ||
| assert not backend_a.diff_to.called | ||
| def test_diffsync_sync_from_w_diff(backend_a, backend_b): | ||
| diff = backend_a.diff_from(backend_b) | ||
| assert diff.has_diffs() | ||
| # Mock diff_from to make sure it's not called when passing in an existing diff | ||
| backend_a.diff_from = mock.Mock() | ||
| backend_a.diff_to = mock.Mock() | ||
| backend_b.diff_from = mock.Mock() | ||
| backend_b.diff_to = mock.Mock() | ||
| # Perform full sync | ||
| backend_a.sync_from(backend_b, diff=diff) | ||
| # Assert none of the diff methods have been called | ||
| assert not backend_a.diff_from.called | ||
| assert not backend_a.diff_to.called | ||
| assert not backend_b.diff_from.called | ||
| assert not backend_b.diff_to.called | ||
| def test_diffsync_sync_from(backend_a, backend_b): | ||
| backend_a.sync_complete = mock.Mock() | ||
| backend_b.sync_complete = mock.Mock() | ||
| @@ -542,7 +593,6 @@ def check_successful_sync_log_sanity(log, src, dst, flags): | ||
| def check_sync_logs_against_diff(diffsync, diff, log, errors_permitted=False): | ||
| """Given a Diff, make sure the captured structlogs correctly correspond to its contents/actions.""" | ||
| for element in diff.get_children(): | ||
| print(element) | ||
| # This is kinda gross, but needed since a DiffElement stores a shortname and keys, not a unique_id | ||
| uid = getattr(diffsync, element.type).create_unique_id(**element.keys) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.