Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-XR cef parser throws error: 'prefix_dict' referenced before assignment #737

Open
naveci opened this issue Mar 20, 2023 · 12 comments
Open
Assignees

Comments

@naveci
Copy link

naveci commented Mar 20, 2023

Hi,

I ran into an issue today trying to parse a CEF table on an IOS-XR device. I can see the CLI output, but then Python returns the following data when using the Pyats CLI:

Issue with the parser show cef ipv4 10.255.255.224/32 detail

Traceback (most recent call last):
  File "src/genie/cli/commands/parser.py", line 339, in genie.cli.commands.parser.ParserCommand.parse
  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 "~/coding/pyats/.venv/lib/python3.9/site-packages/genie/libs/parser/iosxr/show_routing.py", line 230, in cli
    prefix_dict.update(
UnboundLocalError: local variable 'prefix_dict' referenced before assignment

The returned data contains a dict of with the device name as key and then an empty dict as the value. No other data is returned.

My version:

 ~/coding/pyats/src  pyats version check --outdated                                                                                                                                                                                                                                                ✔  pyats   14:47:22 
You are currently running pyATS version: 23.2
Python: 3.9.6 [64bit]

Checking for outdated packages...

  Package                      Version Latest
  ---------------------------- ------- ------
  genie                        23.2          
  genie.libs.clean             23.2          
  genie.libs.conf              23.2          
  genie.libs.filetransferutils 23.2          
  genie.libs.health            23.2          
  genie.libs.ops               23.2          
  genie.libs.parser            23.2          
  genie.libs.robot             23.2          
  genie.libs.sdk               23.2          
  genie.telemetry              23.2          
  genie.trafficgen             23.2          
  pyats                        23.2          
  pyats.aereport               23.2          
  pyats.aetest                 23.2          
  pyats.async                  23.2          
  pyats.connections            23.2          
  pyats.contrib                23.2          
  pyats.datastructures         23.2          
  pyats.easypy                 23.2          
  pyats.kleenex                23.2          
  pyats.log                    23.2          
  pyats.reporter               23.2          
  pyats.results                23.2          
  pyats.robot                  23.2          
  pyats.tcl                    23.2          
  pyats.topology               23.2          
  pyats.utils                  23.2          
  unicon                       23.2          
  unicon.plugins               23.2          
  yang.connector               23.2          

All your packages are up to date!
@naveci
Copy link
Author

naveci commented Mar 20, 2023

To provide some more info, here's the CLI output coming back from the device as displayed in my terminal

show cef ipv4 10.255.255.224/32 detail
Mon Mar 20 14:47:46.405 CET
10.255.255.224/32, version 31880810, drop adjacency, internal 0x1000001 0x30 (ptr 0x79189280) [1], 0x0 (0x0), 0x0 (0x0)
 Updated Mar 20 11:11:27.890
 Prefix Len 32, traffic index 0, precedence n/a, priority 3
  gateway array (0x782f1468) reference count 1, flags 0x2012, source rib (7), 0 backups
                [1 type 3 flags 0xc8401 (0x78399948) ext 0x0 (0x0)]
  LW-LDI[type=0, refc=0, ptr=0x0, sh-ldi=0x0]
  gateway array update type-time 3 Mar 20 14:47:43.154
 LDI Update time Mar 20 11:11:27.890
   via 1.3.2.1/32, 0 dependencies, recursive [flags 0x4]
    path-idx 0 NHID 0x0 [0x781b57c8 0x0]
    unresolved

    Load distribution: 0 (refcount 1)

    Hash  OK  Interface                 Address
    0     Y   recursive                 drop

The above IP addresses are bogus, but I want to check if I can find non-resolved routes in CEF.
However, the error is exactly the same for actual routes. The problem is that in line 230 p2 wants to add to a dict, but the dict doesn't exist yet. There doesn't seem to be a match on line 209. I'm no regex expert, but I feel like there might be something wrong with those statements.

@naveci naveci changed the title IOS-XR cef parser throws fatal error: 'prefix_dict' referenced before assignment IOS-XR cef parser throws error: 'prefix_dict' referenced before assignment Mar 20, 2023
@ParimiNeeraja
Copy link

Hi naveci, I am looking at your ticket and reviewing it, Please let me know are you facing the issue still or not ?

@ParimiNeeraja
Copy link

Hi naveci,

Your cli output "10.255.255.224/32, version 31880810, drop adjacency, internal 0x1000001 0x30" was not matching the regular expression what was there,
"p1 = re.compile(r'^(?P[\d./]+), +version +(?P[\d]+)'
', +internal +(?P.+)+$' "
need to add the " drop adjacency " in regular expression

@naveci
Copy link
Author

naveci commented Apr 13, 2023

Hi @ParimiNeeraja

yes, still an issue and a reason for me not to use this feature right now.
Keep in mind that this entry is not your typical entry. This is the result of a route that's not resolvable in CEF. So the idea is that it can handle both resolved and un-resolved routes.

Thanks =)

