napalm-automation / napalm

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

device.get_vlans() doesn't operate as expected for Cisco IOS / IE switches that support spaces in the vlan name. #1407

Open alphabet5 opened 3 years ago

alphabet5 commented 3 years ago

Description of Issue/Question

Note: Please check https://guides.github.com/features/mastering-markdown/ to see how to properly format your request.

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

(Place an x between the square brackets where applicable)

Setup

{
    "uptime": 1212540,
    "vendor": "Cisco",
    "os_version": "IE4000  Software (IE4000-UNIVERSALK9-M), Version 15.2(4)EA9, RELEASE SOFTWARE (fc2)",
    "serial_number": "REMOVED",
    "model": "IE-4000-4TC4G-E",
    "hostname": "Switch",
    "fqdn": "Switch",
    "interface_list": [
        "Vlan1",
        "GigabitEthernet1/1",
        "GigabitEthernet1/2",
        "GigabitEthernet1/3",
        "GigabitEthernet1/4",
        "FastEthernet1/5",
        "FastEthernet1/6",
        "FastEthernet1/7",
        "FastEthernet1/8"
    ]
}

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==3.2.0

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

IE4000  Software (IE4000-UNIVERSALK9-M), Version 15.2(4)EA9, RELEASE SOFTWARE (fc2)

Steps to Reproduce the Issue

  1. Create a vlan with a space in the name on the switch.
  2. Run device.get_vlans()

Looking at sh vlan br from the switch

Switch#sh vlan br

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Gi1/3, Gi1/4
10   PLC CONTROL NETWORK              active    Fa1/6, Fa1/7
14   OTHER IO NETWORK                  active    Gi1/2, Fa1/5, Fa1/8
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup

Looking at device.get_vlans()

{
    "1": {
        "name": "default",
        "interfaces": [
            "GigabitEthernet1/1",
            "GigabitEthernet1/3",
            "GigabitEthernet1/4"
        ]
    },
    "10": {
        "name": "PLC",
        "interfaces": []
    },
    "14": {
        "name": "OTHER",
        "interfaces": []
    },
    "1002": {
        "name": "fddi-default",
        "interfaces": [
            "GigabitEthernet1/1"
        ]
    },
    "1003": {
        "name": "token-ring-default",
        "interfaces": [
            "GigabitEthernet1/1"
        ]
    },
    "1004": {
        "name": "fddinet-default",
        "interfaces": [
            "GigabitEthernet1/1"
        ]
    },
    "1005": {
        "name": "trnet-default",
        "interfaces": [
            "GigabitEthernet1/1"
        ]
    }
}

I've traced it down to the regex on line ~3589 of _get_vlans_by_id in napalm/napalm/ios/ios.py, which doesn't support spaces in the vlan names.

interface_regex = r"{}\s+{}\s+\S+\s+([A-Z][a-z].*)$".format(
            vlan_id, vlan_name
        )

Error Traceback

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

N/A
network-shark commented 6 months ago

@alphabet5 Can you check the latest napalm version , if this works for you ? I have fixed it in https://github.com/napalm-automation/napalm/pull/2010