napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

Regex used fto match the name of the network interface #179

Closed nicolaskarp closed 6 years ago

nicolaskarp commented 7 years ago

Hello Everyone,

Issue with command "get_interfaces" :

        Traceback (most recent call last):
          File "/usr/lib/python2.7/dist-packages/salt/utils/napalm.py", line 153, in call
            out = getattr(napalm_device.get('DRIVER'), method)(*args, **kwargs)
          File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 985, in get_interfaces
            found without any known interface")
        ValueError: Interface attributes were    found without any known interface

Version : napalm-ios==0.7.0

It's happening when on my router, I have an interface like this : pseudowire100006 is up

The problem is with the regex used to match the interface Name :
interface_regex = r"^(\S+?)\s+is\s+(.+?),\s+line\s+protocol\s+is\s+(\S+)"

The "line protocol" section is not available on this type of Internafe so an issue is raised.

Best Regards,

Nick

itdependsnetworks commented 7 years ago

Can you provide the full scrubbed relevant section of show interfaces?

nicolaskarp commented 7 years ago

hello,

here you go :

pseudowire100006 is up
    MTU 1500 bytes, BW 10000000 Kbit
    Encapsulation mpls
    Peer IP x.x.x.x, VC ID xx
    RX
      34216908 packets 6774108588 bytes 0 drops
    TX
      79234824 packets 23633885654 bytes 0 drops

I've done something like that in order to resolve the issue :

  ```
  interface_regex_simple = r"^(\S+?)\s+is\s+(.+?)"
        if re.search(interface_regex_simple, line):
            interface_match_simple = re.search(interface_regex_simple, line)
            interface = interface_match_simple.groups()[0]
            status = interface_match_simple.groups()[1]

            interface_regex = r"^(\S+?)\s+is\s+(.+?),\s+line\s+protocol\s+is\s+(\S+)"
            if re.search(interface_regex, line):
                interface_match = re.search(interface_regex, line)
                protocol = interface_match.groups()[2]

                if 'admin' in status:
                    is_enabled = False
                else:
                    is_enabled = True
                is_up = bool('up' in protocol)
            else:
                    is_enabled = True
                    is_up = True
itdependsnetworks commented 7 years ago

This is a rather large deviation from the mocked data on hand. Just to clarify this is the full output of the relevant interface?

As an example, here is roughly what is expected.

Vlan1 is up, line protocol is up
  Hardware is EtherSVI, address is 0014.1c57.a4c0 (bia 0014.1c57.a4c0)
  MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive not supported
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input 00:00:00, output never, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/40 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     37453340 packets input, 2249839744 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 packets output, 0 bytes, 0 underruns
     0 output errors, 0 interface resets
     0 output buffer failures, 0 output buffers swapped out
nicolaskarp commented 7 years ago

Yes that's the only output. Those interfaces are used for L2VPN.

sh int pseudowire 100006

pseudowire100006 is up
    MTU 1500 bytes, BW 10000000 Kbit
    Encapsulation mpls
    Peer IP x.x.x.x, VC ID xx
    RX
      34216908 packets 6774108588 bytes 0 drops
    TX
      79234824 packets 23633885654 bytes 0 drops

Nick

itdependsnetworks commented 7 years ago

Your solution seems makes sense. I think it is up to @ktbyers but If I were you I would put in a PR. I would also add to the PR to make sure that it is accommodating for up, down, admin down. I also presume you would need to null out the mac address.

ktbyers commented 7 years ago

@nicolaskarp Do you know what the pseudowire looks like when it is administratively down?

nicolaskarp commented 7 years ago

Hello @ktbyers I will look into this and try to find an example...

nicolaskarp commented 7 years ago

@ktbyers hmmm, the pseudowire is always up even if the L2VPN is down. So your new regex matching up/down is fine ;-) Nick

mirceaulinic commented 6 years ago

Hi @nicolaskarp - we are currently in the process of reunification, please check https://napalm-automation.net/reunification/. Going forward, we'd like to ask you to submit Pull Requests and Issue to the main repository: https://github.com/napalm-automation/napalm. I believe this has been already fixed via https://github.com/napalm-automation/napalm-ios/commit/5ca1d8e7aa269c33f1d5e2b1d658e9ba75b5566f. Otherwise, please feel free to reopen at https://github.com/napalm-automation/napalm/issues.

Thanks for understanding!