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

Unable to learn BGP - UnboundLocalError: local variable 'session_state' referenced before assignment #216

Open
ledgley opened this issue Jul 8, 2023 · 10 comments
Assignees

Comments

@ledgley
Copy link

ledgley commented Jul 8, 2023

genie learn bgp --testbed-file testbeds/testbed.yml

Traceback (most recent call last):
  File "src/genie/cli/commands/learn.py", line 365, in genie.cli.commands.learn.LearnCommand._retrieve_ops
  File "/Users/edgleyl/venv/pyats/lib/python3.9/site-packages/genie/libs/ops/bgp/nxos/bgp.py", line 1110, in learn
    self.make()
  File "/Users/edgleyl/venv/pyats/lib/python3.9/site-packages/genie/ops/base/base.py", line 103, in make
    self.maker.make(*args, **kwargs)
  File "src/genie/ops/base/maker.py", line 315, in genie.ops.base.maker.Maker.make
  File "src/genie/ops/base/maker.py", line 427, in genie.ops.base.maker.Maker._call_parser
  File "src/genie/metaparser/_metaparser.py", line 308, in genie.metaparser._metaparser.MetaParser.parse
  File "/Users/edgleyl/venv/pyats/lib/python3.9/site-packages/genie/libs/parser/nxos/show_bgp.py", line 2971, in cli
    [address_family]['session_state'] = session_state.lower()
UnboundLocalError: local variable 'session_state' referenced before assignment

Testbed

devices:
  switch001:
    connections:
      cli:
        ip: 10.20.0.1
        protocol: ssh
    credentials:
      default:
        password: '%ENC'
        username: admin
      enable:
        password: '%ENC'
    os: nxos
    type: nxos

Can also share snippets of config/output if necessary.

@ledgley
Copy link
Author

ledgley commented Jul 8, 2023

NXOS: version 9.3(5)

@ledgley
Copy link
Author

ledgley commented Jul 10, 2023

Seems like a workaround/solution is to instansiate the session_state variable, as below

            # For address family: VPNv4 Unicast
            m = p31.match(line)
            if m:
                session_state = ''
                if 'address_family' not in  parsed_dict['neighbor'][neighbor_id]:
                    parsed_dict['neighbor'][neighbor_id]['address_family'] = {}
                address_family = str(m.groupdict()['af']).lower()
                
                if address_family not in parsed_dict['neighbor'][neighbor_id]\
                    ['address_family']:
                    parsed_dict['neighbor'][neighbor_id]['address_family']\
                        [address_family] = {}

                parsed_dict['neighbor'][neighbor_id]['address_family']\
                    [address_family]['session_state'] = session_state.lower()
                if 'state_reason' in parsed_dict['neighbor'][neighbor_id]:
                    parsed_dict['neighbor'][neighbor_id]['address_family']\
                    [address_family]['state_reason'] = \
                        parsed_dict['neighbor'][neighbor_id]['state_reason']
                continue

@sumitsehgal123
Copy link

Hi .
Thanks for reaching out piestack support team, I will be looking at your ticket and get back to you .

@sumitsehgal123
Copy link

Hi ,
Please could you share the complete testbed.yaml file , and also please update your genie package and try it again .

pip install --upgrade genie

make sure that the credentials are correctly defined for the device

credentials:
  default:
    username: admin
    password: 'your_password_here'
  enable:
    password: 'your_enable_password_here'

@sumitsehgal123
Copy link

Hi ,
Please can you share the user output and show command to reproduce the issue .

2 similar comments
@sumitsehgal123
Copy link

Hi ,
Please can you share the user output and show command to reproduce the issue .

@sumitsehgal123
Copy link

Hi ,
Please can you share the user output and show command to reproduce the issue .

@ledgley
Copy link
Author

ledgley commented Aug 16, 2023

Company policy won't allow me to paste the configuration on public GitHub. Happy to raise a TAC, if you can direct me what category to raise it under.

@sumitsehgal123
Copy link

sumitsehgal123 commented Aug 25, 2023

Hi ,
Please can you share the devices output and show command on external mailer group [email protected] to reproduce the issue .

@sumitsehgal123
Copy link

Hi ,
Please can you share the devices output and show command on external mail group .

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