networktocode/netutils

Attempts to parse config throws AttributeError

Closed this issue · 3 comments

Environment

  • Python version: 3.10
  • netutils version: 1.6.0

Expected Behavior

Device section configuration is parsed and returned.

Observed Behavior

An error is thrown stating the following:

[2024-02-08 22:09:55,562: ERROR/ForkPoolWorker-5] Host 'test': task 'RENDER COMPLIANCE TASK GROUP' failed with traceback:
Traceback (most recent call last):
2024-02-08T22:09:55.563627949Z   File "/usr/local/lib/python3.10/site-packages/nornir/core/task.py", line 99, in start
    r = self.task(self, **self.params)
  File "/usr/local/lib/python3.10/site-packages/nautobot_golden_config/utilities/db_management.py", line 15, in inner
    func(*args, **kwargs)
2024-02-08T22:09:55.563641188Z   File "/usr/local/lib/python3.10/site-packages/nautobot_golden_config/nornir_plays/config_compliance.py", line 155, in run_compliance
    _intended = get_config_element(rule, intended_cfg, obj, logger)
2024-02-08T22:09:55.563662372Z   File "/usr/local/lib/python3.10/site-packages/nautobot_golden_config/nornir_plays/config_compliance.py", line 78, in get_config_element
    config_element = section_config(rule, config, obj.platform.network_driver_mappings["netmiko"])
2024-02-08T22:09:55.563669009Z   File "/usr/local/lib/python3.10/site-packages/netutils/config/compliance.py", line 439, in section_config
    if not match and line.config_line.startswith(line_start):
AttributeError: 'NoneType' object has no attribute 'startswith'

RENDER COMPLIANCE TASK GROUP failed: 'NoneType' object has no attribute 'startswith'
[2024-02-08 22:09:55,568: ERROR/ForkPoolWorker-5] RENDER COMPLIANCE TASK GROUP failed: 'NoneType' object has no attribute 'startswith'

Specifically this is being seen with a Cisco Nexus configuration. After some troubleshooting I've found that this appears to happen when the configuration being parsed doesn't contain any of the section elements that are defined in the feature, ie if you're looking for AAA in the configuration and no lines are found that match the provided strings.

Steps to Reproduce

  1. Setup Nautobot and Golden Config App.
  2. Add a configuration that contains only some small configuration sections. Purposefully leave out the section being parsed for.
  3. Attempt to run section_config and see results.

Actually, in further testing I've found that it's not actually missing config. Still trying to track down exactly what is causing it.

@jdrew82 can you just create a PR with the config that does not parse correctly, like this one: 1cd4ab8

We have found it helpful to work backwards from a failing test

@jdrew82 if you find additional info, feel free to re-open (or better yet, create a failing test PR like 1cd4ab8 , but not clear at this point what the challenge is.