ntc-rosetta icon indicating copy to clipboard operation
ntc-rosetta copied to clipboard

Add support for nested XML configuration

Open benmcbenben opened this issue 5 years ago • 4 comments

When a show conf | display xml is performed on a juniper device, the configuration is provided as follows:

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1X49/junos">
    <configuration junos:commit-seconds="1556580726" junos:commit-localtime="2019-04-29 23:32:06 UTC" junos:commit-user="vagrant">
      - configuration XML here -
    </configuration>
    <cli>
        <banner></banner>
    </cli>
</rpc-reply>

However, this module currently expected the "configuration" tag to be the top level tag. This minor modification searches for the configuration tag before continuing, and raises an AttributeError if it cannot be found (as the parsing would fail silently anyway if was not the case)

benmcbenben avatar May 30 '19 01:05 benmcbenben

This doesn't actually work - there was a flaw in my testing. Working on a proper fix

benmcbenben avatar May 30 '19 03:05 benmcbenben

thanks for your contribution, could you add some tests to avoid regressions?

Test cases added Also updated test_models.py to allow multiple test cases for each test. It might not be the best way to do it, as it might get confusing as to which case is failing in each test, but I couldn't figure out a more elegant way to add test cases without completely rewriting the "get_test_cases" function, which would end up making this a massive PR. If you like, I can work on this in a separate PR - I think it might be out of scope for this one

benmcbenben avatar Jun 03 '19 00:06 benmcbenben

Ok, played a bit with this and now I see why the copy is done. I think copy.copy is better here as we don't care about the original object (which we are throwing anyway) and it's going to be less resource intensive.

Re the tests, I am going to hold this PR while I rework the tests a bit, I think I need to get rid of all that magic and use a simple list instead. This is too clever for anyone's good.

dbarrosop avatar Jun 12 '19 11:06 dbarrosop

Sounds good!

benmcbenben avatar Jun 12 '19 12:06 benmcbenben