CiscoDevNet / ncclient

Python library for NETCONF clients (http://ncclient.org)
http://ncclient.com
Apache License 2.0
10 stars 9 forks source link

Error in EstablishSubscription #4

Closed timho93 closed 6 years ago

timho93 commented 6 years ago

Hey,

i am not sure if this is a bug or false usage but here is my code:

def establish_subscription(self):
    try:
        xpath = "/ip-sla-ios-xe-oper:ip-sla-stats/sla-oper-entry"
        s = self.netconf_client["netconf_client"].establish_subscription(
            callback=def_callback,
            errback = def_errback,
            period=10000,
            xpath=xpath)
        print('Subscription Result : %s' % s.subscription_result)
    except Exception as e:
        logging.error("Failed to establish subscription with device %s \n %s" % (self.identification, e))

# default Callback Method for established subscriptions
def def_callback(notif):
    print('-->>')
    print('(Default Callback)')
    print('Event time      : %s' % notif.event_time)
    print('Subscription Id : %d' % notif.subscription_id)
    print('Type            : %d' % notif.type)
    print('Data            :')
    print(etree.tostring(notif.datastore_ele, pretty_print=True).decode('utf-8'))
    print('<<--')

# default Callback Method for error while establishing subscriptions
def def_errback(notif):
    pass

Following Error occurs:

2018-07-04 11:59:57,290 ERROR    subscribe.py     callback                         || No callback for subscription_id=2147483664

I take a look at the code and printed out some parts. The subsction_listener od YangPushListener holds the callback and errorback like this:

{'urn:uuid:7e68a11e-ecad-4ce4-8255-0483a0ce707e': (<function def_callback at 0x106fdf048>, <function def_errback at 0x106fdf0d0>)}

A notification itself holds the subscription id like this:

<subscription-id>2147483664</subscription-id><

So the error occuring in callback(self, root, raw) method of YangPushListener:

2018-07-04 11:59:57,290 ERROR    subscribe.py     callback                         || No callback for subscription_id=2147483664

seems to be a result of the following part:

user_callback, _ = self.subscription_listeners[notif.subscription_id]

'urn:uuid:7e68a11e-ecad-4ce4-8255-0483a0ce707e' != 2147483664

Regards Tim

einarnn commented 6 years ago

Tim,

The underlying ncclient library keys messages by the message-id, allowing it to take a response and match it to the original request, making sure the original caller gets the notification. The subscription-id is part of the rest of the payload, but that is what the consumer needs to get back. Thus, to make the link between the original establish-subscription request and when push messages start to arrive, keyed by the subscription-id, the message-id is used as a temporary key, replaced when the subscription-id is learned.

Cheers,

Einar

timho93 commented 6 years ago

That means that the code runs simply to fast to learn the subscription-id before the user-defined callback function is called or what does that mean ?

Thank you for you help

einarnn commented 6 years ago

Crossing messages on separate threads...please see other issue you raised, but yes, I suspect that there may be a race condition here that I haven't previously encountered.

Cheers,

Einar

einarnn commented 6 years ago

This is an underlying netconf server issue, not an ncclient issue. Closing off!