networktocode / ntc-rosetta

The missing bridge between industry standard CLIs and YANG
https://ntc-rosetta.readthedocs.io/en/latest/index.html
Apache License 2.0
103 stars 23 forks source link

Add support for nested XML configuration #3

Open benmcbenben opened 5 years ago

benmcbenben commented 5 years ago

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 commented 5 years ago

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

benmcbenben commented 5 years ago

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

dbarrosop commented 5 years ago

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.

benmcbenben commented 5 years ago

Sounds good!