Skip to content

Commit

Permalink
Merge 25a8945 into 125f327
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemers committed Feb 15, 2016
2 parents 125f327 + 25a8945 commit 724892d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
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>
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

0 comments on commit 724892d

Please sign in to comment.