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

Better handling of errors when the config_context is loaded #198

Open
apast0r opened this issue Feb 20, 2025 · 0 comments
Open

Better handling of errors when the config_context is loaded #198

apast0r opened this issue Feb 20, 2025 · 0 comments

Comments

@apast0r
Copy link

apast0r commented Feb 20, 2025

Environment

  • Python version: 3.11
  • Nautobot version: 2.4.2
  • nautobot-plugin-nornir version: 2.1.0

Expected Behavior

Better handling of errors when the config is loaded.

Observed Behavior

Nornir play fails with a exception.

Steps to Reproduce

  1. Don't configure the default secret_access_type for a platform
  2. Launch a Golden Config backup job
  3. See the Advanced tab of the job result.

Traceback:

Traceback (most recent call last):
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_golden_config/jobs.py", line 173, in gc_repo_wrapper
    func(self, *args, **kwargs)
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_golden_config/jobs.py", line 287, in run
    config_backup(self)
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_golden_config/nornir_plays/config_backup.py", line 121, in config_backup
    replace_regex_dict[regex.platform.network_driver].append({"replace": regex.replace, "regex": regex.regex})
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nornir/init_nornir.py", line 71, in InitNornir
    inventory=load_inventory(config),
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nornir/init_nornir.py", line 20, in load_inventory
    inv = inventory_plugin(**config.inventory.options).load()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_plugin_nornir/plugins/inventory/nautobot_orm.py", line 205, in load
    host = self.create_host(device=device, cred=cred, params=self.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_plugin_nornir/plugins/inventory/nautobot_orm.py", line 265, in create_host
    username, password, secret (redacted) cred.get_device_creds(device=device)  # pylint:disable=unused-variable
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py", line 139, in get_device_creds
    configured_access_type = _get_access_type_value(device)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py", line 44, in _get_access_type_value
    access_type_str = device_obj.get_config_context()["nautobot_plugin_nornir"]["secret_access_type"].upper()
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'nautobot_plugin_nornir'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/extras/jobs.py", line 1234, in run_job
    result = job(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/nautobot/extras/jobs.py", line 160, in __call__
    return self.run(*args, **deserialized_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/nautobot/.local/lib/python3.11/site-packages/nautobot_golden_config/jobs.py", line 178, in gc_repo_wrapper
    raise NornirNautobotException(error_msg) from error
nornir_nautobot.exceptions.NornirNautobotException: `E3001:` General Exception handler, original error message ```'nautobot_plugin_nornir'```
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

1 participant