napalm-automation / napalm-base

Apache License 2.0
32 stars 48 forks source link

Added a framework to be able to diff shitty/ios config #277

Open dbarrosop opened 7 years ago

dbarrosop commented 7 years ago

This framework does two things:

  1. Given a nested configuration it creates a nested structure: https://github.com/napalm-automation/napalm-base/compare/indent_differ?expand=1#diff-cae653bb93fa20df55fada139a153965R22
  2. Adds code to be able to diff two IndentedConfig objects.

What I would like to do is have people help testing (2). To do it you need to create a folder like this one; test/unit/test_indent_differ/test_case_1/. Inside, you have to put three files:

  1. cli.1.show_running_config.0. A configuration file retrieved from a device with a poor configuration model like IOS uses.
  2. candidate.txt. A bunch of commands you want to merge on the device.
  3. diff.txt. The expected diff.

Finally, run the test with py.test test/unit/test_indent_differ.py::Test_Indent_differ

Feel free to send PRs against the branch indent_differ for tests both passing and failing. The more we have the more assurance we will have this actually works.

itdependsnetworks commented 7 years ago

You can ignore my comment, the double git confused me

ogenstad commented 7 years ago

Just tested briefly, it looks nice. It will need some more ordering logic though, for example with access-lists. I sent in #278, which Travis seems happy with but it doesn't look like the tests are run. It fails locally for me due to ordering issues. It could possibly work sometimes but it will be random. Perhaps an ordered dict would do it.

mirceaulinic commented 7 years ago

Out of curiosity: what happens if you load a configuration that removes an entire (sub-)block? Let's have a better example:

running-config:

ntp server 1.2.3.4
ntp peer 5.6.7.8

Loading no ntp I would expect to provide the diff:

- ntp server 1.2.3.4
- ntp peer 5.6.7.8

Would that be the case?

dbarrosop commented 7 years ago

@ogenstad, yes an ordereddict is probably a good idea. Will look at your PR and at changing the logic to use an ordereddict to preserve order.

dbarrosop commented 7 years ago

@mirceaulinic regarding the ntp case you gave, that’s exactly how it works. Check test case 1, there is a logging and a bgp neighbor examples that I think behave as you described.