Skip to content

adding TYPE_API, and API remediation to perform config_merge operatio…#1066

Draft
huacchob wants to merge 2 commits intonautobot:developfrom
huacchob:api_remediation
Draft

adding TYPE_API, and API remediation to perform config_merge operatio…#1066
huacchob wants to merge 2 commits intonautobot:developfrom
huacchob:api_remediation

Conversation

@huacchob
Copy link
Copy Markdown

@huacchob huacchob commented Jan 6, 2026

Closes: #1064

What's Changed

Adding TYPE_API option for remediation and the API JSON remediation engine. I also added the updated documentation and tests

To Do

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  nautobot_golden_config
  choices.py
  models.py 356, 362, 375, 383, 440-441, 458-459, 471-472, 483, 486, 490-491, 494, 517, 520, 547, 549-552, 586, 600-601
Project Total  

This report was generated by python-coverage-comment-action

@huacchob huacchob marked this pull request as draft January 6, 2026 22:26
key: Any


class ApiRemediation: # pylint: disable=too-few-public-methods
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain this a bit more? Ideally, this logic is coming from some other library vs some custom logic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The remediation will travel down the path of the API response. The different data types we find in an API response are lists, dictionaries, and scalars (strings, integers, floats, booleans). The difference between scalars and dictionaries is being handled, because the code checks the type of the data, and continue traversing the path accordingly:

  • If the current type is a dictionary or a list, the remediation engine will continue to travel the path.
  • If the current value is an integer, float, boolean, or string, it will know to end traveling the path there.

The problem we are trying to fix here is what happens when the dictionary key is an integer? Without DictKeys we would have a path that consists of dict keys (which are scalars), list indexes (which are integers), and final scalars (the end of a path). When we rebuild the path in the _process_diff method, and we come across an integer, the _process_diff method will not know if the integer is a list index or a dictionary key. This is why we would need the DictKey class.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But what other options were considered? Like did we look at how we could potentially use jdiff or Dictdiffer?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Okay, I understand. I haven't used Dictdiffer or explored too many other options. I have attempted to use jdiff. The error I came across two errors, one I have a PR for 144 and another issue with how lists are flattened.

I will go ahead and do some research on what other tools I could use, starting with Dictdiffer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have added deepdiff as the diff engine here. While there is more code to make the code work with deepdiff, because of some custom logic (such as removal of unwanted fields in the response), I do think this provides more flexibility in how you would like to handle remediation, because deepdiff shows diff scenarios, such as index item removed/added, dictionary key added/removed, dict value removed/added and so on.

…ns for API based devices, such as Meraki, associated tests and documentation
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.

API JSON Remediation

2 participants