Skip to content

Unable to load the web interface with a sentinel redis : Exception Type: ImproperlyConfigured at / #7189

@pierrechev

Description

@pierrechev

NetBox version

v3.0.1

Python version

3.9

Steps to Reproduce

  1. Configure netbox to use a redis sentinel (https://netbox.readthedocs.io/en/stable/configuration/required-settings/ : Using Redis Sentinel)
  2. Start netbox
  3. Try to connect to the main url to netbox https://localhost:12345/
  4. Error

Logs :

Request Method: GET
Request URL: http://localhost:12345/
Django Version: 3.2.7
Python Version: 3.9.7
Installed Applications:
['django.contrib.admin',
-----
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/__init__.py", line 136, in get
    latest_release = cache.get('latest_release')
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 91, in get
    value = self._get(key, default, version, client)
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 31, in _decorator
    return method(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django_redis/cache.py", line 98, in _get
    return self.client.get(key, default=default, version=version, client=client)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 253, in get
    client = self.get_client(write=False)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/default.py", line 105, in get_client
    self._clients[index] = self.connect(index)
  File "/usr/local/lib/python3.9/site-packages/django_redis/client/sentinel.py", line 36, in connect
    raise ImproperlyConfigured(

Exception Type: ImproperlyConfigured at /ui/bmop-cmdb/
Exception Value: Settings DJANGO_REDIS_CONNECTION_FACTORY or CACHE[].OPTIONS.CONNECTION_POOL_CLASS is not configured correctly.

Expected Behavior

We have this issue because the variable DJANGO_REDIS_CONNECTION_FACTORY is not set in settings.py (https://github.com/netbox-community/netbox/blob/master/netbox/netbox/settings.py)

fix :

if CACHING_REDIS_SENTINELS:
    DJANGO_REDIS_CONNECTION_FACTORY = 'django_redis.pool.SentinelConnectionFactory'
    CACHES['default']['LOCATION'] = f'{CACHING_REDIS_PROTO}://{CACHING_REDIS_SENTINEL_SERVICE}/{CACHING_REDIS_DATABASE}'
    CACHES['default']['OPTIONS']['CLIENT_CLASS'] = 'django_redis.client.SentinelClient'
    CACHES['default']['OPTIONS']['SENTINELS'] = CACHING_REDIS_SENTINELS
if CACHING_REDIS_SKIP_TLS_VERIFY:
    CACHES['default']['OPTIONS']['CONNECTION_POOL_KWARGS']['ssl_cert_reqs'] = False

Observed Behavior

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions