napalm-automation-community / napalm-sros

NAPALM driver for Nokia SR OS
Apache License 2.0
17 stars 17 forks source link

SROS version 23.3.R1 fails with "an unexpected namespace is present" #64

Closed Joshua-M-CANARIE closed 1 year ago

Joshua-M-CANARIE commented 1 year ago

I am trying to access information on our new NOKIA 7750 routers running SROS 23.3.R1 with napalm-sros and I'm running into a problem. Any function that calls XML parsing with the namespace returns the error "an unexpected namespace is present".

Here is my code (This code accesses Juniper and NOKIA equipment):

for device, details in devices.items():
    driver = get_network_driver(details['system'])
    print(driver)
    if details['system'] == 'JunOS':
        connection = driver(username=JUNIPER_USERNAME, password=JUNIPER_PASSWORD, hostname=details['ip'])
    else:
        connection = driver(username=NOKIA_USERNAME, password=NOKIA_PASSWORD, hostname=details['ip'])
    try:
        connection.open()
        if not connection.is_alive():
            print('Unable to log into device')
            print(connection)
        print("interfaces")
        interfaces = connection.get_interfaces()
        pprint(interfaces)
        print('Interfaces with IP')
        ips = connection.get_interfaces_ip()
        pprint(ips)
        print('Network instances')
        instances = connection.get_network_instances()
        pprint(instances)
        print('facts')
        pprint(connection.get_facts())
        print('LLDP neighbors')
        pprint(connection.get_lldp_neighbors_detail())
        print('optics')
        pprint(connection.get_optics())
        print('config')
        pprint(connection.get_config())
   finally:
        connection.close()

And this is the following output:

<class 'napalm_sros.sros.NokiaSROSDriver'>
interfaces
Error in method get interfaces : 
            An unexpected namespace is present.

None
Interfaces with IP
Error in method get interfaces ip : 
            An unexpected namespace is present.

None
Network instances
Error in method get network instances : 
            An unexpected namespace is present.

None
facts
Error in method get facts : 
            An unexpected namespace is present.

None
LLDP neighbors
Error in method get lldp neighbors detail : 
            An unexpected namespace is present.

None
optics
Error in method get optics : 
            An unexpected namespace is present.

None
config
{'candidate': '<configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf" '
              'xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" '
              'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">\n'
              (insert config here)
              '    ',
 'running': '<configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf" '
            'xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" '
            'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">\n'
           (insert config here)
            '    ',
 'startup': '<configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf" '
            'xmlns:nokia-attr="urn:nokia.com:sros:ns:yang:sr:attributes" '
            'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">\n'
           (insert config here)
            '    '}

When I run show version on the device, I see this:

# show version
TiMOS-C-23.3.R1 cpm/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.
All rights reserved. All use subject to applicable license agreements.
Built on (time) by builder in (location)
jbemmel commented 1 year ago

Thanks for reporting. Issue reproduced for get_interfaces API call - XML sent:

<?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:156fe603-eeb8-4071-a28e-fd833dc7bfa5"><nc:get><filter>
        <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">
            <port>
                <port-id/>
                <oper-state/>
                <hardware-mac-address/>
                <ethernet>
                    <oper-speed/>
                </ethernet>
            </port>
            <router>
                <interface>
                    <oper-ip-mtu/>
                    <if-oper-status/>
                    <last-oper-change/>
                </interface>
            </router>
            <chassis>
                <hardware-data>
                    <base-mac-address/>
                </hardware-data>
            </chassis>
        </state>
        <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf">
            <port>
                <port-id/>
                <description/>
                <ethernet>
                    <mtu/>
                </ethernet>
                <admin-state/>
            </port>
            <router>
                <interface>
                    <admin-state/>
                    <description/>
                    <mac/>
                    <port/>
                    <loopback/>
                </interface>
            </router>
        </configure>
    </filter><ns0:with-defaults xmlns:ns0="urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults">report-all</ns0:with-defaults></nc:get></nc:rpc>

The SR OS server side (23.3.R1) complains about the 'filter' element:

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply message-id="urn:uuid:156fe603-eeb8-4071-a28e-fd833dc7bfa5" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <rpc-error>
        <error-type>protocol</error-type>
        <error-tag>unknown-namespace</error-tag>
        <error-severity>error</error-severity>
        <error-message>
            An unexpected namespace is present.
        </error-message>
        <error-info>
            <bad-element>filter</bad-element>
            <bad-namespace></bad-namespace>
        </error-info>
    </rpc-error>
</rpc-reply>

The same code does work with 22.10.R1

jbemmel commented 1 year ago

I've committed a fix which includes an explicit namespace in the \<filter> element, see e.g. https://github.com/napalm-automation-community/napalm-sros/blob/master/napalm_sros/nc_filters.py#L11

There may be additional updates required to the XML filters for newer SR OS releases, I'll have to do some further testing

Joshua-M-CANARIE commented 1 year ago

Thank you very much with the change. Most functions do now work for 23.3.R1, there are some functions I'm still facing errors with though. Specifically, get_interfaces and get_bgp_neighbors. The get_interfaces function gets the following error:

Error in method get interfaces : 
            MINOR: MGMT_CORE #2201: Unknown element

Whereas get_bgp_neighbors gets the previously identified namespace error.

jbemmel commented 1 year ago

get_interfaces has an int-oper-status element that got renamed to oper-state; I need to find a good way to make it work for all releases

get_bgp_neighbors was refactored and has its \<filter> element in a different file; will update it shortly

jbemmel commented 1 year ago

Proposed fix: https://github.com/napalm-automation-community/napalm-sros/pull/65

Basically the root cause is that SR OS 23.3.R1 is more strict about XML namespaces, and the YANG model has changed slightly (one element under state got renamed)