From 264755f6c4d62acec1c7dc0050c92914b5934857 Mon Sep 17 00:00:00 2001 From: frikilax Date: Fri, 29 Nov 2019 09:28:38 +0100 Subject: [PATCH] CONFV2:: NEW CONF FORMAT, CONF VALIDATION, TESTS - update to python files' header (removed Vulture-specific headers) - new configuration format (conf v2) implemented - possibility to add objects in json for general manager/Darwin mechanics - no more variable object names in conf -> filters are self-contained in a list, with the name as a regular field - configuration files validation via jsonschema - new tests for conf v2 - added requirements.txt --- manager/Administration.py | 15 - manager/HeartBeat.py | 15 - manager/JsonSocket.py | 15 - manager/Services.py | 150 +------- manager/config.py | 250 +++++++++++++ manager/manager.py | 26 +- manager/requirements.txt | 3 + tests/manager_socket/monitor_test.py | 57 ++- tests/manager_socket/update_test.py | 532 ++++++++++++++++++++++++++- tests/manager_socket/utils.py | 142 ++++++- 10 files changed, 973 insertions(+), 232 deletions(-) create mode 100644 manager/config.py create mode 100644 manager/requirements.txt diff --git a/manager/Administration.py b/manager/Administration.py index c93c0a9f..7f645c87 100644 --- a/manager/Administration.py +++ b/manager/Administration.py @@ -1,18 +1,3 @@ -"""This file is part of Vulture 3. - -Vulture 3 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Vulture 3 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Vulture 3. If not, see http://www.gnu.org/licenses/. -""" __author__ = "Hugo SOSZYNSKI" __credits__ = [] __license__ = "GPLv3" diff --git a/manager/HeartBeat.py b/manager/HeartBeat.py index 055f31cf..f5e7c768 100644 --- a/manager/HeartBeat.py +++ b/manager/HeartBeat.py @@ -1,18 +1,3 @@ -"""This file is part of Vulture 3. - -Vulture 3 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Vulture 3 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Vulture 3. If not, see http://www.gnu.org/licenses/. -""" __author__ = "Hugo SOSZYNSKI" __credits__ = [] __license__ = "GPLv3" diff --git a/manager/JsonSocket.py b/manager/JsonSocket.py index e4074b0e..13c5378d 100644 --- a/manager/JsonSocket.py +++ b/manager/JsonSocket.py @@ -1,18 +1,3 @@ -"""This file is part of Vulture 3. - -Vulture 3 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Vulture 3 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Vulture 3. If not, see http://www.gnu.org/licenses/. -""" __author__ = "Hugo SOSZYNSKI" __credits__ = [] __license__ = "GPLv3" diff --git a/manager/Services.py b/manager/Services.py index 30f412e8..ceeda86f 100644 --- a/manager/Services.py +++ b/manager/Services.py @@ -1,18 +1,3 @@ -"""This file is part of Vulture 3. - -Vulture 3 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Vulture 3 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Vulture 3. If not, see http://www.gnu.org/licenses/. -""" __author__ = "Hugo SOSZYNSKI" __credits__ = [] __license__ = "GPLv3" @@ -34,6 +19,8 @@ from HeartBeat import HeartBeat from time import sleep import psutil +from config import load_conf, ConfParseError +from config import filters as conf_filters logger = logging.getLogger() @@ -43,16 +30,14 @@ class Services: Manage services execution, monitoring and configuration. """ - def __init__(self, config_file): + def __init__(self, filters): """ Constructor, load configuration pointed by config_file. :param config_file: Path to the filters configuration file. """ - self._config_file = config_file - self._filters = {} + self._filters = deepcopy(filters) self._lock = Lock() - self.load_conf() def start_all(self): """ @@ -351,12 +336,11 @@ def update(self, names): """ logger.debug("Update: Trying to open config file") try: - with open(self._config_file, 'r') as f: - logger.debug("Update: Loading config") - filters = json.load(f) - except Exception as e: - logger.error("Unable to load conf on update: {0}".format(e)) - return [{"filter": "all", "error": "Unable to load conf on update: {0}".format(e)}] + #Reload conf, global variable 'conf_filters' will be updated + load_conf() + except ConfParseError: + logger.error("Update: wrong configuration format, unable to update") + return 1 logger.info("Update: Configuration loaded") @@ -365,7 +349,7 @@ def update(self, names): new = {} for n in names: try: - new[n] = filters[n] + new[n] = conf_filters[n] except KeyError: try: self.stop_one(self._filters[n], no_lock=True) @@ -384,57 +368,16 @@ def update(self, names): name=n, extension=new[n]['extension'] ) - new[n]['output'] = new[n]['output'] - new[n]['name'] = n - - if not new[n]['next_filter']: - new[n]['next_filter_unix_socket'] = 'no' - else: - new[n]['next_filter_unix_socket'] = '/var/sockets/darwin/{next_filter}.sock'.format( - next_filter=new[n]['next_filter'] - ) - new[n]['socket'] = '/var/sockets/darwin/{name}{extension}.sock'.format( name=n, extension=new[n]['extension'] ) - new[n]['socket_link'] = '/var/sockets/darwin/{name}.sock'.format(name=n) - new[n]['monitoring'] = '/var/sockets/darwin/{name}_mon{extension}.sock'.format( name=n, extension=new[n]['extension'] ) - if "config_file" not in new[n]: - logger.warning("Field 'config_file' not found for {}: setting default.".format(n)) - new[n]['config_file'] = '/home/darwin/conf/{name}.conf'.format(name=n) - - if 'cache_size' not in new[n]: - new[n]['cache_size'] = 0 - - logger.info('No cache size provided. Setting it to {cache_size}'.format( - cache_size=new[n]['cache_size'] - )) - - if 'output' not in new[n]: - new[n]['output'] = 'NONE' - logger.info('No output type provided. Setting it to {output}'.format(output=new[n]['output'])) - - if 'nb_thread' not in new[n]: - new[n]['nb_thread'] = 5 - - logger.info('No number of threads provided. Setting it to {nb_thread}'.format( - nb_thread=new[n]['nb_thread'] - )) - - if 'threshold' not in new[n]: - new[n]['threshold'] = 101 - - logger.info('No threshold provided. Setting it to the filter\'s default threshold') - for n, c in new.items(): - c['status'] = psutil.STATUS_WAKING cmd = self._build_cmd(c) - logger.info("Starting updated filter") p = Popen(cmd) try: p.wait(timeout=1) @@ -486,79 +429,6 @@ def update(self, names): return errors - def load_conf(self): - """ - Load the configuration. - """ - - with self._lock: - logger.debug("Trying to open config file") - try: - with open(self._config_file, 'r') as f: - logger.debug("Loading config") - self._filters = json.load(f) - except Exception as e: - logger.critical("Unable to load initial conf: {0}".format(e)) - raise e - - logger.info("Configuration loaded") - - for f, c in self._filters.items(): - if 'next_filter' not in c: - c['next_filter'] = '' - - logger.debug('No next filter provided') - - try: - c['name'] = f - c['status'] = psutil.STATUS_WAKING - c['extension'] = '.1' - c['pid_file'] = '/var/run/darwin/{filter}{extension}.pid'.format(filter=f, extension=c['extension']) - - if not c['next_filter']: - c['next_filter_unix_socket'] = 'no' - else: - c['next_filter_unix_socket'] = '/var/sockets/darwin/{next_filter}.sock'.format( - next_filter=c['next_filter'] - ) - - c['socket'] = '/var/sockets/darwin/{filter}{extension}.sock'.format(filter=f, extension=c['extension']) - c['socket_link'] = '/var/sockets/darwin/{filter}.sock'.format(filter=f) - - c['monitoring'] = '/var/sockets/darwin/{filter}_mon{extension}.sock'.format( - filter=f, extension=c['extension'] - ) - - if 'config_file' not in c: - logger.warning('Field "config_file" not found for {filter}: setting default'.format(filter=f)) - c['config_file'] = '/home/vlt-sys/darwin/conf/{filter}.conf'.format(filter=f) - - if 'cache_size' not in c: - c['cache_size'] = 0 - - logger.info('No cache size provided. Setting it to {cache_size}'.format( - cache_size=c['cache_size'] - )) - - if 'output' not in c: - c['output'] = 'NONE' - logger.info('No output type provided. Setting it to {output}'.format(output=c['output'])) - - if 'nb_thread' not in c: - c['nb_thread'] = 5 - - logger.info('No number of threads provided. Setting it to {nb_thread}'.format( - nb_thread=c['nb_thread'] - )) - except KeyError as e: - logger.critical("Missing parameter: {}".format(e)) - raise e - - if 'threshold' not in c: - c['threshold'] = 101 - - logger.info('No threshold provided. Setting it to the filter\'s default threshold') - def print_conf(self): """ Pretty Print the configuration. diff --git a/manager/config.py b/manager/config.py new file mode 100644 index 00000000..ff0edcc9 --- /dev/null +++ b/manager/config.py @@ -0,0 +1,250 @@ +__author__ = "Theo BERTIN" +__credits__ = [] +__license__ = "GPLv3" +__version__ = "1.2" +__maintainer__ = "Vulture Project" +__email__ = "contact@vultureproject.org" +__doc__ = 'Everything related to config parsing' + +import logging +import json +from jsonschema import validators, Draft7Validator +import psutil + +logger = logging.getLogger() + +# Create a validator able to set defaults defined in schemas +def extend_with_default(validator_class): + validate_properties = validator_class.VALIDATORS["properties"] + + def set_defaults(validator, properties, instance, schema): + for property, subschema in properties.items(): + if "default" in subschema: + instance.setdefault(property, subschema["default"]) + + for error in validate_properties( + validator, properties, instance, schema, + ): + yield error + + return validators.extend( + validator_class, {"properties" : set_defaults}, + ) + +custom_validator = extend_with_default(Draft7Validator) + + +# helpful link for schema generation/comprehension/documentation: +# https://json-schema.org/understanding-json-schema/reference/ +conf_v1_schema = { + "$schema": "http://json-schema.org/schema#", + "type": "object", + "patternProperties": { + ".+": { + "type": "object", + "properties": { + "exec_path": {"type": "string"}, + "config_file": {"type": "string"}, + "nb_thread": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "default": 5 + }, + "log_level": { + "type": "string", + "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "DEVELOPER"], + "default": "WARNING" + }, + "cache_size": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "output": { + "type": "string", + "enum": ["NONE", "RAW", "LOG", "PARSED"], + "default": "NONE" + }, + "next_filter": { + "type": "string", + "default": "no" + }, + "threshold": { + "type": "integer", + "default": 100 + } + }, + "required": ["exec_path", "config_file"], + "additionalProperties": False + } + }, + "additionalProperties": False +} + +conf_v2_schema = { + "$schema": "http://json-schema.org/schema#", + "type": "object", + "properties": { + "version": { + "type": "number", + "minimum": 2 + }, + "report_stats": { + "type": "object", + "properties": { + "redis": { + "type": "object", + "properties": { + "unix_path": {"type": "string"}, + "ip": { + "type": "string"}, + "port": { + "type": "integer", + "default": 6379 + } + }, + "dependencies": { + "port": ["ip"] + }, + "additionalProperties": False + }, + "file": { + "type": "object", + "properties": { + "filepath": {"type": "string"}, + "permissions": {"type": "number"} + }, + "required": ["filepath"], + "additionalProperties": False + }, + "interval": { + "type": "integer", + "minimum": 1, + "default": 60 + } + }, + "additionalProperties": False + }, + "filters": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "exec_path": {"type": "string"}, + "config_file": {"type": "string"}, + "nb_thread": { + "type": "integer", + "minimum": 1, + "maximum": 100, + "default": 5 + }, + "log_level": { + "type": "string", + "enum": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "DEVELOPER"], + "default": "WARNING" + }, + "cache_size": { + "type": "integer", + "minimum": 0, + "default": 0 + }, + "output": { + "type": "string", + "enum": ["NONE", "RAW", "LOG", "PARSED"], + "default": "NONE" + }, + "next_filter": {"type": "string"}, + "threshold": { + "type": "integer", + "default": 100 + } + }, + "required": ["name", "exec_path", "config_file"], + "additionalProperties": False + } + } + }, + "additionalProperties": False, + "required": ["version", "filters"] +} + + +######################### +# Configuration objects # +######################### +config_file = "" +filters = {} +stats_reporting = {} +######################### + +class ConfParseError(Exception): + """Raised when a configuration file couldn't be parsed""" + pass + + +def load_conf(conf=""): + global config_file + global stats_reporting + global filters + logger.debug("Configurator: Trying to open config file...") + + if conf: + config_file = conf + + try: + with open(config_file, 'r') as f: + logger.debug("Configurator: Loading config file") + configuration = json.load(f) + except Exception as e: + logger.critical("Configurator: Unable to load configuration: {}".format(e)) + raise e + + if configuration.get('version'): + logger.debug("Configurator: found a 'version' field, trying v2 format...") + try: + custom_validator(conf_v2_schema).validate(configuration) + except Exception as e: + raise ConfParseError("Incorrect configuration format: {}".format(e.message)) + filters.clear() + stats_reporting.clear() + stats_reporting = configuration['report_stats'] + for filter in configuration['filters']: + filters[filter['name']] = filter + logger.debug("Configurator: loaded v2 config successfully") + else: + logger.debug("Configurator: no 'version' field, trying v1 format...") + try: + custom_validator(conf_v1_schema).validate(configuration) + except Exception as e: + raise ConfParseError("Incorrect configuration format: {}".format(e.message)) + stats_reporting.clear() + filters.clear() + filters.update(configuration) + logger.debug("Configurator: loaded v1 config successfully") + + complete_filters_conf() + +def complete_filters_conf(): + for name, filter in filters.items(): + if name and not filter.get('name'): + filter['name'] = name + filter['status'] = psutil.STATUS_WAKING + filter['failCount'] = 0 + filter['extension'] = '.1' + filter['pid_file'] = '/var/run/darwin/{filter}{extension}.pid'.format(filter=filter['name'], extension=filter['extension']) + + if not filter['next_filter']: + filter['next_filter_unix_socket'] = 'no' + else: + filter['next_filter_unix_socket'] = '/var/sockets/darwin/{next_filter}.sock'.format( + next_filter=filter['next_filter'] + ) + + filter['socket'] = '/var/sockets/darwin/{filter}{extension}.sock'.format(filter=filter['name'], extension=filter['extension']) + filter['socket_link'] = '/var/sockets/darwin/{filter}.sock'.format(filter=filter['name']) + + filter['monitoring'] = '/var/sockets/darwin/{filter}_mon{extension}.sock'.format( + filter=filter['name'], extension=filter['extension'] + ) diff --git a/manager/manager.py b/manager/manager.py index 6a5fbd00..1e95444c 100644 --- a/manager/manager.py +++ b/manager/manager.py @@ -1,19 +1,4 @@ #!/usr/local/bin/python3 -"""This file is part of Vulture 3. - -Vulture 3 is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Vulture 3 is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Vulture 3. If not, see http://www.gnu.org/licenses/. -""" __author__ = "Hugo SOSZYNSKI" __credits__ = [] __license__ = "GPLv3" @@ -34,10 +19,12 @@ from Administration import Server from threading import Thread from time import sleep +from config import load_conf, ConfParseError +from config import filters as conf_filters # Argparse parser = argparse.ArgumentParser() -parser.add_argument('config_file', type=str, help='The config file to use') +parser.add_argument('config_file', type=str, help='The configuration file to use') parser.add_argument('-l', '--log-level', help='Set log level to DEBUG, INFO, WARNING (default), ERROR or CRITICAL', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], @@ -101,8 +88,13 @@ def rotate_logs(sigin, frame): server = Server() logger.info("Configuring...") - services = Services(args.config_file) + try: + load_conf(args.config_file) + except ConfParseError as e: + logger.critical(e) + exit(1) + services = Services(conf_filters) try: logger.info("Starting services...") services.start_all() diff --git a/manager/requirements.txt b/manager/requirements.txt new file mode 100644 index 00000000..f760beb8 --- /dev/null +++ b/manager/requirements.txt @@ -0,0 +1,3 @@ +jsonschema==3.2.0 +psutil==5.6.6 +python-daemon==2.2.4 \ No newline at end of file diff --git a/tests/manager_socket/monitor_test.py b/tests/manager_socket/monitor_test.py index 950509fe..e90452ed 100644 --- a/tests/manager_socket/monitor_test.py +++ b/tests/manager_socket/monitor_test.py @@ -1,4 +1,4 @@ -from manager_socket.utils import requests, CONF_EMPTY, CONF_FLOGS, CONF_ONE, CONF_THREE, CONF_THREE_ONE_WRONG, REQ_MONITOR, RESP_EMPTY, RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3, PATH_CONF_FLOGS +from manager_socket.utils import requests, CONF_EMPTY, CONF_FLOGS, CONF_ONE, CONF_ONE_V2, CONF_THREE, CONF_THREE_V2, CONF_THREE_ONE_WRONG, CONF_THREE_ONE_WRONG_V2, REQ_MONITOR, RESP_EMPTY, RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3, PATH_CONF_FLOGS from tools.darwin_utils import darwin_configure, darwin_remove_configuration, darwin_start, darwin_stop from tools.output import print_result @@ -6,8 +6,11 @@ def run(): tests = [ multiple_filters_running, + multiple_filters_running_conf_v2, multiple_filters_running_one_fail, + multiple_filters_running_one_fail_conf_v2, one_filters_running, + one_filters_running_conf_v2, no_filter, ] @@ -32,6 +35,23 @@ def multiple_filters_running(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def multiple_filters_running_conf_v2(): + + ret = False + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + ret = True + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + def multiple_filters_running_one_fail(): ret = False @@ -49,6 +69,24 @@ def multiple_filters_running_one_fail(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def multiple_filters_running_one_fail_conf_v2(): + + ret = False + + darwin_configure(CONF_THREE_ONE_WRONG_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_3]): + ret = True + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + def one_filters_running(): ret = False @@ -66,6 +104,23 @@ def one_filters_running(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def one_filters_running_conf_v2(): + + ret = False + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 in resp: + ret = True + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + def no_filter(): ret = False diff --git a/tests/manager_socket/update_test.py b/tests/manager_socket/update_test.py index 92e30b4d..c4493d4e 100644 --- a/tests/manager_socket/update_test.py +++ b/tests/manager_socket/update_test.py @@ -1,6 +1,6 @@ import logging from time import sleep -from manager_socket.utils import requests, check_filter_files, PATH_CONF_FLOGS, CONF_EMPTY, CONF_ONE, CONF_THREE, CONF_FLOGS, CONF_FLOGS_WRONG_CONF , REQ_MONITOR, REQ_UPDATE_EMPTY, REQ_UPDATE_ONE, REQ_UPDATE_TWO, REQ_UPDATE_THREE, REQ_UPDATE_NON_EXISTING, RESP_EMPTY, RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3, RESP_STATUS_OK, RESP_STATUS_KO, RESP_ERROR_FILTER_NOT_EXISTING +from manager_socket.utils import requests, check_filter_files, PATH_CONF_FLOGS, CONF_EMPTY, CONF_ONE, CONF_ONE_V2, CONF_THREE, CONF_THREE_V2, CONF_FLOGS, CONF_FLOGS_WRONG_CONF , REQ_MONITOR, REQ_UPDATE_EMPTY, REQ_UPDATE_ONE, REQ_UPDATE_TWO, REQ_UPDATE_THREE, REQ_UPDATE_NON_EXISTING, RESP_EMPTY, RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3, RESP_STATUS_OK, RESP_STATUS_KO, RESP_ERROR_FILTER_NOT_EXISTING from tools.darwin_utils import darwin_configure, darwin_remove_configuration, darwin_start, darwin_stop from tools.output import print_result @@ -9,20 +9,35 @@ def run(): tests = [ no_filter_to_none, no_filter_to_one, + no_filter_to_one_conf_v2, no_filter_to_many, + no_filter_to_many_conf_v2, one_filter_to_none, + one_filter_to_none_conf_v2, many_filters_to_none, + many_filters_to_none_conf_v2, many_filters_to_one, + many_filters_to_one_conf_v2, one_update_none, + one_update_none_conf_v2, one_update_one, + one_update_one_conf_v2, one_update_one_wrong_conf, + one_update_one_wrong_conf_conf_v2, many_update_none, + many_update_none_conf_v2, many_update_one, + many_update_one_conf_v2, many_update_many, + many_update_many_conf_v2, many_update_two_wrong_conf, + many_update_two_wrong_conf_conf_v2, many_update_all, + many_update_all_conf_v2, many_update_all_wrong_conf, - non_existing_filter + many_update_all_wrong_conf_conf_v2, + non_existing_filter, + non_existing_filter_conf_v2 ] for i in tests: @@ -84,6 +99,35 @@ def no_filter_to_one(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def no_filter_to_one_conf_v2(): + + ret = True + + darwin_configure(CONF_EMPTY) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_EMPTY not in resp: + logging.error("no_filter_to_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + resp = requests(REQ_UPDATE_ONE) + if RESP_STATUS_OK not in resp: + logging.error("no_filter_to_one: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("no_filter_to_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + def no_filter_to_many(): @@ -114,6 +158,34 @@ def no_filter_to_many(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def no_filter_to_many_conf_v2(): + + ret = True + + darwin_configure(CONF_EMPTY) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_EMPTY not in resp: + logging.error("no_filter_to_many: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + resp = requests(REQ_UPDATE_THREE) + if RESP_STATUS_OK not in resp: + logging.error("no_filter_to_many: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("no_filter_to_many: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret def one_filter_to_none(): @@ -128,7 +200,7 @@ def one_filter_to_none(): logging.error("one_filter_to_none: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - darwin_configure(CONF_EMPTY) + darwin_configure(CONF_EMPTY) resp = requests(REQ_UPDATE_ONE) if RESP_STATUS_OK not in resp: logging.error("one_filter_to_none: Update response error; got \"{}\"".format(resp)) @@ -144,6 +216,34 @@ def one_filter_to_none(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret +def one_filter_to_none_conf_v2(): + + ret = True + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_filter_to_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_configure(CONF_EMPTY) + resp = requests(REQ_UPDATE_ONE) + if RESP_STATUS_OK not in resp: + logging.error("one_filter_to_none: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if RESP_EMPTY not in resp: + logging.error("one_filter_to_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret def many_filters_to_none(): @@ -158,7 +258,36 @@ def many_filters_to_none(): logging.error("many_filters_to_none: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - darwin_configure(CONF_EMPTY) + darwin_configure(CONF_EMPTY) + resp = requests(REQ_UPDATE_THREE) + if RESP_STATUS_OK not in resp: + logging.error("many_filters_to_none: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if RESP_EMPTY not in resp: + logging.error("many_filters_to_none: Mismatching second monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + +def many_filters_to_none_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_filters_to_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_configure(CONF_EMPTY) resp = requests(REQ_UPDATE_THREE) if RESP_STATUS_OK not in resp: logging.error("many_filters_to_none: Update response error; got \"{}\"".format(resp)) @@ -176,7 +305,7 @@ def many_filters_to_none(): def many_filters_to_one(): - + ret = True darwin_configure(CONF_THREE) @@ -187,9 +316,41 @@ def many_filters_to_one(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("many_filters_to_one: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + darwin_configure(CONF_ONE) + resp = requests(REQ_UPDATE_TWO) + if RESP_STATUS_OK not in resp: + logging.error("many_filters_to_one: Update response error; got \"{}\"".format(resp)) + ret = False + + sleep(1) + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("many_filters_to_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def many_filters_to_one_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_filters_to_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay - darwin_configure(CONF_ONE) + darwin_configure(CONF_ONE_V2) resp = requests(REQ_UPDATE_TWO) if RESP_STATUS_OK not in resp: logging.error("many_filters_to_one: Update response error; got \"{}\"".format(resp)) @@ -208,7 +369,7 @@ def many_filters_to_one(): def one_update_none(): - + ret = True darwin_configure(CONF_ONE) @@ -219,8 +380,39 @@ def one_update_none(): if RESP_LOGS_1 not in resp: logging.error("one_update_none: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - - sleep(1) # Need this beacause of the starting delay + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_EMPTY) + if RESP_STATUS_OK not in resp: + logging.error("one_update_none: Update response error; got \"{}\"".format(resp)) + ret = False + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def one_update_none_conf_v2(): + + ret = True + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_EMPTY) if RESP_STATUS_OK not in resp: logging.error("one_update_none: Update response error; got \"{}\"".format(resp)) @@ -250,7 +442,38 @@ def one_update_one(): if RESP_LOGS_1 not in resp: logging.error("one_update_one: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(2) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_ONE) + if RESP_STATUS_OK not in resp: + logging.error("one_update_one: Update response error; got \"{}\"".format(resp)) + ret = False + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def one_update_one_conf_v2(): + + ret = True + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(2) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_ONE) if RESP_STATUS_OK not in resp: @@ -268,6 +491,7 @@ def one_update_one(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret + def one_update_one_wrong_conf(): ret = True @@ -303,8 +527,43 @@ def one_update_one_wrong_conf(): return ret +def one_update_one_wrong_conf_conf_v2(): + + ret = True + + darwin_configure(CONF_ONE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + sleep(2) # Need this because of the starting delay + darwin_configure(CONF_FLOGS_WRONG_CONF, path=PATH_CONF_FLOGS) + resp = requests(REQ_UPDATE_ONE) + if RESP_STATUS_KO not in resp: + logging.error("one_update_one_wrong_conf: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if RESP_LOGS_1 not in resp: + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + if not check_filter_files("logs_1", ".1"): + logging.error("Error: filter files check failed") + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + def many_update_none(): - + ret = True darwin_configure(CONF_THREE) @@ -315,7 +574,37 @@ def many_update_none(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("many_update_none: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_EMPTY) + if RESP_STATUS_OK not in resp: + logging.error("many_update_none: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def many_update_none_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_none: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_EMPTY) if RESP_STATUS_OK not in resp: @@ -334,7 +623,7 @@ def many_update_none(): def many_update_one(): - + ret = True darwin_configure(CONF_THREE) @@ -345,7 +634,37 @@ def many_update_one(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("many_update_one: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_ONE) + if RESP_STATUS_OK not in resp: + logging.error("many_update_one: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def many_update_one_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_one: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_ONE) if RESP_STATUS_OK not in resp: @@ -374,7 +693,36 @@ def many_update_many(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("many_update_many: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_TWO) + if RESP_STATUS_OK not in resp: + logging.error("many_update_many: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_many: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def many_update_many_conf_v2(): + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_many: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_TWO) if RESP_STATUS_OK not in resp: @@ -391,6 +739,7 @@ def many_update_many(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret + def many_update_two_wrong_conf(): ret = True @@ -429,6 +778,46 @@ def many_update_two_wrong_conf(): darwin_remove_configuration(path=PATH_CONF_FLOGS) return ret + +def many_update_two_wrong_conf_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + sleep(2) # Need this because of the starting delay + darwin_configure(CONF_FLOGS_WRONG_CONF, path=PATH_CONF_FLOGS) + resp = requests(REQ_UPDATE_TWO) + if RESP_STATUS_KO not in resp: + logging.error("one_update_one_wrong_conf: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + if not check_filter_files("logs_2", ".1"): + logging.error("Error: filter files check failed") + ret = False + + if not check_filter_files("logs_3", ".1"): + logging.error("Error: filter files check failed") + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + def many_update_all_wrong_conf(): ret = True @@ -472,8 +861,51 @@ def many_update_all_wrong_conf(): return ret +def many_update_all_wrong_conf_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + sleep(2) # Need this because of the starting delay + darwin_configure(CONF_FLOGS_WRONG_CONF, path=PATH_CONF_FLOGS) + resp = requests(REQ_UPDATE_THREE) + if RESP_STATUS_KO not in resp: + logging.error("one_update_one_wrong_conf: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("one_update_one_wrong_conf: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + if not check_filter_files("logs_1", ".1"): + logging.error("Error: filter files check failed") + ret = False + + if not check_filter_files("logs_2", ".1"): + logging.error("Error: filter files check failed") + ret = False + + if not check_filter_files("logs_3", ".1"): + logging.error("Error: filter files check failed") + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + def many_update_all(): - + ret = True darwin_configure(CONF_THREE) @@ -484,7 +916,37 @@ def many_update_all(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("many_update_all: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_THREE) + if RESP_STATUS_OK not in resp: + logging.error("many_update_all: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_all: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def many_update_all_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("many_update_all: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_THREE) if RESP_STATUS_OK not in resp: @@ -503,7 +965,7 @@ def many_update_all(): def non_existing_filter(): - + ret = True darwin_configure(CONF_THREE) @@ -514,7 +976,37 @@ def non_existing_filter(): if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): logging.error("non_existing_filter: Mismatching monitor response; got \"{}\"".format(resp)) ret = False - + + sleep(1) # Need this beacause of the starting delay + resp = requests(REQ_UPDATE_NON_EXISTING) + if RESP_ERROR_FILTER_NOT_EXISTING not in resp: + logging.error("non_existing_filter: Update response error; got \"{}\"".format(resp)) + ret = False + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("non_existing_filter: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + + darwin_stop(process) + darwin_remove_configuration() + darwin_remove_configuration(path=PATH_CONF_FLOGS) + return ret + + +def non_existing_filter_conf_v2(): + + ret = True + + darwin_configure(CONF_THREE_V2) + darwin_configure(CONF_FLOGS, path=PATH_CONF_FLOGS) + process = darwin_start() + + resp = requests(REQ_MONITOR) + if not all(x in resp for x in [RESP_LOGS_1, RESP_LOGS_2, RESP_LOGS_3]): + logging.error("non_existing_filter: Mismatching monitor response; got \"{}\"".format(resp)) + ret = False + sleep(1) # Need this beacause of the starting delay resp = requests(REQ_UPDATE_NON_EXISTING) if RESP_ERROR_FILTER_NOT_EXISTING not in resp: diff --git a/tests/manager_socket/utils.py b/tests/manager_socket/utils.py index 808dfc99..bb40da7e 100644 --- a/tests/manager_socket/utils.py +++ b/tests/manager_socket/utils.py @@ -16,18 +16,18 @@ def requests(request): sock.connect(MANAGEMENT_SOCKET_PATH) except socket.error as msg: logging.error(msg) - return None + return "" try: sock.sendall(bytes(request)) except Exception as e: logging.error("manager_socket.utils.requests: Could not send the request: " + str(e)) - return None + return "" try: response = sock.recv(4096).decode() except Exception as e: logging.error("manager_socket.utils.requests: Could not get the response: " + str(e)) - return None + return "" return response @@ -97,10 +97,38 @@ def check_filter_files(filter_name, extension=".1"): }} }} """.format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) +CONF_ONE_V2 = """{{ + "version": 2, + "filters": [ + {{ + "name": "logs_1", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }} + ], + "report_stats": {{ + "redis": {{ + "ip": "127.0.0.1", + "port": 6379, + "unix_path": "/var/sockets/redis/redis.sock" + }}, + "file": {{ + "filepath": "/tmp/darwin-stats", + "permissions": 640 + }}, + "interval": 5 + }} +}} +""".format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) CONF_THREE = """{{ "logs_1": {{ "exec_path": "{0}darwin_logs", - "config_file":"{1}", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, @@ -109,7 +137,7 @@ def check_filter_files(filter_name, extension=".1"): }}, "logs_2": {{ "exec_path": "{0}darwin_logs", - "config_file":"{1}", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, @@ -118,7 +146,7 @@ def check_filter_files(filter_name, extension=".1"): }}, "logs_3": {{ "exec_path": "{0}darwin_logs", - "config_file":"{1}", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, @@ -127,10 +155,58 @@ def check_filter_files(filter_name, extension=".1"): }} }} """.format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) +CONF_THREE_V2 = """{{ + "version": 2, + "filters": [ + {{ + "name": "logs_1", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }}, + {{ + "name": "logs_2", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }}, + {{ + "name": "logs_3", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }} + ], + "report_stats": {{ + "redis": {{ + "ip": "127.0.0.1", + "port": 6379, + "unix_path": "/var/sockets/redis/redis.sock" + }}, + "file": {{ + "filepath": "/tmp/darwin-stats", + "permissions": 640 + }}, + "interval": 5 + }} +}} +""".format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) CONF_THREE_ONE_WRONG = """{{ "logs_1": {{ "exec_path": "{0}darwin_logs", - "config_file":"{1}", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, @@ -139,7 +215,7 @@ def check_filter_files(filter_name, extension=".1"): }}, "logs_2": {{ "exec_path": "wrong_path", - "config_file":"{1}", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, @@ -148,13 +224,61 @@ def check_filter_files(filter_name, extension=".1"): }}, "logs_3": {{ "exec_path": "{0}darwin_logs", - "config_file":"{1}", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }} +}} +""".format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) +CONF_THREE_ONE_WRONG_V2 = """{{ + "version": 2, + "filters": [ + {{ + "name": "logs_1", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }}, + {{ + "name": "logs_2", + "exec_path": "wrong_path", + "config_file": "{1}", + "output": "NONE", + "next_filter": "", + "nb_thread": 1, + "log_level": "DEBUG", + "cache_size": 0 + }}, + {{ + "name": "logs_3", + "exec_path": "{0}darwin_logs", + "config_file": "{1}", "output": "NONE", "next_filter": "", "nb_thread": 1, "log_level": "DEBUG", "cache_size": 0 }} + ], + "report_stats": {{ + "redis": {{ + "ip": "127.0.0.1", + "port": 6379, + "unix_path": "/var/sockets/redis/redis.sock" + }}, + "file": {{ + "filepath": "/tmp/darwin-stats", + "permissions": 640 + }}, + "interval": 5 + }} }} """.format(DEFAULT_FILTER_PATH, PATH_CONF_FLOGS) CONF_FLOGS = """{