Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Migrate to IPFabric Client Library #85

Merged
merged 10 commits into from
May 2, 2022
Merged

Migrate to IPFabric Client Library #85

merged 10 commits into from
May 2, 2022

Conversation

h4ndzdatm0ld
Copy link
Contributor

@h4ndzdatm0ld h4ndzdatm0ld commented Mar 25, 2022

A start to migrate the API client the IPFabric maintained python library.

TODO:

  • - Linting, the usual
  • - Replace the get_vlans call with whatever the equivalent is in the new library
  • - Look into maybe adding more valid unit tests with more data
  • - Add a unit test to validate the logic of serial number. Even though char limit will be raised in later Nautobot version, we want it backwards compatible

@h4ndzdatm0ld h4ndzdatm0ld added good first issue Good for newcomers status: help wanted This issue is tentatively accepted pending a volunteer committed to its implementation labels Mar 25, 2022
@chadell chadell changed the title [WIP] Migrate to IPFabric Client Library Migrate to IPFabric Client Library Apr 7, 2022
@pke11y
Copy link
Contributor

pke11y commented Apr 8, 2022

Looks straight forward.
@justinjeffery-ipf can you take a look?

@ghost
Copy link

ghost commented Apr 11, 2022

An exception occurred: DataError: value too long for type character varying(50)

Action: DiffSyncActions.UPDATE
Synced_object: vlan 1ry firewall__35HEADOFFICE

{ "+": { "vid": 5, "description": "VLAN ID: 5" }, "-": { "vid": 4, "description": "VLAN ID: 4" } }

`Traceback (most recent call last):
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 573, in get_or_create
return self.get(**kwargs), False
File "/opt/nautobot/lib/python3.9/site-packages/cacheops/query.py", line 353, in get
return qs._no_monkey.get(qs, *args, **kwargs)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 429, in get
raise self.model.DoesNotExist(
nautobot.dcim.models.devices.Device.DoesNotExist: Device matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/nautobot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(50)

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

Traceback (most recent call last):
File "/opt/nautobot/lib/python3.9/site-packages/nautobot_ssot/jobs/base.py", line 326, in run
self.sync_data()
File "/opt/nautobot/lib/python3.9/site-packages/nautobot_ssot_ipfabric/jobs.py", line 185, in sync_data
dest.sync_from(ipfabric_source)
File "/opt/nautobot/lib/python3.9/site-packages/diffsync/init.py", line 525, in sync_from
result = syncer.perform_sync()
File "/opt/nautobot/lib/python3.9/site-packages/diffsync/helpers.py", line 326, in perform_sync
changed |= self.sync_diff_element(element)
File "/opt/nautobot/lib/python3.9/site-packages/diffsync/helpers.py", line 390, in sync_diff_element
changed |= self.sync_diff_element(child, parent_model=dst_model)
File "/opt/nautobot/lib/python3.9/site-packages/diffsync/helpers.py", line 366, in sync_diff_element
changed, modified_model = self.sync_model(src_model=src_model, dst_model=dst_model, ids=ids, attrs=attrs)
File "/opt/nautobot/lib/python3.9/site-packages/diffsync/helpers.py", line 415, in sync_model
dst_model = self.model_class.create(diffsync=self.dst_diffsync, ids=ids, attrs=attrs)
File "/opt/nautobot/lib/python3.9/site-packages/nautobot_ssot_ipfabric/diffsync/diffsync_models.py", line 191, in create
new_device, _ = NautobotDevice.objects.get_or_create(
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 576, in get_or_create
return self._create_object_from_params(kwargs, params)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 610, in _create_object_from_params
obj = self.create(**params)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "/opt/nautobot/lib/python3.9/site-packages/nautobot/dcim/models/devices.py", line 735, in save
super().save(*args, **kwargs)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/base.py", line 790, in save_base
updated = self._save_table(
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/base.py", line 933, in _do_insert
return manager._insert(
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File "/opt/nautobot/lib/python3.9/site-packages/cacheops/transaction.py", line 93, in execute
result = self._no_monkey.execute(self, sql, params)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/nautobot/lib/python3.9/site-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/nautobot/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(50)
`

@ghost
Copy link

ghost commented Apr 11, 2022

Logs are not working either. Saying a failure but tells me no failure.

image

@chadell
Copy link
Contributor

chadell commented Apr 12, 2022

thanks @justinjeffery-ipf for the feedback.

@pke11y
Copy link
Contributor

pke11y commented Apr 15, 2022

I ran this against a clean Nautobot and it worked.
@justinjeffery-ipf I'm guessing you had data in your Nautobot before syncing from IP Fabric?

@ghost
Copy link

ghost commented Apr 15, 2022

Some yes but not everything as Azure serial numbers are too long to import. I deleted that one VLAN entry but I don't think that was the issue as it is failing for some unknown reason.

@chadell chadell merged commit 4d6e634 into develop May 2, 2022
@chadell chadell deleted the ht-client-swap branch May 2, 2022 05:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers status: help wanted This issue is tentatively accepted pending a volunteer committed to its implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants