napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.24k stars 552 forks source link

Raises XMLCLIError when getting facts from IOS-XR Version 7.3.3 #1656

Open Kani999 opened 2 years ago

Kani999 commented 2 years ago

Unable to get facts from IOS-XR (7.3.3) device

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

Setup

napalm version

napalm==3.4.1

Network operating system version

Mon May 30 12:24:43.257 CEST
Cisco IOS XR Software, Version 7.3.3 LNT
Copyright (c) 2013-2022 by Cisco Systems, Inc.

Build Information:
 Built By     : ingunawa
 Built On     : Sat Jan 29 10:33:37 UTC 2022
 Build Host   : iox-ucs-060
 Workspace    : /auto/srcarchive16/prod/7.3.3/8000/ws
 Version      : 7.3.3
 Label        : 7.3.3

cisco 8000 (Intel(R) Xeon(R) CPU D-1530 @ 2.40GHz)
cisco 8201 (Intel(R) Xeon(R) CPU D-1530 @ 2.40GHz) processor with 32GB of memory
RP5 uptime is 1 day, 2 hours, 6 minutes
Cisco 8201 Chassis w/ 24x400GE QSFP56-DD&12x100GE QSFP28

Steps to Reproduce the Issue

run napalm --user USERNAME --password PASSWORD --vendor iosxr --debug IP_ADDRESS call get_facts

Error Traceback

2022-05-30 12:23:11,656 - napalm - DEBUG - Starting napalm's debugging tool
2022-05-30 12:23:11,656 - napalm - DEBUG - Gathering napalm packages
2022-05-30 12:23:11,657 - napalm - DEBUG - napalm==3.4.1
2022-05-30 12:23:11,657 - napalm - DEBUG - get_network_driver - Calling with args: ('iosxr',), {}
2022-05-30 12:23:11,657 - napalm - DEBUG - get_network_driver - Successful
2022-05-30 12:23:11,657 - napalm - DEBUG - __init__ - Calling with args: (<class 'napalm.iosxr.iosxr.IOSXRDriver'>, 'IP_ADDRESS', 'USERNAME'), {'password': '*******', 'timeout': 60, 'optional_args': {}}
2022-05-30 12:23:11,657 - napalm - DEBUG - __init__ - Successful
2022-05-30 12:23:11,657 - napalm - DEBUG - pre_connection_tests - Calling with args: (<napalm.iosxr.iosxr.IOSXRDriver object at 0x7fde21ec3490>,), {}
2022-05-30 12:23:11,657 - napalm - DEBUG - open - Calling with args: (<napalm.iosxr.iosxr.IOSXRDriver object at 0x7fde21ec3490>,), {}
2022-05-30 12:23:19,516 - napalm - DEBUG - open - Successful
2022-05-30 12:23:19,516 - napalm - DEBUG - connection_tests - Calling with args: (<napalm.iosxr.iosxr.IOSXRDriver object at 0x7fde21ec3490>,), {}
2022-05-30 12:23:19,516 - napalm - DEBUG - get_facts - Calling with args: (<napalm.iosxr.iosxr.IOSXRDriver object at 0x7fde21ec3490>,), {}
2022-05-30 12:23:19,587 - napalm.pyIOSXR.iosxr - ERROR -
Original call was: <?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0"><Get><Operational><SystemTime/><PlatformInventory><RackTable><Rack><Naming><Name>0</Name></Naming><Attributes><BasicInfo/></Attributes></Rack></RackTable></PlatformInventory></Operational></Get></Request>
2022-05-30 12:23:19,588 - napalm - ERROR - get_facts - Failed:
Original call was: <?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0"><Get><Operational><SystemTime/><PlatformInventory><RackTable><Rack><Naming><Name>0</Name></Naming><Attributes><BasicInfo/></Attributes></Rack></RackTable></PlatformInventory></Operational></Get></Request>

================= Traceback =================

Traceback (most recent call last):
  File "/home/jankrupa/napalm_test/venv/bin/napalm", line 8, in <module>
    sys.exit(main())
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/base/clitools/cl_napalm.py", line 308, in main
    run_tests(args)
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/base/clitools/cl_napalm.py", line 287, in run_tests
    call_facts(device)
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
    r = func(*args, **kwargs)
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/base/clitools/cl_napalm.py", line 195, in call_facts
    facts = device.get_facts()
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/iosxr/iosxr.py", line 175, in get_facts
    facts_rpc_reply = ETREE.fromstring(self.device.make_rpc_call(facts_rpc_request))
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/pyIOSXR/iosxr.py", line 174, in make_rpc_call
    result = self._execute_rpc(rpc_command)
  File "/home/jankrupa/napalm_test/venv/lib/python3.8/site-packages/napalm/pyIOSXR/iosxr.py", line 474, in _execute_rpc
    raise XMLCLIError(error_msg, self)
napalm.pyIOSXR.exceptions.XMLCLIError:
Original call was: <?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0"><Get><Operational><SystemTime/><PlatformInventory><RackTable><Rack><Naming><Name>0</Name></Naming><Attributes><BasicInfo/></Attributes></Rack></RackTable></PlatformInventory></Operational></Get></Request>
Kani999 commented 2 years ago

https://github.com/napalm-automation/napalm/blob/develop/napalm/pyIOSXR/iosxr.py#L409 https://github.com/napalm-automation/napalm/blob/develop/napalm/pyIOSXR/iosxr.py#L415

    def _execute_rpc(self, command_xml, delay_factor=0.1):

        xml_rpc_command = (
            '<?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0">'
            + command_xml
            + "</Request>"
        )

        response = self._send_command(xml_rpc_command, delay_factor=delay_factor)

xml_rpc_command =

<?xml version="1.0" encoding="UTF-8"?>
<Request MajorVersion="1" MinorVersion="0">
    <Get>
        <Operational>
            <SystemTime/>
            <PlatformInventory>
                <RackTable>
                    <Rack>
                        <Naming>
                            <Name>0</Name>
                        </Naming>
                        <Attributes>
                            <BasicInfo/>
                        </Attributes>
                    </Rack>
                </RackTable>
            </PlatformInventory>
        </Operational>
    </Get>
</Request>

response =

<?xml version="1.0" encoding="UTF-8"?>\n
<Response MajorVersion="1" MinorVersion="0">
    <Get ErrorCode="0x43679000" ErrorMsg="&apos;XML Service Library&apos; detected the &apos;warning&apos; condition &apos;An error was encountered in the XML beneath this operation tag&apos;">
        <Operational>
            <SystemTime MajorVersion="4" MinorVersion="2">
                <Clock>
                    <Year>2022</Year>
                    <Month>5</Month>
                    <Day>30</Day>
                    <Hour>13</Hour>
                    <Minute>20</Minute>
                    <Second>24</Second>
                    <Millisecond>619</Millisecond>
                    <Wday>1</Wday>
                    <TimeZone>CEST</TimeZone>
                    <TimeSource>NTP</TimeSource>
                </Clock>
                <Uptime>
                    <Hostname>HOSTNAME</Hostname>
                    <Uptime>97348</Uptime>
                </Uptime>
            </SystemTime>
            <PlatformInventory ErrorCode="0x4368a400" ErrorMsg="&apos;XMLMDA&apos; detected the &apos;warning&apos; condition &apos;The XML request does not conform to the schema. No such element name exists at this location in the schema. Please check the request against the schema.&apos;"/>
        </Operational>
    </Get>
    <ResultSummary ErrorCount="1"/>
</Response>
ktbyers commented 2 years ago

So PlatformInventory doesn't exist on 7.3.3? Is there an alternate place we should be querying for this information on 7.3.3?

Kani999 commented 2 years ago

@ktbyers Could you help me with how I can get the whole XML representation from the device? So I can look at what's in there when PlatfomrInventory is missing?

Kani999 commented 2 years ago

Instead of PlatformInventory there is Inventory with Entities instead RackTable

xml request:

<?xml version="1.0" encoding="UTF-8"?>
<Request MajorVersion="1" MinorVersion="0">
<Get>
    <Operational>
        <SystemTime/>
        <Inventory>
        <Entities>
            <Entity>
                <Naming>
                    <Name>Rack 0</Name>
                </Naming>
                <Attributes>
                    <InvBasicBag></InvBasicBag>
                </Attributes>
            </Entity>
        </Entities>
    </Inventory>
    </Operational>
</Get>
</Request>

response:

<?xml version="1.0" encoding="UTF-8"?>
<Response MajorVersion="1" MinorVersion="0">
    <Get>
        <Operational>
            <SystemTime MajorVersion="4" MinorVersion="2">
                <Clock><Year>2022</Year><Month>6</Month><Day>3</Day><Hour>12</Hour><Minute>29</Minute><Second>39</Second><Millisecond>64</Millisecond><Wday>5</Wday><TimeZone>CEST</TimeZone><TimeSource>NTP</TimeSource></Clock>
                <Uptime>
                    <Hostname>HOSTNAME</Hostname>
                    <Uptime>439903</Uptime>
                </Uptime>
            </SystemTime>
            <Inventory MajorVersion="6" MinorVersion="0">
                <Entities MajorVersion="6" MinorVersion="0">
                    <Entity>
                        <Naming><Name>Rack 0</Name></Naming>
                        <Attributes>
                            <InvBasicBag>
                                <Description>Cisco 8201 Chassis w/ 24x400GE QSFP56-DD&amp;12x100GE QSFP28</Description>
                                <VendorType>1.3.6.1.4.1.9.12.3.1.3.2044</VendorType>
                                <Name>Rack 0</Name>
                                <HardwareRevision>V03</HardwareRevision>
                                <SoftwareRevision>7.3.3</SoftwareRevision>
                                <ChipHardwareRevision>1.0</ChipHardwareRevision>
                                <SerialNumber>FOCXXXXXN051</SerialNumber>
                                <ModelName>8201</ModelName>
                                <assetIdStr>N/A</assetIdStr>
                                <IsFieldReplaceableUnit>true</IsFieldReplaceableUnit>
                                <CompositeClassCode>65536</CompositeClassCode>
                                <Alias>N/A</Alias>
                                <UnrecognizedFRU>false</UnrecognizedFRU>
                                <UniqueID>8384555</UniqueID>
                            </InvBasicBag>
                        </Attributes>
                    </Entity>
                </Entities>
            </Inventory>
        </Operational>
    </Get>
    <ResultSummary ErrorCount="0"/>
</Response>
Kani999 commented 2 years ago

@ktbyers I've created pull request (work in progress) #1664 which replaces the XML RPC calls which work with iosxr version 7.3.3. It fixes get_facts and get_interfaces calls. I did not test other methods, but I suppose there will be problems too.

But I don't know how to make conditional statements that determine which xml_rpc_command (and xpaths) should be executed based on the version of the platform. Do you know how to handle this if you only get the version information in the get_facts method?

ktbyers commented 2 years ago

@Kani999 We could detect the OS-version on connect (NAPALM open() call) and then set that as a private object attribute.

napalm_object._iosxr_version()

We would have to use a solution for detecting the OS version that we thought would reasonably work across versions and if it fails set it to unknown and then in the getters have some default action happen for the unknown case.

Does that sound reasonable?

Kani999 commented 2 years ago

@ktbyers - That sounds fine, but still, I don't know which "common" command should be sent to the device, to get the os_version response in the open() method.

Sending CLI command show version and parse it? (Using textfsm or something).

ktbyers commented 2 years ago

@Kani999 Yes, someone will have to dig into the IOS-XR netconf and which "get" operations would reliably return this across some set of IOS-XR versions.

ktbyers commented 2 years ago

@Kani999 Okay, I think with what you provided above there is probably enough...let me see what I can do on this.

ktbyers commented 1 year ago

I didn't do any work on this. Someone would still need to work on this.