napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

Fix for zero interfaces in VRF causing TypeError in get_network_inter… #135

Closed biwhite closed 7 years ago

biwhite commented 7 years ago

I found a VRF without any interfaces in it causes this to happen.

INFO:ncclient.operations.rpc:Requesting 'ExecuteRpc' Traceback (most recent call last): File "./modeller.py", line 140, in sys.exit(main()) File "./modeller.py", line 114, in main data = nd.get_network_instances() File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 1541, in get_network_instances intrf_name: {} for intrf_name in ri_interfaces if intrf_name TypeError: 'NoneType' object is not iterable Segmentation fault (core dumped)

biwhite commented 7 years ago

Actually, it looks like it should be a list rather than a dict

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.04%) to 85.323% when pulling 5baea7b63be08e9feaefcc45f03d4eda06f522ec on biwhite:vrf-zero-interfaces into 26c628b0ab7ed7d7636a0697ea6f0f626e428565 on napalm-automation:develop.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.2%) to 85.448% when pulling 5baea7b63be08e9feaefcc45f03d4eda06f522ec on biwhite:vrf-zero-interfaces into 26c628b0ab7ed7d7636a0697ea6f0f626e428565 on napalm-automation:develop.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.2%) to 85.448% when pulling 24b6636d758a77d4a2646218d4d5846ed10cd298 on biwhite:vrf-zero-interfaces into 26c628b0ab7ed7d7636a0697ea6f0f626e428565 on napalm-automation:develop.

biwhite commented 7 years ago

This fixes the case when there's zero or 1 interface in a VRF. If there's zero, the previous code threw an exception. If there was one, it would return each character of that interface name as a separate interface. This PR addresses both issues, by ensuring the variable iterated over is set to a list containing zero or more interfaces.

mirceaulinic commented 7 years ago

Thanks @biwhite