networktocode/network-importer

Check Succeeds but Apply Fails with Juniper EX4200

b-higgins opened this issue · 4 comments

Environment

  • Python version: 3.8.10
  • Network Importer version: 3.0.0

Steps to Reproduce

  1. Create fresh Ubuntu virtual
  2. Follow https://blog.networktocode.com/post/installing-nautobot/
  3. Install https://github.com/nautobot/nautobot-plugin-device-onboarding
  4. Create just enough in nautobot to onboard a switch
  5. Onboard "switch" (Device Type, Manufacturer, etc auto created)
  6. Install https://github.com/networktocode/network-importer
  7. run network-importer inventory --check-connectivity to confirm communications
  8. run network-importer check --update-configs to confirm things appear to work
  9. run network-importer apply --update-configs

Expected Behavior

Expected network-importer would populate Nautobot with the data it was able to parse with the "check" function

Observed Behavior

After detecting several CABLE which it marked SKIPPING, the program crashed with a traceback (below). Full debug output included in attached files.

Traceback (most recent call last):
File "/opt/nautobot/bin/network-importer", line 8, in
sys.exit(main())
File "/opt/nautobot/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/opt/nautobot/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/nautobot/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/nautobot/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/nautobot/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/nautobot/lib/python3.8/site-packages/network_importer/cli.py", line 108, in apply
ni.sync()
File "/opt/nautobot/lib/python3.8/site-packages/network_importer/main.py", line 142, in sync
self.sot.sync_from(self.network, diff_class=NetworkImporterDiff)
File "/opt/nautobot/lib/python3.8/site-packages/diffsync/init.py", line 464, in sync_from
result = syncer.perform_sync()
File "/opt/nautobot/lib/python3.8/site-packages/diffsync/helpers.py", line 251, in perform_sync
changed |= self.sync_diff_element(element)
File "/opt/nautobot/lib/python3.8/site-packages/diffsync/helpers.py", line 304, in sync_diff_element
changed |= self.sync_diff_element(child, parent_model=model)
File "/opt/nautobot/lib/python3.8/site-packages/diffsync/helpers.py", line 283, in sync_diff_element
changed, modified_model = self.sync_model(model, ids, attrs)
File "/opt/nautobot/lib/python3.8/site-packages/diffsync/helpers.py", line 329, in sync_model
model = self.model_class.create(diffsync=self.dst_diffsync, ids=ids, attrs=attrs)
File "/opt/nautobot/lib/python3.8/site-packages/network_importer/adapters/nautobot_api/models.py", line 557, in create
nb_params = item.translate_attrs_for_nautobot(attrs)
File "/opt/nautobot/lib/python3.8/site-packages/network_importer/adapters/nautobot_api/models.py", line 510, in translate_attrs_for_nautobot
tag_id = device.get_device_tag_id()
File "/opt/nautobot/lib/python3.8/site-packages/network_importer/adapters/nautobot_api/models.py", line 55, in get_device_tag_id
self.device_tag_id = tag.id
File "/opt/nautobot/lib/python3.8/site-packages/pynautobot/core/response.py", line 192, in getattr
raise AttributeError('object has no attribute "{}"'.format(k))
AttributeError: object has no attribute "id"

pip3 install network-importer (with all version numbers)
network-importer check --update-configs
network-importer apply --update-configs

@b-higgins
I’ve reviewed it couple of times but I don’t understand what is happening
the logic in the code is very simple
Either we are able to retrieve a specific tag from Nautobot or we create it

        tag = self.diffsync.nautobot.extras.tags.get(name=f"device={self.name}")

        if not tag:
            tag = self.diffsync.nautobot.extras.tags.create(name=f"device={self.name}", slug=f"device__{self.name}")

        self.device_tag_id = tag.id
        return self.device_tag_id

But somehow for you the tag.id is not valid
I just checked how pynautobot is behaving with tags and everything is looking good to me.
Maybe try to delete all existings tags that starts with device=

To be 100% certain that my instance of Nautobot is working properly - I stood up a CentOS Stream VM and ran through https://nautobot.readthedocs.io/en/latest/installation/#installing-nautobot-dependencies-on-centosrhel

I set as many options to "false" to narrow down the issue. I've attached the new output and configuration file as the error has changed. It no longer crashes, but I get the following for every interface:

network-importer - WARNING - Unable to create interface ge-0/0/2.0 on switch in Nautobot (object has no attribute "name")

new command output.txt
network_importer.toml.txt

Follow up: I used the same Nautobot server configuration and the same network_importer.toml configuration in my work lab. Everything worked as expected.

My assumption is that I have something weird in my home lab. Thank you for your attention!

Thank you for the follow up @b-higgins