Skip to content
Snippets Groups Projects
Commit 0240d080 authored by Robert Latta's avatar Robert Latta
Browse files

Merge branch 'feature/DBOARD3-747' into 'develop'

Added redis auth credentials to inventory config schema and updated _get_redis wrapper.

See merge request !11
parents c5da4995 4b7f3c8c
No related branches found
No related tags found
1 merge request!11Added redis auth credentials to inventory config schema and updated _get_redis wrapper.
......@@ -62,6 +62,7 @@ CONFIG_SCHEMA = {
'properties': {
'hostname': {'type': 'string'},
'port': {'type': 'integer'},
'password': {'type': 'string'},
'celery-db-index': {'type': 'integer'},
'socket_timeout': {'$ref': '#/definitions/timeout'}
},
......@@ -73,6 +74,7 @@ CONFIG_SCHEMA = {
'properties': {
'hostname': {'type': 'string'},
'port': {'type': 'integer'},
'password': {'type': 'string'},
'celery-db-index': {'type': 'integer'},
'name': {'type': 'string'},
'redis_socket_timeout': {'$ref': '#/definitions/timeout'},
......
......@@ -178,23 +178,27 @@ def _get_redis(config, dbid=None):
}
if 'sentinel' in config:
kwargs['socket_timeout'] = config['sentinel'].get(
'sentinel_socket_timeout', DEFAULT_SENTINEL_SOCKET_TIMEOUT)
sentinel_kwargs = {
'password': config['sentinel'].get('password'),
'socket_timeout': config['sentinel'].get(
'redis_socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT),
}
sentinel = redis.sentinel.Sentinel([(
config['sentinel']['hostname'],
config['sentinel']['port'])],
**kwargs)
return sentinel.master_for(
config['sentinel']['name'],
socket_timeout=config['sentinel'].get(
'redis_socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT))
config['sentinel']['name'], **sentinel_kwargs)
else:
kwargs['socket_timeout'] = config['redis'].get(
'socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT)
redis_kwargs = {
'password': config['redis'].get('password'),
'socket_timeout': config['redis'].get(
'socket_timeout', DEFAULT_REDIS_SENTINEL_TIMEOUT),
}
return redis.StrictRedis(
host=config['redis']['hostname'],
port=config['redis']['port'],
**kwargs)
**redis_kwargs)
def get_current_redis(config):
......
import jsonschema
import pytest
from inventory_provider.config import CONFIG_SCHEMA
@pytest.fixture
def config():
return {
'redis': {
'hostname': 'localhost',
'port': 6379,
'password': 'redis_password',
},
'ssh': {
'username': 'test_username',
'private-key': 'private_key_content',
'known-hosts': 'known_hosts_content'
},
'redis-databases': [0, 1, 2],
'ims': {
'api': 'ims_api',
'username': 'ims_username',
'password': 'ims_password',
},
'managed-routers': 'router_list',
'gws-direct': [],
'nren-asn-map': [],
}
def test_config_validation(config):
assert validate_config(config)
def test_config_validation_include_sentinel(config):
config['sentinel'] = { # noqa
'hostname': 'localhost',
'port': 26379,
'password': 'redis_password',
'name': 'mymaster'
}
assert not validate_config(config)
# Configuration validation failed.
# One of the redis and sentinel should exist in the config.
del config['redis']
assert validate_config(config) # Configuration validation successful.
def test_config_validation_without_redis_password(config):
# Password is optional.
del config['redis']['password']
assert validate_config(config)
def validate_config(config):
try:
jsonschema.validate(config, CONFIG_SCHEMA)
return True # Configuration validation successful.
except jsonschema.exceptions.ValidationError:
return False # Configuration validation failed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment