Skip to content
Snippets Groups Projects
Commit b6851bba authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature redis-with-sentinel.

parents 25a8cab4 d7a5d994
No related branches found
No related tags found
No related merge requests found
...@@ -44,44 +44,40 @@ CONFIG_SCHEMA = { ...@@ -44,44 +44,40 @@ CONFIG_SCHEMA = {
"required": ["hostname", "port"], "required": ["hostname", "port"],
"additionalProperties": False "additionalProperties": False
}, },
"sentinel": {
"type": "object",
"properties": {
"hostname": {"type": "string"},
"port": {"type": "integer"},
"name": {"type": "string"}
},
"required": ["hostname", "port"],
"additionalProperties": False
},
"junosspace": { "junosspace": {
"api": {"type": "string"}, "api": {"type": "string"},
"username": {"type": "string"}, "username": {"type": "string"},
"password": {"type": "string"} "password": {"type": "string"}
},
"infinera-dna": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"address": {"type": "string"}
},
"required": ["name", "address"],
"additionalProperties": False
}
},
"coriant-tnms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"address": {"type": "string"}
},
"required": ["name", "address"],
"additionalProperties": False
}
} }
}, },
"required": [ "oneOf": [
"ops-db", {
"oid_list.conf", "required": [
"ssh", "ops-db",
"redis", "oid_list.conf",
"junosspace", "ssh",
"infinera-dna", "redis",
"coriant-tnms"], "junosspace"]
},
{
"required": [
"ops-db",
"oid_list.conf",
"ssh",
"sentinel",
"junosspace"]
}
],
"additionalProperties": False "additionalProperties": False
} }
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
"loggers": { "loggers": {
"inventory_provider": { "inventory_provider": {
"level": "INFO", "level": "DEBUG",
"handlers": ["console", "syslog_handler"], "handlers": ["console", "syslog_handler"],
"propagate": false "propagate": false
}, },
......
...@@ -2,7 +2,7 @@ import functools ...@@ -2,7 +2,7 @@ import functools
import logging import logging
from flask import request, Response, current_app, g from flask import request, Response, current_app, g
import redis from inventory_provider.tasks.common import get_redis as tasks_get_redis
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -10,10 +10,7 @@ logger = logging.getLogger(__name__) ...@@ -10,10 +10,7 @@ logger = logging.getLogger(__name__)
def get_redis(): def get_redis():
if 'redis_db' not in g: if 'redis_db' not in g:
config = current_app.config['INVENTORY_PROVIDER_CONFIG'] config = current_app.config['INVENTORY_PROVIDER_CONFIG']
g.redis_db = redis.StrictRedis( g.redis_db = tasks_get_redis(config)
host=config['redis']['hostname'],
port=config['redis']['port'])
return g.redis_db return g.redis_db
......
...@@ -2,7 +2,7 @@ import collections ...@@ -2,7 +2,7 @@ import collections
import json import json
import re import re
from flask import Blueprint, Response, current_app, jsonify from flask import Blueprint, Response, jsonify
from lxml import etree from lxml import etree
from inventory_provider import juniper from inventory_provider import juniper
...@@ -42,22 +42,6 @@ def update_interface_statuses(): ...@@ -42,22 +42,6 @@ def update_interface_statuses():
return Response('OK') return Response('OK')
@routes.route("infinera-dna-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def infinera_addresses():
infinera_config = current_app.config[
"INVENTORY_PROVIDER_CONFIG"]["infinera-dna"]
return jsonify([dna['address'] for dna in infinera_config])
@routes.route("coriant-tnms-addresses", methods=['GET', 'POST'])
@common.require_accepts_json
def coriant_addresses():
coriant_config = current_app.config[
"INVENTORY_PROVIDER_CONFIG"]["coriant-tnms"]
return jsonify([tnms['address'] for tnms in coriant_config])
@routes.route("juniper-server-addresses", methods=['GET', 'POST']) @routes.route("juniper-server-addresses", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def juniper_addresses(): def juniper_addresses():
......
import redis import redis
import redis.sentinel
def get_redis(config): def get_redis(config):
return redis.StrictRedis( if 'sentinel' in config:
host=config['redis']['hostname'], sentinel = redis.sentinel.Sentinel([(
port=config['redis']['port']) config['sentinel']['hostname'],
config['sentinel']['port'])],
socket_timeout=0.1)
return sentinel.master_for(
config['sentinel']['name'],
socket_timeout=0.1)
else:
return redis.StrictRedis(
host=config['redis']['hostname'],
port=config['redis']['port'])
import json
from os import getenv from os import getenv
broker_url = getenv( broker_url = getenv(
...@@ -6,4 +7,13 @@ broker_url = getenv( ...@@ -6,4 +7,13 @@ broker_url = getenv(
result_backend = getenv( result_backend = getenv(
'CELERY_BROKER_URL', 'CELERY_BROKER_URL',
default='redis://test-dashboard02.geant.org:6379/1') default='redis://test-dashboard02.geant.org:6379/1')
tmp_options = getenv(
'BROKER_TRANSPORT_OPTIONS',
default='')
if tmp_options:
broker_transport_options = json.loads(tmp_options)
else:
broker_transport_options = {}
task_eager_propagates = True task_eager_propagates = True
...@@ -44,17 +44,7 @@ def data_config_filename(tmp_dir_name): ...@@ -44,17 +44,7 @@ def data_config_filename(tmp_dir_name):
"api": "bogus-url", "api": "bogus-url",
"username": "bogus-username", "username": "bogus-username",
"password": "bogus-password" "password": "bogus-password"
}, }
"infinera-dna": [
{"name": "name1", "address": "123.456.789.0"},
{"name": "name2", "address": "012.345.678.9"},
{"name": "name3", "address": "111.222.333.000"}
],
"coriant-tnms": [
{"name": "name1", "address": "123.456.789.0"},
{"name": "name2", "address": "012.345.678.9"},
{"name": "name3", "address": "111.222.333.000"}
]
} }
shutil.copyfile( shutil.copyfile(
...@@ -157,7 +147,7 @@ def app_config(): ...@@ -157,7 +147,7 @@ def app_config():
def client(app_config, mocker): def client(app_config, mocker):
mocker.patch( mocker.patch(
'inventory_provider.routes.common.redis.StrictRedis', 'inventory_provider.tasks.common.redis.StrictRedis',
MockedRedis) MockedRedis)
os.environ["SETTINGS_FILENAME"] = app_config os.environ["SETTINGS_FILENAME"] = app_config
...@@ -166,19 +156,15 @@ def client(app_config, mocker): ...@@ -166,19 +156,15 @@ def client(app_config, mocker):
@pytest.fixture @pytest.fixture
def client_with_mocked_data(client, mocker): def mocked_redis(mocker):
mocker.patch( mocker.patch(
'inventory_provider.routes.common.redis.StrictRedis', 'inventory_provider.tasks.common.redis.StrictRedis',
MockedRedis) MockedRedis)
return client
@pytest.fixture @pytest.fixture
def mocked_redis(mocker): def client_with_mocked_data(client, mocked_redis):
mocker.patch( return client
'inventory_provider.routes.common.redis.StrictRedis',
MockedRedis)
NETIFACES_TEST_DATA_STRING = """{ NETIFACES_TEST_DATA_STRING = """{
......
...@@ -18,26 +18,6 @@ def test_flushdb(client): ...@@ -18,26 +18,6 @@ def test_flushdb(client):
assert rv.status_code == 200 assert rv.status_code == 200
def test_infinera_addresses(client):
rv = client.post(
"/testing/infinera-dna-addresses",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
jsonschema.validate(
json.loads(rv.data.decode("utf-8")),
ROUTER_LIST_SCHEMA)
def test_coriant_addresses(client):
rv = client.post(
"/testing/coriant-tnms-addresses",
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
jsonschema.validate(
json.loads(rv.data.decode("utf-8")),
ROUTER_LIST_SCHEMA)
def test_juniper_addresses(client): def test_juniper_addresses(client):
rv = client.post( rv = client.post(
"/testing/juniper-server-addresses", "/testing/juniper-server-addresses",
......
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