diff --git a/inventory_provider/tasks/monitor.py b/inventory_provider/tasks/monitor.py index 389bf15a844d6829b10785f7f16e58f6e26b97d7..a02ede72a6081022df88718a076934999e84384e 100644 --- a/inventory_provider/tasks/monitor.py +++ b/inventory_provider/tasks/monitor.py @@ -10,9 +10,12 @@ import logging import os import queue import threading + +from redis.exceptions import RedisError + from inventory_provider import config, environment from inventory_provider.tasks.worker import app -from inventory_provider.tasks.common import get_current_redis, _get_redis +from inventory_provider.tasks.common import _get_redis logger = logging.getLogger(__name__) @@ -35,7 +38,7 @@ def _save_proc(db_queue, params, dbid): while True: try: _save_events(_get_redis(config=params, dbid=dbid), db_queue) - except: + except RedisError: logger.exception('redis i/o exception, reconnecting') # TODO: do something to terminate the process ...? diff --git a/test/test_job_routes.py b/test/test_job_routes.py index b563ca1312a26d1eeb919de01d5e6c52f38b1a40..b7ff1ddf570eab056224024da3b02b8f77541440 100644 --- a/test/test_job_routes.py +++ b/test/test_job_routes.py @@ -256,22 +256,29 @@ def test_latchdb(client, mocked_redis): jsonschema.validate(latch, DB_LATCH_SCHEMA) - -TEST_EVENTS = { - 'joblog:AAAA:task-aaa': {'type': 'task-aaaa', 'uuid': 'AAAA', 'clock': 999}, - 'joblog:AAAB:task-infox': {'type': 'task-infox', 'uuid': 'AAAB', 'clock': 999}, - 'joblog:BBBB:task-info:99': {'type': 'task-info', 'uuid': 'BBBB', 'clock': 99}, - 'joblog:BBBB:task-info:999': {'type': 'task-info', 'uuid': 'BBBB', 'clock': 999}, - 'joblog:AAAA:task-warning:88': {'type': 'task-warning', 'uuid': 'AAAA', 'clock': 88}, - 'joblog:AAAA:task-warning:888': {'type': 'task-warning', 'uuid': 'AAAA', 'clock': 888}, - 'joblog:AAAA:task-error:77': {'type': 'task-error', 'uuid': 'AAAA', 'clock': 77}, - 'joblog:AAAA:task-error:777': {'type': 'task-error', 'uuid': 'AAAA', 'clock': 777} -} - def test_job_log(client): + test_events = { + 'joblog:AAAA:task-aaa': { + 'type': 'task-aaaa', 'uuid': 'AAAA', 'clock': 999}, + 'joblog:AAAB:task-infox': { + 'type': 'task-infox', 'uuid': 'AAAB', 'clock': 999}, + 'joblog:BBBB:task-info:99': { + 'type': 'task-info', 'uuid': 'BBBB', 'clock': 99}, + 'joblog:BBBB:task-info:999': { + 'type': 'task-info', 'uuid': 'BBBB', 'clock': 999}, + 'joblog:AAAA:task-warning:88': { + 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 88}, + 'joblog:AAAA:task-warning:888': { + 'type': 'task-warning', 'uuid': 'AAAA', 'clock': 888}, + 'joblog:AAAA:task-error:77': { + 'type': 'task-error', 'uuid': 'AAAA', 'clock': 77}, + 'joblog:AAAA:task-error:777': { + 'type': 'task-error', 'uuid': 'AAAA', 'clock': 777} + } + db = backend_db() - for k, v in TEST_EVENTS.items(): + for k, v in test_events.items(): db[k] = json.dumps(v) rv = client.post( @@ -279,4 +286,4 @@ def test_job_log(client): headers=DEFAULT_REQUEST_HEADERS) assert rv.status_code == 200 result = json.loads(rv.data.decode('utf-8')) - assert len(result.keys()) == 3 # TODO: make a proper test \ No newline at end of file + assert len(result.keys()) == 3 # TODO: make a proper test