CiscoTestAutomation / pyats

Cisco DevNet pyATS Test Framework Bug Tracker
Apache License 2.0
148 stars 31 forks source link

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

Open ledgley opened 1 year ago

ledgley commented 1 year ago

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 commented 1 year ago

NXOS: version 9.3(5)

ledgley commented 1 year ago

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 commented 1 year ago

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

sumitsehgal123 commented 1 year ago

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 commented 1 year ago

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

sumitsehgal123 commented 1 year ago

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

sumitsehgal123 commented 1 year ago

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

ledgley commented 1 year ago

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 commented 1 year ago

Hi , Please can you share the devices output and show command on external mailer group pyats-support-ext@cisco.com to reproduce the issue .

sumitsehgal123 commented 1 year ago

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