genieparser icon indicating copy to clipboard operation
genieparser copied to clipboard

Parser and API unable to parse OSPF area 0 if not in IP Address format

Open stefanopilla opened this issue 1 year ago • 5 comments

Scenario: C8K (IOS-XE 17.9) connected with OSPF routing enabled on multiple interfaces in Area0

Issue: Genie parser is unable to read Area 0 when this is not in IP Format and raise an invalid IP exception

Tried with Parsers and API and both have the same behaviour.

The following commands has been tested: show ip ospf show ip ospf neighbor detail show ip ospf interface

How to replicate:

testbed = Genie.init("testbed.yml")

device = testbed.devices['C8K-01'] device.connect()

ospf = device.api.get_ospf_interfaces() print(ospf)

2024-02-22 12:31:39,846: %UNICON-INFO: +++ C8K-01 with via 'cli': executing command 'show ip ospf interface brief' +++ show ip ospf interface brief Interface PID Area IP Address/Mask Cost State Nbrs F/C Gi2 1 0 10.10.12.1/24 1 DR 0/0 C8K-01# {'interface': 'Gi2', 'instance': '1', 'area': '0', 'address': '10.10.12.1/24', 'cost': '1', 'state': 'DR', 'nbrs_full': '0', 'nbrs_count': '0'} Traceback (most recent call last): File "/*****************", line 17, in ospf = device.api.get_ospf_interfaces() File "src/genie/conf/base/api.py", line 189, in genie.conf.base.api.API.getattr.wrapper_match File "src/genie/conf/base/api.py", line 187, in genie.conf.base.api.API.getattr.wrapper_match File "/home/localadmin/.venv/lib/python3.9/site-packages/genie/libs/sdk/apis/iosxe/ospf/get.py", line 513, in get_ospf_interfaces out = device.parse("show ip ospf interface brief") File "src/genie/conf/base/device.py", line 531, in genie.conf.base.device.Device.parse File "src/genie/conf/base/device.py", line 570, in genie.conf.base.device.Device._get_parser_output File "src/genie/conf/base/device.py", line 568, in genie.conf.base.device.Device._get_parser_output File "src/genie/metaparser/_metaparser.py", line 308, in genie.metaparser._metaparser.MetaParser.parse File "/home/localadmin/.venv/lib/python3.9/site-packages/genie/libs/parser/iosxe/show_ospf.py", line 1430, in cli area = str(IPAddress(str(group['area']))) File "/home/localadmin/.venv/lib/python3.9/site-packages/netaddr/ip/init.py", line 341, in init raise AddrFormatError('failed to detect a valid IP ' 'address from %r' % addr) netaddr.core.AddrFormatError: failed to detect a valid IP address from '0'

Troubleshooting: From the code https://github.com/CiscoTestAutomation/genieparser/blob/master/src/genie/libs/parser/iosxe/show_ospf.py#L1429 it seems that it tries to get the area of the ospf neighbour based on an IP format. However the area on the router for Area 0 gets converted to '0' by the IOS that is not a valid IP.

Reviewing the test for this function https://github.com/CiscoTestAutomation/genieparser/blob/master/src/genie/libs/parser/iosxe/tests/ShowIpOspfInterfaceBrief/cli/equal/golden_output_expected.py it seems is only being tested on the area using the IP format 0.0.0.8

Tested with 0.0.0.1 as Area and the parser works as expected

stefanopilla avatar Feb 22 '24 12:02 stefanopilla

I will be looking in to your issue. Kindly give me some time

sowmyadn010501 avatar Mar 04 '24 12:03 sowmyadn010501

Hello stefanopilla, I tried executing the command show ip ospf interface brief and i am not seeing the issue there and getting proper output as below, {'instance': {'1': {'areas': {'0.0.0.0': {'interfaces': {'GigabitEthernet2': {'ip_address': '10.10.12.1/24', 'cost': 1, 'state': 'DR', 'nbrs_full': 0, 'nbrs_count': 0}}}}}}} Kindly check and let me know.

sowmyadn010501 avatar Mar 06 '24 10:03 sowmyadn010501

Hi @sowmyadn010501 ,

I'm continuing to see this on multiple devices and IOS/IOS-XE version and not only in the lab environment.

I think the issue is only on the IOS/IOS-XE versions where the area gets converted from the '0.0.0.0' format to '0'.

