-
Notifications
You must be signed in to change notification settings - Fork 390
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?