cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2613
Views
5
Helpful
2
Replies

ncclient subscribe to netconf stream problem with NSO version 5.2

cabottch@cisco.com
Cisco Employee
Cisco Employee

Dear Community,

 

Can not subscribe to a netconf stream using ncclient (same code working well with NSO version 4.7). 

 

Code:

 

 

from ncclient import manager

def start():
  conn=manager.connect(host="192.168.137.235", port=2022, username="admin", password="admin", device_params={'name': "default"}, timeout=30, hostkey_verify=False, unknown_host_cb=True, look_for_keys=False)
  print conn.create_subscription(stream_name="ncs-events")
  while True:
    print conn.take_notification().notification_xml

if __name__ == '__main__':
  start()

Error:

Traceback (most recent call last):
  File "stream-ncs-events.py", line 12, in <module>
    start()
  File "stream-ncs-events.py", line 7, in start
    print conn.create_subscription(stream_name="ncs-events")
  File "/usr/local/lib/python2.7/dist-packages/ncclient/manager.py", line 236, in execute
    huge_tree=self._huge_tree).request(*args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/subscribe.py", line 64, in request
    return self._request(node)
  File "/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py", line 349, in _request
    raise self._reply.error
ncclient.operations.rpc.RPCError: {'info': '<?xml version="1.0" encoding="UTF-8"?><error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>stream</bad-element>\n</error-info>\n', 'severity': 'error', 'tag': 'unknown-element', 'path': '\n    /rpc/p0:create-subscription\n  ', 'message': None, 'type': 'protocol'}

stream is there:

 

admin@ncs# show notification stream ?
Possible completions:
  SPWIFI          SP-WIFI-stream
  kicker-events   NCS event according to tailf-kicker.yang
  ncs-events      NCS event according to tailf-ncs-devices.yang

 

Thanks in advance for your help.

 

 

 

1 Accepted Solution

Accepted Solutions

gmuloche
Cisco Employee
Cisco Employee

Hello

 

managed to reproduce same error python 3.7 ncclient 6.6.0 and NSO 5.2.1

 

looking at netconf trace:

#309
<nc:rpc message-id="urn:uuid:86a933bc-510b-4be9-ace9-809af87bba52" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <nc:stream>ncs-events</nc:stream>
  </ns0:create-subscription>
</nc:rpc>

using netconf console (coming with NSO)

netconf-console -d  --host 127.0.0.1 --port 2022 --create-subscription ncs-events

looking at netconf trace:

#266
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <stream>ncs-events</stream>
  </create-subscription>
</rpc>

Looks like a NS problem you can track in ncclient library to xml_.py file (sub_ele / qualify lambda that insert BASE_NS_1

 

I patched my library like this (ncclient/operations/subscribe.py):

   53         if stream_name is not None:
   54             # Original commented
   55             # sub_ele(node, "stream").text = stream_name
CC 56             sub_ele_ns(node, "stream", NETCONF_NOTIFICATION_NS).text = stream_name

and your script started working.

looking at netconf trace:

#311
<nc:rpc message-id="urn:uuid:6fe34aa2-7b08-4b68-8a7f-ceef96a3d986" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <ns0:stream>ncs-events</ns0:stream>
  </ns0:create-subscription>
</nc:rpc>

Bottom line: you can patch the library (hmmm maybe open a github issue for this ?) - or use netconf-console! 

 

Corollary: probably you will need to do the sub_ele_ns trick for filter and start/stop times if you want to continue using ncclient

 

Why was it working before? maybe a less strict checking of namespaces in NSO 4.x ? (I have in mind restconf enforcing namespaces starting NSO 5.x)

 

Hope that helps!

View solution in original post

2 Replies 2

gmuloche
Cisco Employee
Cisco Employee

Hello

 

managed to reproduce same error python 3.7 ncclient 6.6.0 and NSO 5.2.1

 

looking at netconf trace:

#309
<nc:rpc message-id="urn:uuid:86a933bc-510b-4be9-ace9-809af87bba52" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <nc:stream>ncs-events</nc:stream>
  </ns0:create-subscription>
</nc:rpc>

using netconf console (coming with NSO)

netconf-console -d  --host 127.0.0.1 --port 2022 --create-subscription ncs-events

looking at netconf trace:

#266
<rpc message-id="1" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
  <create-subscription xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <stream>ncs-events</stream>
  </create-subscription>
</rpc>

Looks like a NS problem you can track in ncclient library to xml_.py file (sub_ele / qualify lambda that insert BASE_NS_1

 

I patched my library like this (ncclient/operations/subscribe.py):

   53         if stream_name is not None:
   54             # Original commented
   55             # sub_ele(node, "stream").text = stream_name
CC 56             sub_ele_ns(node, "stream", NETCONF_NOTIFICATION_NS).text = stream_name

and your script started working.

looking at netconf trace:

#311
<nc:rpc message-id="urn:uuid:6fe34aa2-7b08-4b68-8a7f-ceef96a3d986" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
  <ns0:create-subscription xmlns:ns0="urn:ietf:params:xml:ns:netconf:notification:1.0">
    <ns0:stream>ncs-events</ns0:stream>
  </ns0:create-subscription>
</nc:rpc>

Bottom line: you can patch the library (hmmm maybe open a github issue for this ?) - or use netconf-console! 

 

Corollary: probably you will need to do the sub_ele_ns trick for filter and start/stop times if you want to continue using ncclient

 

Why was it working before? maybe a less strict checking of namespaces in NSO 4.x ? (I have in mind restconf enforcing namespaces starting NSO 5.x)

 

Hope that helps!

Thanks so much for your help!!!
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: