napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

Fixing parsing of shutdown DHCP interfaces #183

Closed gjim83 closed 7 years ago

gjim83 commented 7 years ago

When an interface is set to take its IP from DHCP, but is shut down, an exception will get raised because this command will return no output since there's no IP address but then the code will try to split the output and get some of the list elements.

The result is:

  File "/home/vagrant/.local/lib/python3.5/site-packages/napalm_ios/ios.py", line 947, in get_interfaces_ip
     ip_address, subnet = int_fields[3].split(r'/')
IndexError: list index out of range
coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.1%) to 70.619% when pulling 01d680a1fcd08d33e72c56b5ca31ad2a462b3bfa on gjim83:develop into 83673534da1dcd89a13ae06d956bb40c63505b11 on napalm-automation:develop.

ktbyers commented 7 years ago

@gjim83 This looks good...do you have any handy test data (so I can add this to the unit tests):

         command = 'show ip interface brief'  
         show_command = "show run interface {0}".format(interface)
         cmd = "show interface {} | in Internet address is".format(interface)

It would be good to get the output of the above three commands with one normal interface and one in the DHCP state.

gjim83 commented 7 years ago

sure, will post some soon

gjim83 commented 7 years ago

@ktbyers DHCP interface:

FOO-RT01#sh run int GigabitEthernet0 
Building configuration...

Current configuration : 95 bytes
!
interface GigabitEthernet0
 vrf forwarding Mgmt-intf
 ip address dhcp
 negotiation auto
end
FOO-RT01#show interface GigabitEthernet0 | in Internet address is
FOO-RT01#

Usual manual config:

FOO-RT01#sh run interface GigabitEthernet0/0/0
Building configuration...

Current configuration : 274 bytes
!
interface GigabitEthernet0/0/0
 description Primary Connection to FOO-RS01 G1/0/1
 backup interface Vlan200
 ip address 172.29.91.82 255.255.255.240
 no ip redirects
 no ip proxy-arp
 ip flow monitor MONITOR1 input
 ip flow monitor MONITOR1 output
 negotiation auto
end
FOO-RT01#show interface GigabitEthernet0/0/0 | in Internet address is     
  Internet address is 172.29.91.82/28
FOO-RT01
gjim83 commented 7 years ago
FOO-RT01#sh ip int br
Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0/0   172.29.91.82    YES NVRAM  up                    up      
GigabitEthernet0/0/1   unassigned      YES NVRAM  administratively down down    
GigabitEthernet0/0/2   10.63.54.190    YES NVRAM  up                    up      
GigabitEthernet0/0/3   10.240.25.121   YES NVRAM  up                    up      
GigabitEthernet0/3/0   unassigned      YES unset  up                    up      
GigabitEthernet0/3/1   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/2   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/3   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/4   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/5   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/6   unassigned      YES unset  administratively down down    
GigabitEthernet0/3/7   unassigned      YES unset  administratively down down    
ucse1/0/0              unassigned      YES NVRAM  administratively down down    
ucse1/0/1              unassigned      YES NVRAM  administratively down down    
GigabitEthernet0       unassigned      YES NVRAM  down                  down 
Loopback0              172.29.1.81     YES NVRAM  up                    up      
Tunnel30522            172.29.67.166   YES NVRAM  up                    up      
Vlan1                  unassigned      YES NVRAM  administratively down down    
Vlan200                172.29.91.82    YES NVRAM  standby mode          down

Btw, thos UCS blades interfaces also cause another issue when parsing, that I will soon post a PR about.

mirceaulinic commented 7 years ago

@ktbyers is this okay to include it into 0.8.0?