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

validate router fqdn

parent 158b5236
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,12 @@ import click ...@@ -8,13 +8,12 @@ import click
import jsonschema import jsonschema
from brian_polling_manager.interface_stats import config, brian, errors, juniper from brian_polling_manager.interface_stats import config, brian, errors, juniper
from brian_polling_manager import influx from brian_polling_manager import influx, inventory
import logging.config import logging.config
import os import os
LOGGING_DEFAULT_CONFIG = { LOGGING_DEFAULT_CONFIG = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
...@@ -106,7 +105,7 @@ def _validate_hostname(_unused_ctx, _unused_param, hostname): ...@@ -106,7 +105,7 @@ def _validate_hostname(_unused_ctx, _unused_param, hostname):
except socket.error: except socket.error:
raise click.BadParameter(f'{hostname} is not resolveable') raise click.BadParameter(f'{hostname} is not resolveable')
def _brian_points(router_fqdn, netconf_doc, timestamp, measurement_name): def _brian_points(router_fqdn, netconf_doc, timestamp, measurement_name):
_ctr2point = partial(ctr2point, measurement_name, timestamp) _ctr2point = partial(ctr2point, measurement_name, timestamp)
...@@ -136,10 +135,18 @@ def _main(router_fqdn: str, app_config_params: dict): ...@@ -136,10 +135,18 @@ def _main(router_fqdn: str, app_config_params: dict):
callable entry point, without click callable entry point, without click
... tmp, for testing ... tmp, for testing
note: the optional inventory param is only used to validate the hostname
:param router_fqdn:
:param app_config_params: :param app_config_params:
:return: :return:
""" """
if 'inventory' in app_config_params:
all_routers = {_ifc['router'] for _ifc in inventory.load_interfaces()}
if router_fqdn not in all_routers:
raise ValueError(f'{router_fqdn} must be one of: {all_routers}')
setup_logging() setup_logging()
netconf_doc = juniper.get_interface_info_ncrpc(router_fqdn) netconf_doc = juniper.get_interface_info_ncrpc(router_fqdn)
......
...@@ -54,7 +54,7 @@ CONFIG_SCHEMA = { ...@@ -54,7 +54,7 @@ CONFIG_SCHEMA = {
'additionalProperties': False 'additionalProperties': False
}, },
}, },
'required': ['ssh-config', 'inventory', 'influx'], 'required': ['ssh-config', 'influx'],
'additionalProperties': False 'additionalProperties': False
} }
......
...@@ -195,6 +195,7 @@ def app_config_params(free_host_port): ...@@ -195,6 +195,7 @@ def app_config_params(free_host_port):
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
yield { yield {
'ssh-config': f.name, 'ssh-config': f.name,
'inventory': ['http://blah'],
'influx': { 'influx': {
'brian-counters': { 'brian-counters': {
'hostname': 'localhost', 'hostname': 'localhost',
...@@ -422,8 +423,11 @@ def test_e2e(app_config_params, ifc_netconf_rpc, testenv_containers): ...@@ -422,8 +423,11 @@ def test_e2e(app_config_params, ifc_netconf_rpc, testenv_containers):
# TODO: srx's are excluded for now, since there's no test data # TODO: srx's are excluded for now, since there's no test data
if not _h['router'].startswith('srx') if not _h['router'].startswith('srx')
} }
for router_fqdn in managed_routers:
cli._main(router_fqdn=router_fqdn, app_config_params=app_config_params) with patch('brian_polling_manager.inventory.load_interfaces') as inventory:
inventory.return_value = poller_interfaces()
for router_fqdn in managed_routers:
cli._main(router_fqdn=router_fqdn, app_config_params=app_config_params)
def verify_influx_content(influx_config, expected_fields): def verify_influx_content(influx_config, expected_fields):
# for each expected field, verify that there's # for each expected field, verify that there's
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment