Skip to content

Commit

Permalink
fixed xpath and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
einarnn committed Apr 10, 2022
1 parent 8d8d01d commit aab7db6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ncclient/devices/iosxe.py
Expand Up @@ -43,7 +43,7 @@ def add_additional_ssh_connect_params(self, kwargs):

def transform_edit_config(self, node):
# find the first node that has the tag "config" with no namespace
nodes = node.findall(".//config")
nodes = node.findall("./config")
if len(nodes) == 1:
logger.debug('IOS XE handler: patching namespace of config element')
nodes[0].tag = '{%s}%s' % (BASE_NS_1_0, 'config')
Expand Down
19 changes: 19 additions & 0 deletions test/unit/devices/test_iosxe.py
@@ -1,5 +1,17 @@
import unittest
from ncclient.devices.iosxe import *
from ncclient.xml_ import new_ele
from ncclient.xml_ import qualify
from ncclient.xml_ import validated_element


CFG_BROKEN = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<hostname>tl-einarnn-c8kv</hostname>
</native>
</config>
"""


class TestIosxeDevice(unittest.TestCase):
Expand All @@ -20,3 +32,10 @@ def test_add_additional_ssh_connect_params(self):

def test_csr_unknown_host_cb(self):
self.assertTrue(iosxe_unknown_host_cb('host', 'fingerprint'))

def test_iosxe_transform_edit_config(self):
node = new_ele("edit-config")
node.append(validated_element(CFG_BROKEN, ("config", qualify("config"))))
node = self.obj.transform_edit_config(node)
config_nodes = node.findall('./config')
self.assertTrue(len(config_nodes) == 0)

0 comments on commit aab7db6

Please sign in to comment.