nautobot / nautobot-plugin-ssot-ipfabric

Nautobot SSoT IP Fabric
https://nautobot.github.io/nautobot-plugin-ssot-ipfabric/
Other
8 stars 2 forks source link

ipfabric_timeout var should be cast as integer if coming from env var #110

Closed pauljorgenson closed 1 year ago

pauljorgenson commented 2 years ago

Environment

Expected Behavior

Nautobot starts up when plugin is added with steps described in README

Observed Behavior

Nautobot worker crashes on startup with traceback below

ipfabric_worker_1 exited with code 1
nautobot_1  | Traceback (most recent call last):
nautobot_1  |   File "/usr/local/bin/nautobot-server", line 8, in <module>
nautobot_1  |     sys.exit(main())
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot/core/cli.py", line 54, in main
nautobot_1  |     run_app(
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot/core/runner/runner.py", line 266, in run_app
nautobot_1  |     management.execute_from_command_line([runner_name, command] + command_args)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
nautobot_1  |     utility.execute()
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
nautobot_1  |     django.setup()
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
nautobot_1  |     apps.populate(settings.INSTALLED_APPS)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
nautobot_1  |     app_config.ready()
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot_ssot_ipfabric/__init__.py", line 37, in ready
nautobot_1  |     super().ready()
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot/extras/plugins/__init__.py", line 144, in ready
nautobot_1  |     jobs = import_object(f"{self.__module__}.{self.jobs}")
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot/extras/plugins/utils.py", line 45, in import_object
nautobot_1  |     spec.loader.exec_module(module)
nautobot_1  |   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
nautobot_1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/nautobot_ssot_ipfabric/jobs.py", line 77, in <module>
nautobot_1  |     CLIENT = IPFClient(
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/ipfabric/client.py", line 45, in __init__
nautobot_1  |     super().__init__(base_url, token, snapshot_id, username, password, **kwargs)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/ipfabric/api.py", line 71, in __init__
nautobot_1  |     self.os_version = self.fetch_os_version()
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/ipfabric/api.py", line 97, in fetch_os_version
nautobot_1  |     res = self.get(url="os/version")
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1039, in get
nautobot_1  |     return self.request(
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 815, in request
nautobot_1  |     return self.send(request, auth=auth, follow_redirects=follow_redirects)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 902, in send
nautobot_1  |     response = self._send_handling_auth(
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 930, in _send_handling_auth
nautobot_1  |     response = self._send_handling_redirects(
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 967, in _send_handling_redirects
nautobot_1  |     response = self._send_single_request(request)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1003, in _send_single_request
nautobot_1  |     response = transport.handle_request(request)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 218, in handle_request
nautobot_1  |     resp = self._pool.handle_request(req)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 253, in handle_request
nautobot_1  |     raise exc
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 237, in handle_request
nautobot_1  |     response = connection.handle_request(request)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 86, in handle_request
nautobot_1  |     raise exc
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 63, in handle_request
nautobot_1  |     stream = self._connect(request)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 111, in _connect
nautobot_1  |     stream = self._network_backend.connect_tcp(**kwargs)
nautobot_1  |   File "/usr/local/lib/python3.8/site-packages/httpcore/backends/sync.py", line 86, in connect_tcp
nautobot_1  |     sock = socket.create_connection(
nautobot_1  |   File "/usr/local/lib/python3.8/socket.py", line 793, in create_connection
nautobot_1  |     sock.settimeout(timeout)
nautobot_1  | TypeError: an integer is required (got type str)

Steps to Reproduce

  1. Add nautobot-plugin-ssot-ipfabric to nautobot plugins as described in README
  2. Configure IPFABRIC_TIMEOUT environment variable to an integer (I used 15)
  3. Attempt to start Nautobot

To test if this was really the issue I wrapped the ipfabric_timeout value in the plugins config in the int() method and nautobot started as expected.

    "nautobot_ssot_ipfabric": {
        "ipfabric_api_token": os.environ.get("IPFABRIC_API_TOKEN"),
        "ipfabric_host": os.environ.get("IPFABRIC_HOST"),
        "nautobot_host": os.environ.get("NAUTOBOT_HOST"),
        "ipfabric_ssl_verify": os.environ.get("IPFABRIC_SSL_VERIFY"),
        "ipfabric_timeout": int(os.environ.get("IPFABRIC_TIMEOUT", 15)),
    },
alhogan commented 1 year ago

This has been implemented