diff --git a/brian_polling_manager/cli.py b/brian_polling_manager/cli.py index ea01e1ac5367d25b1aafc49d9777a40386eb2779..6711ed41ade9b6cb233016a94b562a2cafbb1ab7 100644 --- a/brian_polling_manager/cli.py +++ b/brian_polling_manager/cli.py @@ -54,7 +54,9 @@ _DEFAULT_CONFIG = { 'output_metric_handlers': ['influx-db-handler'], 'namespace': 'default', 'round_robin': True, - 'command': '{script} {measurement} {community} {hostname} {interface} {ifIndex}', + 'command': ('{script} {measurement} ' + '{community} {hostname} ' + '{interface} {ifIndex}'), } }, 'statedir': '/tmp/' @@ -166,12 +168,16 @@ class State(object): @property def interfaces(self) -> list: - return State._load_json(self.filenames['cache'], inventory.INVENTORY_INTERFACES_SCHEMA) + return State._load_json( + self.filenames['cache'], + inventory.INVENTORY_INTERFACES_SCHEMA) @interfaces.setter def interfaces(self, new_interfaces): try: - jsonschema.validate(new_interfaces, inventory.INVENTORY_INTERFACES_SCHEMA) + jsonschema.validate( + new_interfaces, + inventory.INVENTORY_INTERFACES_SCHEMA) except jsonschema.ValidationError: logger.exception('invalid interface state data') return diff --git a/brian_polling_manager/interfaces.py b/brian_polling_manager/interfaces.py index f50b975cafd3a0fa87b8926505682d96c73bd1e7..4c47e5969b38bc578c27d1a5b6be7e3688fa0026 100644 --- a/brian_polling_manager/interfaces.py +++ b/brian_polling_manager/interfaces.py @@ -5,12 +5,13 @@ from brian_polling_manager import sensu logger = logging.getLogger(__name__) + def load_ifc_checks(sensu_params): def _is_ifc_check(check): name = check['metadata']['name'] return re.match(r'^check-([^-]+\.geant\.net)-(.+)$', name) ifc_checks = filter(_is_ifc_check, sensu.load_all_checks(sensu_params)) - return {c['metadata']['name']:c for c in ifc_checks} + return {c['metadata']['name']: c for c in ifc_checks} def _check_name(interface): @@ -35,7 +36,8 @@ def _make_check(check_params, interface): 'proxy_entity_name': interface['router'], 'round_robin': check_params['round_robin'], 'output_metric_format': 'influxdb_line', - 'output_metric_handlers': sorted(check_params['output_metric_handlers']), + 'output_metric_handlers': sorted( + check_params['output_metric_handlers']), 'metadata': { 'name': _check_name(interface), 'namespace': check_params['namespace'] @@ -56,7 +58,8 @@ def _checks_match(a, b) -> bool: return False if sorted(a['subscriptions']) != sorted(b['subscriptions']): return False - if sorted(a['output_metric_handlers']) != sorted(b['output_metric_handlers']): + if sorted(a['output_metric_handlers']) \ + != sorted(b['output_metric_handlers']): return False if a['metadata']['name'] != b['metadata']['name']: return False @@ -71,7 +74,8 @@ def refresh(sensu_params, state): for interface in state.interfaces: - expected_check = _make_check(sensu_params['interface-check'], interface) + expected_check = _make_check( + sensu_params['interface-check'], interface) expected_name = _check_name(interface) if expected_name not in ifc_checks: diff --git a/docs/source/conf.py b/docs/source/conf.py index b09ad6206684687a155098f75421e9d955f763b4..2db47d2af9be401adc20354305d350e8eb9ef255 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -27,6 +27,7 @@ sys.path.insert(0, os.path.abspath( os.path.dirname(__file__), '..', '..', 'brian_polling_manager'))) + class RenderAsJSON(Directive): # cf. https://stackoverflow.com/a/59883833 @@ -97,4 +98,3 @@ html_static_path = ['_static'] # are concatenated and inserted. autoclass_content = "both" autodoc_typehints = "none" - diff --git a/setup.py b/setup.py index f53e1c4118a819da753048aed7516a17c33f3bee..0189d12398684ac8e477511cf99253e2189a75dd 100644 --- a/setup.py +++ b/setup.py @@ -19,4 +19,3 @@ setup( ] }, ) - diff --git a/test/conftest.py b/test/conftest.py index ea94ef8e3d16ea45a570671607994f04636a94cb..9d1320066b0b6b27fa4034e5afdb6ac8af71605c 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -41,7 +41,9 @@ def config(): 'output_metric_handlers': ['influx-db-handler'], 'namespace': 'default', 'round_robin': True, - 'command': '{script} {measurement} {community} {hostname} {interface} {ifIndex}', + 'command': ('{script} {measurement} ' + '{community} {hostname} ' + '{interface} {ifIndex}'), } }, 'statedir': state_dir_name @@ -66,7 +68,10 @@ def mocked_sensu(): 'proxy_entity_name': {'type': 'string'}, 'round_robin': {'type': 'boolean'}, 'output_metric_format': {'enum': ['influxdb_line']}, - 'output_metric_handlers': {'type': 'array', 'items': {'type': 'string'}}, + 'output_metric_handlers': { + 'type': 'array', + 'items': {'type': 'string'} + }, 'metadata': { 'type': 'object', 'properties': { @@ -122,7 +127,8 @@ def mocked_sensu(): # mocked api for updating a check responses.add_callback( method=responses.PUT, - url=re.compile(r'.*sensu.+/api/core/v2/namespaces/[^\/]+/checks/[^\/]+$'), + url=re.compile( + r'.*sensu.+/api/core/v2/namespaces/[^\/]+/checks/[^\/]+$'), callback=update_check_callback) def delete_check_callback(request): @@ -134,7 +140,8 @@ def mocked_sensu(): # mocked api for deleting a check responses.add_callback( method=responses.DELETE, - url=re.compile(r'.*sensu.+/api/core/v2/namespaces/[^\/]+/checks/[^\/]+$'), + url=re.compile( + r'.*sensu.+/api/core/v2/namespaces/[^\/]+/checks/[^\/]+$'), callback=delete_check_callback) yield saved_sensu_checks diff --git a/test/test_sensu_checks.py b/test/test_sensu_checks.py index fef3645f040eee394f156c07405b7ebf553ea188..7a5a8178cfd72ff4d3d6a1899b1d1012e45f5df4 100644 --- a/test/test_sensu_checks.py +++ b/test/test_sensu_checks.py @@ -15,7 +15,8 @@ def test_load_checks(config, mocked_sensu): @responses.activate def test_check_lifecycle(config, mocked_sensu, mocked_inventory): - test_interface = random.choice(inventory.load_interfaces(config['inventory'])) + test_interface = random.choice( + inventory.load_interfaces(config['inventory'])) test_interface['name'] = 'xyz' new_check = interfaces._make_check(