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

Fixing napalm extra args validation #292

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

theandrelima
Copy link

fixes #291

Trying to pass napalm specific options using [network.napalm_extras] in the network_importer.toml file, throws the following error:

Traceback (most recent call last):
  File "/usr/local/bin/network-importer", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/network_importer/cli.py", line 104, in apply
    ni.build_inventory(limit=limit)
  File "/usr/local/lib/python3.7/site-packages/network_importer/performance.py", line 67, in timed
    result = method(*args, **kw)
  File "/usr/local/lib/python3.7/site-packages/network_importer/main.py", line 70, in build_inventory
    "settings": config.SETTINGS.inventory.settings,
  File "/usr/local/lib/python3.7/site-packages/nornir/init_nornir.py", line 72, in InitNornir
    inventory=load_inventory(config),
  File "/usr/local/lib/python3.7/site-packages/nornir/init_nornir.py", line 20, in load_inventory
    inv = inventory_plugin(**config.inventory.options).load()
  File "/usr/local/lib/python3.7/site-packages/network_importer/adapters/nautobot_api/inventory.py", line 27, in __init__
    *args, **kwargs,
  File "/usr/local/lib/python3.7/site-packages/network_importer/inventory.py", line 85, in __init__
    elif isinstance(dict, self.global_group.connection_options["napalm"].extras):
TypeError: isinstance() arg 2 must be a type or tuple of types

It seems the problem is the code in the exactly the highlighted line:

elif isinstance(dict, self.global_group.connection_options["napalm"].extras):

isintance() should receive the object first and the type we are trying to assess as a second argument. That order is inverted and dict is passed as the first argument, whereas self.global_group.connection_options["napalm"].extras is the second.

I can see the same thing happening in line 90 again, by the way.

Copy link

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me - thanks for the fix!

@chadell chadell merged commit 72e1ce2 into networktocode:develop Jan 27, 2023
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

Successfully merging this pull request may close these issues.

Trying to use network.napalm_extras configs will cause an error
3 participants