Skip to content

Commit

Permalink
Conditionally include Redis connection information
Browse files Browse the repository at this point in the history
Redis is only used when cache is enabled or RQ tasking is used. In other
cases, the connection is not needed. We've changed the Foreman installer
to only install Redis if needed, just to stop wasting resources[1].
However, this leads to warnings.

This PR changes the status view to only include Redis if it's used.

[1]: theforeman/puppet-pulpcore@7a5543b

closes #9070
https://pulp.plan.io/issues/9070
  • Loading branch information
ekohl committed Jul 14, 2021
1 parent 0c3b69d commit c3db975
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES/9070.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set Redis connection information in status to null unless it's used. Redis is
needed for RQ tasking or content caching.
5 changes: 4 additions & 1 deletion pulpcore/app/serializers/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class StatusSerializer(serializers.Serializer):
help_text=_("Database connection information")
)

redis_connection = RedisConnectionSerializer(help_text=_("Redis connection information"))
redis_connection = RedisConnectionSerializer(
required=False,
help_text=_("Redis connection information"),
)

storage = StorageSerializer(required=False, help_text=_("Storage information"))
6 changes: 5 additions & 1 deletion pulpcore/app/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def get(self, request):
for app in pulp_plugin_configs():
versions.append({"component": app.label, "version": app.version})

redis_status = {"connected": self._get_redis_conn_status()}
if settings.CACHE_ENABLED or not settings.USE_NEW_WORKER_TYPE:
redis_status = {"connected": self._get_redis_conn_status()}
else:
redis_status = None

db_status = {"connected": self._get_db_conn_status()}

try:
Expand Down
11 changes: 11 additions & 0 deletions pulpcore/tests/functional/api/test_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test the status page."""
import unittest

from django.test import override_settings
from jsonschema import validate
from pulp_smash import api, cli, config, utils
from pulp_smash.pulp3.constants import STATUS_PATH
Expand Down Expand Up @@ -91,10 +92,20 @@ def verify_get_response(self, status):
"""
validate(status, self.status_response)
self.assertTrue(status["database_connection"]["connected"])
self.assertIsNotNone(status["redis_connection"])
self.assertTrue(status["redis_connection"]["connected"])
self.assertNotEqual(status["online_workers"], [])
self.assertNotEqual(status["versions"], [])
if self.storage == "pulpcore.app.models.storage.FileSystem":
self.assertIsNotNone(status["storage"])
else:
self.assertIsNone(status["storage"])

@override_settings(CACHE_ENABLED=False, USE_NEW_WORKER_TYPE=True)
def verify_get_response_without_redis(self, status):
"""Verify the response to an HTTP GET call when Redis is not used.
Verify that redis_connection is null
"""
validate(status, self.status_response)
self.assertIsNone(status["redis_connection"])

0 comments on commit c3db975

Please sign in to comment.