As you can see in your output the area that the parser is pulling from the device is in the '0.0.0.0' format probably because the IOS version on your testing environment doesn't convert it to '0'. In my output provided above the area format on the ios is converted to '0' (even if I configured it to be 0.0.0.0). This happens only with area 0. No issues if area != 0.

I think that the solution would be to handle also the case where area is not in IP format and add the area 0 and 0.0.0.0 in the tests.

Here is another example from a production environment (CAT4506 with IOS-XE 15.2-7

<hostname>#show ip ospf interface brief 
Interface    PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Lo0          1     **0**               xx.yy.zz.x/32     1     LOOP  0/0
Vl112        1     **0**               xx.yy.zz.x/26    1     DR    1/1
Vl111        1     **0**               xx.yy.zz.x/26     1     DR    1/1
Vl705        1     **0**               xx.yy.zz.x/28   1     DR    1/1
Vl704        1     **0**               xx.yy.zz.x/26    1     DR    1/1
Vl703        1     **0**               xx.yy.zz.x/26   1     DR    1/1
Vl702        1     **0**               xx.yy.zz.x/24    1     DR    1/1
Vl701        1     **0**               xx.yy.zz.x/23    1     DR    1/1
Vl108        1     **0**               xx.yy.zz.x/24     1     DR    1/1
<hostname>#show run | sec router
router ospf 1
 network 10.0.0.0 0.255.255.255 **area 0**
<hostname>#
<hostname>#show version 
Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch  Software (cat4500e-UNIVERSALK9-M), Version 03.11.04.E RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2021 by Cisco Systems, Inc.
Compiled Mon 08-Mar-21 15:37 by prod_rel_team


ROM: 15.0(1r)SG(16)
<hostname> uptime is 29 weeks, 5 days, 19 hours, 40 minutes
System returned to ROM by power-on
System restarted at 04:50:43 MST Fri Aug 11 2023
System image file is "bootflash:/cat4500e-universalk9.SPA.03.11.04.E.152-7.E4.bin"
Jawa Revision 7, Snowtrooper Revision 0x0.0x1C

Output from the logger when I try to capture show ip ospf

461: <devbox>: 2024-03-07T08:03:14: %HELPERS-4-WARNING: %[pid=191810][pname=MainProcess]: [33mFailed to parse output for **'show ip ospf'** on device '<hostname>': **failed to detect a valid IP address from '0'**
461: devbox: 2024-03-07T08:03:14: %HELPERS-4-WARNING: %[pid=191810][pname=MainProcess]: [33mFailed to parse output for **'show ip ospf'** on device '<hostname>': **failed to detect a valid IP address from '0**'[0m[39m
473: devbox: 2024-03-07T08:03:15: %HELPERS-4-WARNING: %[pid=191810][pname=MainProcess]: [33mFailed to parse output for **'show ip ospf neighbor detail'** on device '<hostname>': failed to detect a valid IP address from '0'[0m[39m
485: devbox: 2024-03-07T08:03:17: %HELPERS-4-WARNING: %[pid=191810][pname=MainProcess]: [33mFailed to parse output for **'show ip ospf interface'** on device '<hostname>': failed to detect a valid IP address from '0'[0m[39m

Please let me know if you need any additional info on this.

Thank you!

stefanopilla avatar Mar 07 '24 07:03 stefanopilla

Sure. Let me check on this with my team and get back to you

sowmyadn010501 avatar Mar 07 '24 07:03 sowmyadn010501

Hi, As you mentioned about IOS/IOS-XE versions, can you tell me the specific version you are using?

sowmyadn010501 avatar Mar 07 '24 09:03 sowmyadn010501

Hi, Kindly give us the status on this.

sowmyadn010501 avatar Mar 11 '24 05:03 sowmyadn010501

Hi @sowmyadn010501 sorry for the delay on this one.

The IOS versions of the devices on which I face the issues are in my previous messages:

C8K (IOS-XE 17.9) CAT4506 with IOS-XE 15.2-7

Thank you

stefanopilla avatar Mar 11 '24 11:03 stefanopilla

Thank you. I will check and let you know.

sowmyadn010501 avatar Mar 11 '24 11:03 sowmyadn010501

Hi, As you can take a look at below analysis, I used the output what you shared and ran the command using mock data and its being tested on the area using the IP format only and not getting converted to '0'.

(24.1) bgl-ads-2978:/nobackup/sodn/workspace/Tickets/5921 > python mock.py 

2024-03-12 16:34:14,943: %UNICON-INFO: +++ mock logfile /tmp/mock-cli-20240312T163414943.log +++

2024-03-12 16:34:14,943: %UNICON-INFO: +++ Unicon plugin iosxe (unicon.internal.plugins.iosxe) +++
/nobackup/sodn/workspace/pyats_env/24.1/lib/python3.8/site-packages/unicon/bases/routers/connection.py:97: DeprecationWarning: Arguments 'username', 'enable_password','tacacs_password' and 'line_password' are now deprecated and replaced by 'credentials'.
  warnings.warn(message = "Arguments 'username', "
Router#

2024-03-12 16:34:15,988: %UNICON-INFO: +++ connection to spawn: mock_device_cli --os iosxe --mock_data_dir mock_data --state mock_commands, id: 140172449443264 +++

2024-03-12 16:34:15,988: %UNICON-INFO: connection to mock

2024-03-12 16:34:16,041: %UNICON-INFO: Learned hostname(s): 'Router'.

2024-03-12 16:34:16,041: %UNICON-INFO: +++ initializing handle +++

2024-03-12 16:34:17,107: %UNICON-INFO: +++ Router with via 'a': executing command 'show ip ospf interface brief' +++
show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Gi2 1 0 10.10.12.1/24 1 DR 0/0
Router#
{'instance': {'1': {'areas': {'0.0.0.0': {'interfaces': {'GigabitEthernet2': {'ip_address': '10.10.12.1/24', 'cost': 1, 'state': 'DR', 'nbrs_full': 0, 'nbrs_count': 0}}}}}}}

sowmyadn010501 avatar Mar 12 '24 11:03 sowmyadn010501

Hi,

not sure with which data you're tried but the conversion is on the IOS side so the parsers is expecting to receive it into IPAddress format. If you spin up a C8Kv with IOS-XE 17.9 and you try to configure OSPF with area 0.0.0.0 the IOS-XE will convert it to '0' (you can see it from my output above) and then you will face the issue. Here is the output from another device on which I just faced the same issue:

Software Version: Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500-ENTSERVICESK9-M), Version 15.0(2)SG11, RELEASE SOFTWARE (fc2)

this is the code I'm running to reproduce:

from pyats.topology import loader

testbed = loader.load("./vars/testbed_test.yml")

device = testbed.devices['device-hostname']
device.connect(via="ssh")

ospf = device.parse("show ip ospf neighbor detail")

here is the full output:


(venv) parallels@devbox:/home/user$ python3 test_ospf.py 

2024-03-12 20:34:03,976: %UNICON-INFO: +++ device_hostname logfile /tmp/device_hostname-cli-20240312T203403976.log +++

2024-03-12 20:34:03,977: %UNICON-INFO: +++ Unicon plugin ios (unicon.plugins.ios) +++
([email protected]) Password:

2024-03-12 20:34:06,098: %UNICON-INFO: +++ connection to spawn: ssh -l admin 192.168.1.1 -o KexAlgorithms=diffie-hellman-group1-sha1,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1, id: 139852496081104 +++

2024-03-12 20:34:06,099: %UNICON-INFO: connection to device_hostname

C
Warning!  
This is a private network access point and is reserved for authorized
personnel only. Any person attempting to access this network without
permission will be prosecuted under state and federal laws covering
computer tampering and illegal access.
If you are not authorized to use this device disconnect NOW!
(device_hostname)

device_hostname#

2024-03-12 20:34:07,261: %UNICON-INFO: +++ initializing handle +++

2024-03-12 20:34:07,397: %UNICON-INFO: +++ device_hostname with via 'ssh': executing command 'term length 0' +++
term length 0
device_hostname#

2024-03-12 20:34:07,927: %UNICON-INFO: +++ device_hostname with via 'ssh': executing command 'term width 0' +++
term width 0
device_hostname#

2024-03-12 20:34:08,459: %UNICON-INFO: +++ device_hostname with via 'ssh': executing command 'show version' +++
show version
Cisco IOS Software, Catalyst 4500 L3 Switch Software (cat4500-ENTSERVICESK9-M), Version 15.0(2)SG11, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Mon 24-Oct-16 09:48 by prod_rel_team
Image text-base: 0x10000000, data-base: 0x123AECA8

ROM: 12.2(31r)SGA7
Pod Revision 16, Force Revision 31, Tie Revision 32

device_hostname uptime is 1 year, 18 weeks, 1 day, 20 hours, 16 minutes
Uptime for this control processor is 1 year, 18 weeks, 1 day, 19 hours, 32 minutes
System returned to ROM by reload
System restarted at 19:18:05 EDT Sat Nov 5 2022
System image file is "bootflash:cat4500-entservicesk9-mz.150-2.SG11.bin"


This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
[email protected].

cisco WS-C4510R-E (MPC8540) processor (revision 13) with 524288K bytes of memory.
Processor board ID XXXXXXXXXX
MPC8540 CPU at 800Mhz, Supervisor V-10GE
Last reset from Reload
16 Virtual Ethernet interfaces
262 Gigabit Ethernet interfaces
2 Ten Gigabit Ethernet interfaces
511K bytes of non-volatile configuration memory.

Configuration register is 0x2102

device_hostname#

2024-03-12 20:34:08,839: %UNICON-INFO: +++ device_hostname with via 'ssh': configure +++
config term
Enter configuration commands, one per line.  End with CNTL/Z.
device_hostname(config)#no logging console
device_hostname(config)#line console 0
device_hostname(config-line)#exec-timeout 0
device_hostname(config-line)#line vty 0 4
device_hostname(config-line)#exec-timeout 0
device_hostname(config-line)#end
device_hostname#

2024-03-12 20:34:12,626: %UNICON-INFO: +++ device_hostname with via 'ssh': executing command 'show ip ospf neighbor detail' +++
show ip ospf neighbor detail
 Neighbor 192.168.111.3, interface address 192.168.37.66
    In the area 0 via interface Vlan112
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 192.168.37.66 BDR is 192.168.37.67
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:34
    Neighbor is up for 9w2d    
    Index 17/17, retransmission queue length 0, number of retransmission 4
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 13, maximum is 13
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.37.2
    In the area 0 via interface Vlan111
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.37.2 BDR is 10.32.37.3
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:32
    Neighbor is up for 9w2d    
    Index 16/16, retransmission queue length 0, number of retransmission 3
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 14, maximum is 14
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 109.1.1.2, interface address 10.38.111.21
    In the area 0 via interface GigabitEthernet2/2
    Neighbor priority is 0, State is FULL, 6 state changes
    DR is 0.0.0.0 BDR is 0.0.0.0
    Options is 0x2 in Hello (E-bit )
    Options is 0x2 in DBD (E-bit )
    Dead timer due in 00:00:33
    Neighbor is up for 7w2d    
    Index 13/13, retransmission queue length 0, number of retransmission 5
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 13, maximum is 37
    Last retransmission scan time is 0 msec, maximum is 0 msec
    Number of retransmissions for last link state request packet 1
 Neighbor 109.1.1.1, interface address 10.38.111.29
    In the area 0 via interface GigabitEthernet2/1
    Neighbor priority is 0, State is FULL, 6 state changes
    DR is 0.0.0.0 BDR is 0.0.0.0
    Options is 0x2 in Hello (E-bit )
    Options is 0x2 in DBD (E-bit )
    Dead timer due in 00:00:33
    Neighbor is up for 7w2d    
    Index 14/14, retransmission queue length 0, number of retransmission 2
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 0, maximum is 1
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.111.242
    In the area 0 via interface Vlan705
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.111.242 BDR is 10.38.111.243
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:31
    Neighbor is up for 1y18w   
    Index 4/4, retransmission queue length 0, number of retransmission 18
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 2, maximum is 24
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.111.66
    In the area 0 via interface Vlan704
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.111.66 BDR is 10.38.111.67
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:38
    Neighbor is up for 1y18w   
    Index 6/6, retransmission queue length 0, number of retransmission 15
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 13, maximum is 18
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.111.130
    In the area 0 via interface Vlan703
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.111.130 BDR is 10.38.111.131
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:34
    Neighbor is up for 1y18w   
    Index 8/8, retransmission queue length 0, number of retransmission 19
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 15, maximum is 19
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.32.10
    In the area 0 via interface Vlan702
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.32.10 BDR is 10.32.32.11
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:36
    Neighbor is up for 1y18w   
    Index 5/5, retransmission queue length 0, number of retransmission 18
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 15, maximum is 24
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.108.10
    In the area 0 via interface Vlan701
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.108.10 BDR is 10.38.108.11
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:38
    Neighbor is up for 1y18w   
    Index 2/2, retransmission queue length 0, number of retransmission 18
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 15, maximum is 20
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.38.2
    In the area 0 via interface Vlan108
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.38.2 BDR is 10.32.38.3
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:33
    Neighbor is up for 1y18w   
    Index 9/9, retransmission queue length 0, number of retransmission 18
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 14, maximum is 20
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.39.130
    In the area 0 via interface Vlan107
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.39.130 BDR is 10.32.39.131
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:32
    Neighbor is up for 1y18w   
    Index 3/3, retransmission queue length 0, number of retransmission 15
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 12, maximum is 24
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.39.2
    In the area 0 via interface Vlan106
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.39.2 BDR is 10.32.39.3
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:35
    Neighbor is up for 1y18w   
    Index 10/10, retransmission queue length 0, number of retransmission 13
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 14, maximum is 21
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.111.194
    In the area 0 via interface Vlan105
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.111.194 BDR is 10.38.111.195
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:39
    Neighbor is up for 1y18w   
    Index 7/7, retransmission queue length 0, number of retransmission 17
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 14, maximum is 24
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.32.34.10
    In the area 0 via interface Vlan104
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.32.34.10 BDR is 10.32.34.11
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:36
    Neighbor is up for 1y18w   
    Index 15/15, retransmission queue length 0, number of retransmission 15
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 16, maximum is 20
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.110.10
    In the area 0 via interface Vlan103
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.110.10 BDR is 10.38.110.11
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:38
    Neighbor is up for 1y18w   
    Index 1/1, retransmission queue length 0, number of retransmission 17
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 13, maximum is 20
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.106.2
    In the area 0 via interface Vlan102
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.106.2 BDR is 10.38.106.3
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:38
    Neighbor is up for 1y18w   
    Index 12/12, retransmission queue length 0, number of retransmission 17
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 15, maximum is 25
    Last retransmission scan time is 0 msec, maximum is 0 msec
 Neighbor 192.168.111.3, interface address 10.38.104.10
    In the area 0 via interface Vlan101
    Neighbor priority is 1, State is FULL, 6 state changes
    DR is 10.38.104.10 BDR is 192.168.1.1
    Options is 0x12 in Hello (E-bit L-bit )
    Options is 0x52 in DBD (E-bit L-bit O-bit)
    LLS Options is 0x1 (LR)
    Dead timer due in 00:00:34
    Neighbor is up for 1y18w   
    Index 11/11, retransmission queue length 0, number of retransmission 15
    First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
    Last retransmission scan length is 8, maximum is 25
    Last retransmission scan time is 0 msec, maximum is 0 msec
device_hostname#
Traceback (most recent call last):
  File "/home/user/test_ospf.py", line 9, in <module>
    ospf = device.parse("show ip ospf neighbor detail")
  File "src/genie/conf/base/device.py", line 531, in genie.conf.base.device.Device.parse
  File "src/genie/conf/base/device.py", line 570, in genie.conf.base.device.Device._get_parser_output
  File "src/genie/conf/base/device.py", line 568, in genie.conf.base.device.Device._get_parser_output
  File "src/genie/metaparser/_metaparser.py", line 308, in genie.metaparser._metaparser.MetaParser.parse
  **File "/home/user/venv/lib/python3.9/site-packages/genie/libs/parser/iosxe/show_ospf.py", line 4328, in cli
    area = str(IPAddress(str(m.groupdict()['area'])))
  File "/home/user/venv/lib/python3.9/site-packages/netaddr/ip/__init__.py", line 341, in __init__
    raise AddrFormatError('failed to detect a valid IP ' 'address from %r' % addr)
netaddr.core.AddrFormatError: failed to detect a valid IP address from '0'**

If I go on line 4328 on the /home/user/venv/lib/python3.9/site-packages/genie/libs/parser/iosxe/show_ospf.py

 # In the area 0 via interface GigabitEthernet2
            # In the area 0 via interface TenGigabitEthernet3/1/1, BFD enabled
            m = p2.match(line)
            if m:
                area = str(IPAddress(str(m.groupdict()['area']))) << -- Here is the issue
                interface = str(m.groupdict()['interface'])
                instance = None
                router_id = None
                bfd_state = m.groupdict().get('bfd_state', None)
                # Get OSPF process ID from 'show ip ospf interface'
                cmd = 'show ip ospf interface {}'.format(interface)
                out = self.device.execute(cmd)

As a proof that the problem is the format of the area received by the parser you can also run this simple script:

from netaddr import IPAddress, IPNetwork

area_ip = '0.0.0.0'
print(str(IPAddress(str(area_ip))))

area_no_ip = '0'
print(str(IPAddress(str(area_no_ip))))
(venv) parallels@devbox:/home/user$ python3 test_area.py 
0.0.0.0
Traceback (most recent call last):
  File "/home/user/test_area.py", line 22, in <module>
    print(str(IPAddress(str(area_no_ip))))
  File "/home/user/venv/lib/python3.9/site-packages/netaddr/ip/__init__.py", line 341, in __init__
    **raise AddrFormatError('failed to detect a valid IP ' 'address from %r' % addr)
netaddr.core.AddrFormatError: failed to detect a valid IP address from '0'**

as you can see the error message is the same so a possibile solution might be a check that if the area is '0' is should be converted to '0.0.0.0' by the script.

Let me know if there's any additional information you need.

stefanopilla avatar Mar 12 '24 20:03 stefanopilla

Hi, i tried with sample script you shared earlier as you can see in below screen shot i am getting it correctly and 0 has been converting in to into the ip format

image

Also can you share me the EXACT testbed device schema without the ip/port.

sowmyadn010501 avatar Mar 13 '24 08:03 sowmyadn010501

That is very strange... I tried with both netaddr version 1.0.0 and 1.2.1 (latest) and I'm still having the issue. Python 3.9.18.

What Python and netaddr version are you using?

image

here is the device schema in my testbed:

  hostname:
    alias: hostname
    type: switch
    os: iosxe
    connections:
      defaults:
        class: unicon.Unicon
      ssh:
        protocol: "ssh"
        ip: "x.x.x.x"
        hostname: "hostname"
        command: "ssh -l admin x.x.x.x -o KexAlgorithms=diffie-hellman-group1-sha1,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1"
      arguments:
        init_exec_commands: []
        init_config_commands: []
    credentials:
      default:
        username: admin
        password: password

stefanopilla avatar Mar 14 '24 21:03 stefanopilla

Hi, As for the python and netaddr versions i am using below versions, netaddr 0.10.1 Python 3.8.2.

sowmyadn010501 avatar Mar 19 '24 06:03 sowmyadn010501

Hi, we pyATS team only support netaddr until version 0.10.1. Can you please let me know whether you updated the netaddr version by yourself?

sowmyadn010501 avatar Mar 19 '24 14:03 sowmyadn010501

Hi, Kindly give us the update on this

sowmyadn010501 avatar Mar 22 '24 08:03 sowmyadn010501

Hi, Kindly give us the update

sowmyadn010501 avatar Mar 25 '24 07:03 sowmyadn010501

Hi, Kindly give us the update on the issue.

sowmyadn010501 avatar Mar 27 '24 05:03 sowmyadn010501

Hi, Kindly give us the update

sowmyadn010501 avatar Mar 28 '24 12:03 sowmyadn010501

You are not responding; hence I am closing this ticket. I hope you are not facing this issue anymore, but if you are still facing the same issue, kindly let me know, I'll re-open the ticket. If you are facing any other issues, kindly open a new ticket. Thank you.

sowmyadn010501 avatar Mar 29 '24 05:03 sowmyadn010501

Hi @sowmyadn010501 ,

sorry for the delay but I have been out of office for the last 2 weeks. I didn't upgrade netaddr by myself but I found that I was using netaddr 1.0.0 (maybe it got upgraded by some other module I'm using). I downgraded to 0.10.1 and the issue is not present anymore and I'm getting the results as you.

I would still suggest to add a test for Area '0' in the tests given that we know that it will be an issue when pyATS will start to use netaddr version > 0.10.1.

Thank you for troubleshooting this with me. Appreciated your help.

stefanopilla avatar Apr 02 '24 09:04 stefanopilla