Skip to content

Add support for nested XML configuration#3

Open
benmcbenben wants to merge 8 commits intonetworktocode:developfrom
benmcbenben:patch-2
Open

Add support for nested XML configuration#3
benmcbenben wants to merge 8 commits intonetworktocode:developfrom
benmcbenben:patch-2

Conversation

@benmcbenben
Copy link
Copy Markdown
Contributor

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)

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
Copy link
Copy Markdown
Contributor Author

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

Changes now appear to be working as expected.
Comment thread ntc_rosetta/parsers/openconfig/junos/__init__.py
@jathanism jathanism added the enhancement New feature or request label May 30, 2019
Copy link
Copy Markdown
Collaborator

@dbarrosop dbarrosop left a comment

Choose a reason for hiding this comment

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

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

Comment thread ntc_rosetta/parsers/openconfig/junos/__init__.py Outdated
… happy

* Update test_models to allow multiple test cases for each test type
* Add test case for the junos parser
* Add failing test case for junos parser
* Add raises test case for junos parser, to test new code in parsers/openconfig/junos/__init__.py
@benmcbenben
Copy link
Copy Markdown
Contributor Author

benmcbenben commented Jun 3, 2019

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
Copy link
Copy Markdown
Collaborator

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.

s/deepcopy/copy
@benmcbenben
Copy link
Copy Markdown
Contributor Author

Sounds good!

parsed_xml = parsed_xml.find("configuration")
if parsed_xml is None:
raise AttributeError(
"Unable to locate 'configuration' tag in XML blob"
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.

We made changes to the testing so if you could rebase off the develop branch and change the testing for these change to match the new way, that would be great.

I think we should also start creating our own exceptions for parsing errors rather than use built-in errors. Such as ntc_rosetta.exceptions.ConfigurationParsingError, but this needs more discussion.

@FragmentedPacket FragmentedPacket added the changes_requested Waiting on user to address feedback label Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes_requested Waiting on user to address feedback enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants