napalm-automation-community / napalm-ros

MikroTik RouterOS NAPALM driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

expected string or bytes-like object on get_facts

brantleyp1 opened this issue · comments

Description of Issue/Question

I've got napalm/napalm-ros installed on an instance of NetBox and am hitting an error "napalm - ERROR - method - Failed: expected string or bytes-like object" either calling get_facts via CLI or NetBox GUI

Setup

Fresh install of Ubuntu 20.04 that has updates run.

The Napalm/Napalm-ROS are being installed in both /usr/local/lib/python3.8 and /opt/netbox/venv/lib/python3.8, but seeing same results from either. This is an artifact of the ansible role I'm using to build the netbox install.

napalm-ros version

napalm-ros==1.0.1

ROS version

 #   NAME                                                     VERSION                                                    SCHEDULED
 0   routeros-arm64                                           6.48.1
 1   system                                                   6.48.1
 2   ipv6                                                     6.48.1
 3 X wireless                                                 6.48.1
 4 X hotspot                                                  6.48.1
 5 X mpls                                                     6.48.1
 6   routing                                                  6.48.1
 7   ppp                                                      6.48.1
 8   dhcp                                                     6.48.1
 9   security                                                 6.48.1
10   advanced-tools                                           6.48.1

Steps to Reproduce the Issue

Install napalm==3.4.1 and napalm_ros==1.0.1

Running into an issue with netmiko that is required for napalm>=4.0.0 so keeping at 3.4.1 for now.

Error Traceback

(Paste the complete traceback of the exception between quotes below)

napalm --user yep --password 'uhhuh' --vendor ros 172.X.X.3 call get_facts
2022-07-13 16:04:29,089 - napalm - ERROR - method - Failed: expected string or bytes-like object

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

Traceback (most recent call last):
  File "/usr/local/bin/napalm", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py", line 308, in main
    run_tests(args)
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py", line 291, in run_tests
    call_getter(device, args.method, **method_kwargs)
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py", line 255, in call_getter
    r = func(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/napalm_ros/ros.py", line 382, in get_facts
    'interface_list': napalm.base.utils.string_parsers.sorted_nicely(
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/utils/string_parsers.py", line 19, in sorted_nicely
    return sorted(sort_me, key=alphanum_key)
  File "/usr/local/lib/python3.8/dist-packages/napalm/base/utils/string_parsers.py", line 14, in alphanum_key
    return [convert(c) for c in re.split("([0-9]+)", key)]
  File "/usr/lib/python3.8/re.py", line 231, in split
    return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or bytes-like object

Workaround

I'm able to work around it by changing the function and removing the call to napalm.base.string_parsers:

    def get_facts(self):
        resource = tuple(self.api('/system/resource/print'))[0]
        identity = tuple(self.api('/system/identity/print'))[0]
        routerboard = tuple(self.api('/system/routerboard/print'))[0]
        interfaces = tuple(self.api('/interface/print'))
        return {
            'uptime': to_seconds(resource['uptime']),
            'vendor': resource['platform'],
            'model': resource['board-name'],
            'hostname': identity['name'],
            'fqdn': u'',
            'os_version': resource['version'],
            'serial_number': routerboard.get('serial-number', ''),
            'interface_list': tuple(iface['name'] for iface in interfaces),
        #    'interface_list': napalm.base.utils.string_parsers.sorted_nicely(
        #        tuple(iface['name'] for iface in interfaces),
        #    ),
        }

Which nets a better result:

napalm --user xxxxxxx --password 'xxxxxxx' --vendor ros 172.x.x.3 call get_facts
{
    "uptime": 4188696,
    "vendor": "MikroTik",
    "model": "CCR2004-1G-12S+2XS",
    "hostname": "xxxxxxx",
    "fqdn": "",
    "os_version": "6.48.1 (stable)",
    "serial_number": "xxxxxxxx",
    "interface_list": [
        "ether1-COPPER-TEST-PORT",
etc...
        "WiFi-Management"
    ]
}

Please provide all interface names for a device that crashes napalm-ros. I suspect some strange character in name.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.