@ParimiNeeraja
Copy link

Hi,

Could you please raise the PR, will contribute with reviews to merge.

@naveci
Copy link
Author

naveci commented Apr 24, 2023

Hi,

Could you please raise the PR, will contribute with reviews to merge.

I'm sorry, it's unclear for me what to raise a PR for. I don't have any suggested code change.

@ParimiNeeraja
Copy link

Hi @naveci ,

As per parser schema of this command (show cef ipv4 10.255.255.224/32 detail) , changes are required as per cli output.
Ex: drop key is missing and source rib key is missing ,
for this changes in schema raise a request to genieparser team and raise a PR.

@naveci
Copy link
Author

naveci commented Apr 25, 2023

Hi @ParimiNeeraja,

I understand that the regex is incomplete. However, I'm not an expert at regex and I don't have the solution for this right now. Hence why I'm reporting it as an issue.

To raise a PR, some branch or fork has to be merged with another. I don't have a branch or fork to merge right now, as I don't have any proposed code change. Furthermore, I'm reporting this issue within the genieparser repository. I'm very sorry, but these directions really aren't clear to me. If you tell me to open a TAC case, that I can do. But as far as I'm aware, I'm here at the right place to report an issue to which I don't have the solution yet myself.

@ParimiNeeraja
Copy link

Hi @naveci ,

Thanks for reporting the issue. We will add this to our backlog and keep you posted on when it will be released.

@ParimiNeeraja
Copy link

ParimiNeeraja commented May 8, 2023

Hi @naveci ,

Could you please share the full cli output(show cef ipv4 10.255.255.224/32 detail) for the issue you are facing. So that we can help you in fixing the issue.

@naveci
Copy link
Author

naveci commented May 8, 2023

Hi,

I believe the output was already somewhere in this topic, but here's one I just pulled from the router.

RP/0/RSP0/CPU0:pe17#show cef ipv4 10.255.255.224/32 detail
Mon May  8 16:14:10.095 CEST
10.255.255.224/32, version 2, drop adjacency, internal 0x1000001 0x30 (ptr 0x79125568) [1], 0x0 (0x0), 0x0 (0x0)
 Updated May  1 22:06:21.879
 Prefix Len 32, traffic index 0, precedence n/a, priority 3
  gateway array (0x78990bd8) reference count 1, flags 0x2012, source rib (7), 0 backups
                [1 type 3 flags 0xc8401 (0x78a41ba0) ext 0x0 (0x0)]
  LW-LDI[type=0, refc=0, ptr=0x0, sh-ldi=0x0]
  gateway array update type-time 3 May  8 16:14:00.480
 LDI Update time May  1 22:06:21.879
   via 1.3.2.1/32, 0 dependencies, recursive [flags 0x4]
    path-idx 0 NHID 0x0 [0x7885f7c8 0x0]
    unresolved

    Load distribution: 0 (refcount 1)

    Hash  OK  Interface                 Address
    0     Y   recursive                 drop           
RP/0/RSP0/CPU0:pe17#

@ParimiNeeraja
Copy link

ParimiNeeraja commented Jun 27, 2023

Hi @naveci ,

I Resolved this issue with your output. It will be available on 23.7 released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants