Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Fix up redis configuration to use REDIS_BACKEND instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonthomas authored and spasovski committed Apr 28, 2015
1 parent 5dcc4d6 commit 13d6e9c
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 250 deletions.
11 changes: 2 additions & 9 deletions mkt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,15 +981,8 @@ def JINJA_CONFIG():
# Read-only mode setup.
READ_ONLY = False

REDIS_BACKENDS = {
'master': {
'HOST': os.environ.get('REDIS_HOST', 'localhost'),
'PORT': '6379',
'OPTIONS': {
'socket_timeout': '0.5',
}
}
}
REDIS_BACKEND = 'redis://{0}:6379?socket_timeout=0.1'.format(
os.environ.get('REDIS_HOST', 'localhost'))

REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
Expand Down
119 changes: 0 additions & 119 deletions mkt/site/management/commands/clean_redis.py

This file was deleted.

30 changes: 13 additions & 17 deletions mkt/site/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,19 @@ def path():

def redis():
# Check Redis
redis_results = [None, 'REDIS_BACKENDS is not set']
status = 'REDIS_BACKENDS is not set'
if getattr(settings, 'REDIS_BACKENDS', False):
import redisutils
status = []

redis_results = {}

for alias, redis in redisutils.connections.iteritems():
try:
redis_results[alias] = redis.info()
except Exception, e:
redis_results[alias] = None
status.append('Failed to chat with redis:%s' % alias)
monitor_log.critical('Failed to chat with redis: (%s)' % e)

status = ','.join(status)
redis_results = [None, 'REDIS_BACKEND is not set']
status = 'REDIS_BACKEND is not set'
if getattr(settings, 'REDIS_BACKEND', False):
from caching.invalidation import get_redis_backend
status = ''

try:
redis = get_redis_backend()
redis_results = redis.info()
except Exception, e:
redis_results = None
status = ('Failed to chat with redis')
monitor_log.critical('Failed to chat with redis: (%s)' % e)

return status, redis_results

Expand Down
8 changes: 3 additions & 5 deletions mkt/site/templates/services/monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ <h2>[Paths] Paths and Permissions ({{ path_timer }}ms)</h2>
<div class="notification-box {{ status(status_summary.redis) }}">
<h2>[Redis] Redis Info ({{ redis_timer }}ms)</h2>
<dl>
{% for alias, info in redis_results.iteritems() %}
<dt>{{ alias }}</dt>
<dt>Cache</dt>
<dd>
{% if info %}
{% if redis_results %}
<ul>
{% for k, v in info|dictsort %}
{% for k, v in redis_results|dictsort %}
<li><code>{{ k }}: {{ v }}</code></li>
{% endfor %}
</ul>
Expand All @@ -78,7 +77,6 @@ <h2>[Redis] Redis Info ({{ redis_timer }}ms)</h2>
<code>{{ error }}</code>
{% endif %}
</dd>
{% endfor %}
</dl>
</div>

Expand Down
16 changes: 1 addition & 15 deletions mkt/site/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from nose.exc import SkipTest
from nose.tools import eq_
from pyquery import PyQuery as pq
from redisutils import mock_redis, reset_redis
from waffle import cache_sample, cache_switch
from waffle.models import Flag, Sample, Switch

Expand Down Expand Up @@ -193,18 +192,6 @@ def check_links(expected, elements, selected=None, verify=True):
eq_(bool(e.length), text == selected)


class RedisTest(object):
"""Mixin for when you need to mock redis for testing."""

def _pre_setup(self):
self._redis = mock_redis()
super(RedisTest, self)._pre_setup()

def _post_teardown(self):
super(RedisTest, self)._post_teardown()
reset_redis(self._redis)


class TestClient(Client):

def __getattr__(self, name):
Expand Down Expand Up @@ -443,8 +430,7 @@ def _post_teardown(self):
connections.all = real_connections_all


class TestCase(MockEsMixin, RedisTest, MockBrowserIdMixin,
ClassFixtureTestCase):
class TestCase(MockEsMixin, MockBrowserIdMixin, ClassFixtureTestCase):
"""Base class for all mkt tests."""
client_class = TestClient

Expand Down
8 changes: 3 additions & 5 deletions mkt/site/tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from django.test.utils import override_settings

from mock import Mock, patch
from nose.tools import eq_, ok_
import redisutils
from nose.tools import eq_
import requests

import mkt.site.tests
Expand Down Expand Up @@ -60,11 +59,10 @@ def test_path(self):
status, path_result = monitors.path()
eq_(status, '')

@patch.object(redisutils.MockRedis, 'info', create=True)
def test_redis(self, mock_redis):
@patch('caching.invalidation.get_redis_backend')
def test_redis(self, get_redis_backend):
status, redis_result = monitors.redis()
eq_(status, '')
ok_(mock_redis.called)

def test_settings_check(self):
status, settings_check_result = monitors.settings_check()
Expand Down
6 changes: 0 additions & 6 deletions sites/altdev/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@
})

REDIS_BACKEND = private.REDIS_BACKENDS_CACHE
REDIS_BACKENDS = {
'cache': private.REDIS_BACKENDS_CACHE,
'cache_slave': private.REDIS_BACKENDS_CACHE_SLAVE,
'master': private.REDIS_BACKENDS_MASTER,
'slave': private.REDIS_BACKENDS_SLAVE,
}
CACHE_MACHINE_USE_REDIS = True

TMP_PATH = os.path.join(NETAPP_STORAGE, 'tmp')
Expand Down
14 changes: 0 additions & 14 deletions sites/altdev/settings_mkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@
# Redis
REDIS_BACKEND = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE', private.REDIS_BACKENDS_CACHE)
REDIS_BACKENDS_CACHE_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE_SLAVE',
private.REDIS_BACKENDS_CACHE_SLAVE)
REDIS_BACKENDS_MASTER = getattr(
private_mkt, 'REDIS_BACKENDS_MASTER', private.REDIS_BACKENDS_MASTER)
REDIS_BACKENDS_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_SLAVE', private.REDIS_BACKENDS_SLAVE)

REDIS_BACKENDS = {
'cache': REDIS_BACKEND,
'cache_slave': REDIS_BACKENDS_CACHE_SLAVE,
'master': REDIS_BACKENDS_MASTER,
'slave': REDIS_BACKENDS_SLAVE,
}

# Celery
BROKER_URL = private_mkt.BROKER_URL
Expand Down
6 changes: 0 additions & 6 deletions sites/dev/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@
})

REDIS_BACKEND = private.REDIS_BACKENDS_CACHE
REDIS_BACKENDS = {
'cache': private.REDIS_BACKENDS_CACHE,
'cache_slave': private.REDIS_BACKENDS_CACHE_SLAVE,
'master': private.REDIS_BACKENDS_MASTER,
'slave': private.REDIS_BACKENDS_SLAVE,
}
CACHE_MACHINE_USE_REDIS = True

TMP_PATH = os.path.join(NETAPP_STORAGE, 'tmp')
Expand Down
14 changes: 0 additions & 14 deletions sites/dev/settings_mkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@
# Redis
REDIS_BACKEND = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE', private.REDIS_BACKENDS_CACHE)
REDIS_BACKENDS_CACHE_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE_SLAVE',
private.REDIS_BACKENDS_CACHE_SLAVE)
REDIS_BACKENDS_MASTER = getattr(
private_mkt, 'REDIS_BACKENDS_MASTER', private.REDIS_BACKENDS_MASTER)
REDIS_BACKENDS_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_SLAVE', private.REDIS_BACKENDS_SLAVE)

REDIS_BACKENDS = {
'cache': REDIS_BACKEND,
'cache_slave': REDIS_BACKENDS_CACHE_SLAVE,
'master': REDIS_BACKENDS_MASTER,
'slave': REDIS_BACKENDS_SLAVE,
}

# Celery
BROKER_URL = private_mkt.BROKER_URL
Expand Down
6 changes: 0 additions & 6 deletions sites/identitystage/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@
})

REDIS_BACKEND = private.REDIS_BACKENDS_CACHE
REDIS_BACKENDS = {
'cache': private.REDIS_BACKENDS_CACHE,
'cache_slave': private.REDIS_BACKENDS_CACHE_SLAVE,
'master': private.REDIS_BACKENDS_MASTER,
'slave': private.REDIS_BACKENDS_SLAVE,
}
CACHE_MACHINE_USE_REDIS = True

TMP_PATH = os.path.join(NETAPP_STORAGE, 'tmp')
Expand Down
6 changes: 0 additions & 6 deletions sites/paymentsalt/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@
})

REDIS_BACKEND = private.REDIS_BACKENDS_CACHE
REDIS_BACKENDS = {
'cache': private.REDIS_BACKENDS_CACHE,
'cache_slave': private.REDIS_BACKENDS_CACHE_SLAVE,
'master': private.REDIS_BACKENDS_MASTER,
'slave': private.REDIS_BACKENDS_SLAVE,
}
CACHE_MACHINE_USE_REDIS = True

TMP_PATH = os.path.join(NETAPP_STORAGE, 'tmp')
Expand Down
7 changes: 0 additions & 7 deletions sites/prod/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@
})

REDIS_BACKEND = private.REDIS_BACKENDS_CACHE
REDIS_BACKENDS = {
'cache': REDIS_BACKEND,
'cache_slave': private.REDIS_BACKENDS_CACHE_SLAVE,
'master': private.REDIS_BACKENDS_MASTER,
'slave': private.REDIS_BACKENDS_SLAVE,
}

CACHE_MACHINE_USE_REDIS = True

TMP_PATH = os.path.join(NETAPP_STORAGE, 'tmp')
Expand Down
15 changes: 0 additions & 15 deletions sites/prod/settings_mkt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@
# Redis
REDIS_BACKEND = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE', private.REDIS_BACKENDS_CACHE)
REDIS_BACKENDS_CACHE_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_CACHE_SLAVE',
private.REDIS_BACKENDS_CACHE_SLAVE)
REDIS_BACKENDS_MASTER = getattr(
private_mkt, 'REDIS_BACKENDS_MASTER', private.REDIS_BACKENDS_MASTER)
REDIS_BACKENDS_SLAVE = getattr(
private_mkt, 'REDIS_BACKENDS_SLAVE', private.REDIS_BACKENDS_SLAVE)

REDIS_BACKENDS = {
'cache': REDIS_BACKEND,
'cache_slave': REDIS_BACKENDS_CACHE_SLAVE,
'master': REDIS_BACKENDS_MASTER,
'slave': REDIS_BACKENDS_SLAVE,
}

CACHE_MACHINE_ENABLED = True

# Celery
Expand Down
Loading

0 comments on commit 13d6e9c

Please sign in to comment.