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

ncclient should require minimum of lxml>=3.3.0 #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/unit/transport/expected_edit_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><rpc xmlns:if="http://www.cisco.com/nxos:1.0:if_manager" xmlns:nfcli="http://www.cisco.com/nxos:1.0:nfcli" xmlns:nxos="http://www.cisco.com/nxos:1.0" xmlns:vlan_mgr_cli="http://www.cisco.com/nxos:1.0:vlan_mgr_cli" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:UUID-HERE"><edit-config><target><running/></target><config> <configure> <__XML__MODE__exec_configure> <vlan> <vlan-id-create-delete> <__XML__PARAM_value>1</__XML__PARAM_value> <__XML__MODE_vlan> <name> <vlan-name>1</vlan-name> </name> </__XML__MODE_vlan> </vlan-id-create-delete> </vlan> </__XML__MODE__exec_configure> </configure> </config></edit-config></rpc>
1 change: 1 addition & 0 deletions test/unit/transport/expected_get_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><rpc xmlns:if="http://www.cisco.com/nxos:1.0:if_manager" xmlns:nfcli="http://www.cisco.com/nxos:1.0:nfcli" xmlns:nxos="http://www.cisco.com/nxos:1.0" xmlns:vlan_mgr_cli="http://www.cisco.com/nxos:1.0:vlan_mgr_cli" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:UUID-HERE"><get><filter type="subtree"><cmd>show version</cmd></filter></get></rpc>
Copy link
Author

Choose a reason for hiding this comment

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

the xmlns order changed between now, and the last time I messed with this. I'm not sure the best way to deal with this.

Should the resulting xml be parsed, and the object diff'd ?
I don't want to ignore all the attributes in the root node because that is where the problem was with lxml 3.2.1

Thoughts / ideas ?

75 changes: 75 additions & 0 deletions test/unit/transport/test_clear_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from ncclient import manager
from ncclient import transport
from ncclient.manager import Manager

import re

import os

from mock import Mock
from mock import create_autospec

from nose.tools import assert_equal

from unittest import TestCase

class Test_LXML_problem(TestCase):

def test_clear_attributes_from_previous_message(self):
"""test sending multiple messages results in valid xml"""

test_dir = os.path.dirname(os.path.realpath(__file__))

# setup ncclient
device_handler = manager.make_device_handler({'name':'nexus'})
session = transport.Session(device_handler)
def mock_send(self, message='Not Set'):
pass
mock_send_function = create_autospec(mock_send, return_value="<test/>")
session.send = Mock(side_effect=mock_send_function)
session._connected = True
mgr = Manager(session, device_handler)
mgr._async_mode = True

# make first get call
mgr.get(filter=('subtree', '<cmd>show version</cmd>'))
xml_string = mock_send_function.mock_calls[0][1][0] # first call, second arg, value
xml_string = self._normalize_uuid(xml_string)
assert_equal(self._read_test_string(test_dir + '/expected_get_message.xml'), xml_string)
mock_send_function.reset_mock()

# make an edit-config call
config = '''<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<configure>
<__XML__MODE__exec_configure>
<vlan>
<vlan-id-create-delete>
<__XML__PARAM_value>1</__XML__PARAM_value>
<__XML__MODE_vlan>
<name>
<vlan-name>1</vlan-name>
</name>
</__XML__MODE_vlan>
</vlan-id-create-delete>
</vlan>
</__XML__MODE__exec_configure>
</configure>
</config>'''
config = ' '.join(config.split())


mgr.edit_config(target='running', config=config)
xml_string = mock_send_function.mock_calls[0][1][0]
xml_string = self._normalize_uuid(xml_string)
# using lxml 3.2.1 attributes from the get message bleed into the edit
assert_equal(self._read_test_string(test_dir + '/expected_edit_message.xml'), xml_string)

def _normalize_uuid(self, x):
"""replace the UUID, so we can compare apples to apples"""
return re.sub(r"urn:uuid:[a-z0-9\-]*", "urn:uuid:UUID-HERE", x)


def _read_test_string(self, file):
with open(file, 'r') as f:
text = f.read()
return text