nautobot / nautobot-app-ssot

Single Source of Truth for Nautobot
https://docs.nautobot.com/projects/ssot/en/latest/
Other
35 stars 33 forks source link

AristaCV error - AttributeError: module 'distutils' has no attribute 'util' #492

Open ecrosswhite opened 1 month ago

ecrosswhite commented 1 month ago

Environment

Expected Behavior

Running the Arista CloudVision --> Nautobot job should be able to complete

Observed Behavior

The job errors out due to distutils module error.

Traceback (most recent call last):
  File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 760, in __protected_call__
    return self.run(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 1136, in run_job
    result = job(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 149, in __call__
    return self.run(*args, **deserialized_kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/jobs.py", line 140, in run
    super().run(dryrun=self.dryrun, memory_profiling=self.memory_profiling, *args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/jobs/base.py", line 317, in run
    self.sync_data(memory_profiling)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/jobs/base.py", line 136, in sync_data
    self.load_source_adapter()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/jobs.py", line 119, in load_source_adapter
    self.source_adapter.load()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 269, in load
    self.load_devices()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 95, in load_devices
    self.load_device_tags(device=new_device)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 252, in load_device_tags
    tag["value"] = bool(distutils.util.strtobool(tag["value"]))
AttributeError: module 'distutils' has no attribute 'util'

Steps to Reproduce

  1. Launch the job, wait for the error

Possible fix

As distutils is depricated, PEP 632 I was able to get around the issue by patching my file nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py

I added python package str2bool, imported to the file from str2bool import str2bool and changed instances of tag["value"] = bool(distutils.util.strtobool(tag["value"])) to tag["value"] = str2bool(tag["value"])

I see the same logic exists in nautobot_ssot/integrations/aristacv/diffsync/models/nautobot.py but don't know what impact this file has.

jdrew82 commented 3 weeks ago

@ecrosswhite can you confirm if this is still happening in 3.0.0?

ecrosswhite commented 3 weeks ago

@jdrew82 Yes, it looks to still occur with 3.0.0.

{
    "exc_message": [
        "module 'distutils' has no attribute 'util'"
    ],
    "exc_module": "builtins",
    "exc_type": "AttributeError"
}

With a traceback of;

Traceback (most recent call last):
  File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 477, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/celery/app/trace.py", line 760, in __protected_call__
    return self.run(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 1136, in run_job
    result = job(*args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot/extras/jobs.py", line 149, in __call__
    return self.run(*args, **deserialized_kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/jobs.py", line 140, in run
    super().run(dryrun=self.dryrun, memory_profiling=self.memory_profiling, *args, **kwargs)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/jobs/base.py", line 317, in run
    self.sync_data(memory_profiling)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/jobs/base.py", line 136, in sync_data
    self.load_source_adapter()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/jobs.py", line 119, in load_source_adapter
    self.source_adapter.load()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 269, in load
    self.load_devices()
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 95, in load_devices
    self.load_device_tags(device=new_device)
  File "/opt/nautobot/lib/python3.10/site-packages/nautobot_ssot/integrations/aristacv/diffsync/adapters/cloudvision.py", line 252, in load_device_tags
    tag["value"] = bool(distutils.util.strtobool(tag["value"]))
AttributeError: module 'distutils' has no attribute 'util'