Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested XML configuration #3

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ntc_rosetta/parsers/openconfig/junos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy
from lxml import etree

from ntc_rosetta.parsers.openconfig.junos.openconfig_interfaces.interfaces import (
Expand All @@ -18,9 +19,17 @@ class JunosParser(parser.RootParser):

class Yangify(parser.ParserData):
def init(self) -> None:
self.root_native["dev_conf"] = etree.fromstring(
self.root_native["dev_conf"]
)
parsed_xml = etree.fromstring(self.root_native["dev_conf"])
if parsed_xml.tag != "configuration":
parsed_xml = parsed_xml.find("configuration")
if parsed_xml is None:
raise AttributeError(
"Unable to locate 'configuration' tag in XML blob"
Copy link
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.

)
# We need to copy the XML element here, otherwise it will retain its parent
# references, meaning we can inadvertantly walk up the tree when we shouldn't.
parsed_xml = copy(parsed_xml)
jathanism marked this conversation as resolved.
Show resolved Hide resolved
self.root_native["dev_conf"] = parsed_xml
self.native["dev_conf"] = self.root_native["dev_conf"]

interfaces = Interfaces
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<rpc-reply>
<configuration>
<interfaces>
<interface>
<name>xe-0/0/0</name>
<unit>
<name>0</name>
<description>this is interface xe-0/0/0</description>
</unit>
<disable/>
</interface>
<interface>
<name>xe-0/0/1</name>
<unit>
<name>0</name>
</unit>
<unit>
<name>10</name>
<description>this is interface xe-0/0/1.10</description>
</unit>
</interface>
<interface>
<name>xe-0/0/3</name>
<unit>
<name>0</name>
</unit>
</interface>
</interfaces>
</configuration>
<cli>
<banner></banner>
</cli>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<rpc-reply>
<configuration>
<interfaces>
<interface>
<name>xe-0/0/0</name>
<unit>
<name>0</name>
<description>this is interface xe-0/0/0</description>
</unit>
<disable/>
</interface>
<interface>
<name>xe-0/0/1</name>
<unit>
<name>0</name>
</unit>
<unit>
<name>10</name>
<description>this is interface xe-0/0/1.10</description>
</unit>
</interface>
<interface>
<name>xe-0/0/3</name>
<unit>
<name>0</name>
</unit>
</interface>
</interfaces>
</configuration>
<cli>
<banner></banner>
</cli>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<rpc-reply>
<bad_config_tag>
<interfaces>
<interface>
<name>xe-0/0/0</name>
<unit>
<name>0</name>
<description>this is interface xe-0/0/0</description>
</unit>
<disable/>
</interface>
<interface>
<name>xe-0/0/1</name>
<unit>
<name>0</name>
</unit>
<unit>
<name>10</name>
<description>this is interface xe-0/0/1.10</description>
</unit>
</interface>
<interface>
<name>xe-0/0/3</name>
<unit>
<name>0</name>
</unit>
</interface>
</interfaces>
</bad_config_tag>
<cli>
<banner></banner>
</cli>
</rpc-reply>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "xe-0/0/0",
"config": {
"name": "xe-0/0/0",
"type": "iana-if-type:ethernetCsmacd",
"enabled": false
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0,
"description": "this is interface xe-0/0/0"
}
}
]
}
},
{
"name": "xe-0/0/1",
"config": {
"name": "xe-0/0/1",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0
}
}
]
}
},
{
"name": "xe-0/0/3",
"config": {
"name": "xe-0/0/3",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0
}
}
]
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "xe-0/0/0",
"config": {
"name": "xe-0/0/0",
"type": "iana-if-type:ethernetCsmacd",
"enabled": false
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0,
"description": "this is interface xe-0/0/0"
}
}
]
}
},
{
"name": "xe-0/0/1",
"config": {
"name": "xe-0/0/1",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0
}
},
{
"index": 10,
"config": {
"index": 10,
"description": "this is interface xe-0/0/1.10"
}
}
]
}
},
{
"name": "xe-0/0/3",
"config": {
"name": "xe-0/0/3",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true
},
"subinterfaces": {
"subinterface": [
{
"index": 0,
"config": {
"index": 0
}
}
]
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<rpc-reply>
<configuration>
<interfaces>
<interface>
<name>xe-0/0/0</name>
<unit>
<name>0</name>
<description>this is interface xe-0/0/0</description>
</unit>
</interface>
<interface>
<name>xe-0/0/1</name>
<unit>
<name>0</name>
<family>
<ethernet-switching>
<interface-mode>access</interface-mode>
<vlan>
<members>10</members>
</vlan>
</ethernet-switching>
</family>
</unit>
</interface>
<interface>
<name>xe-0/0/3</name>
<unit>
<name>0</name>
<family>
<ethernet-switching>
<interface-mode>trunk</interface-mode>
<vlan>
<members>10</members>
<members>20</members>
</vlan>
</ethernet-switching>
</family>
</unit>
</interface>
</interfaces>
<vlans>
<vlan>
<name>default</name>
<vlan-id>1</vlan-id>
</vlan>
<vlan>
<name>prod</name>
<vlan-id>20</vlan-id>
</vlan>
<vlan inactive="inactive">
<vlan-id>10</vlan-id>
</vlan>
</vlans>
</configuration>
<cli>
<banner></banner>
</cli>
</rpc-reply>
Loading