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

pep8

parent 5f8fff1c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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:
......
......@@ -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"
......@@ -19,4 +19,3 @@ setup(
]
},
)
......@@ -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
......
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment