Skip to content
Snippets Groups Projects
Commit 78ccaa1c authored by Sam Roberts's avatar Sam Roberts
Browse files

fix timeout issue and speeds not being collected properly

parent d7f0d8ef
Branches
Tags
2 merge requests!22Feature/pol1 744 fix speed issues,!21Draft: Feature/pol1 744 fix speed issues
...@@ -122,7 +122,7 @@ class TimeoutError(Exception): ...@@ -122,7 +122,7 @@ class TimeoutError(Exception):
pass pass
TIMEOUT = 3.0 TIMEOUT = 30.0
@contextlib.contextmanager @contextlib.contextmanager
......
...@@ -207,7 +207,6 @@ INTERFACE_LIST_SCHEMA = { ...@@ -207,7 +207,6 @@ INTERFACE_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/interface'} 'items': {'$ref': '#/definitions/interface'}
} }
INTERFACE_SPEED_LIST_SCHEMA = { INTERFACE_SPEED_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft-07/schema#', '$schema': 'https://json-schema.org/draft-07/schema#',
...@@ -344,7 +343,6 @@ GWS_DIRECT_DATA_SCHEMA = { ...@@ -344,7 +343,6 @@ GWS_DIRECT_DATA_SCHEMA = {
'items': {'$ref': '#/definitions/interface-counters'} 'items': {'$ref': '#/definitions/interface-counters'}
} }
SERVICES_LIST_SCHEMA = { SERVICES_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft-07/schema#', '$schema': 'https://json-schema.org/draft-07/schema#',
...@@ -405,7 +403,6 @@ SERVICES_LIST_SCHEMA = { ...@@ -405,7 +403,6 @@ SERVICES_LIST_SCHEMA = {
'items': {'$ref': '#/definitions/service'} 'items': {'$ref': '#/definitions/service'}
} }
STRING_LIST_SCHEMA = { STRING_LIST_SCHEMA = {
'$schema': 'https://json-schema.org/draft-07/schema#', '$schema': 'https://json-schema.org/draft-07/schema#',
'type': 'array', 'type': 'array',
...@@ -490,7 +487,6 @@ def _get_dashboards(interface): ...@@ -490,7 +487,6 @@ def _get_dashboards(interface):
def _get_dashboard_data(ifc, customers): def _get_dashboard_data(ifc, customers):
def _get_interface_type(description): def _get_interface_type(description):
if re.match(r'^PHY', description): if re.match(r'^PHY', description):
return INTERFACE_TYPES.PHYSICAL return INTERFACE_TYPES.PHYSICAL
...@@ -573,7 +569,6 @@ def _load_interface_bundles(config, hostname=None, use_next_redis=False): ...@@ -573,7 +569,6 @@ def _load_interface_bundles(config, hostname=None, use_next_redis=False):
key_pattern=key_pattern, key_pattern=key_pattern,
num_threads=20, num_threads=20,
use_next_redis=use_next_redis): use_next_redis=use_next_redis):
m = re.match( m = re.match(
r'.*netconf-interface-bundles:([^:]+):(.+)', doc['key']) r'.*netconf-interface-bundles:([^:]+):(.+)', doc['key'])
assert m assert m
...@@ -664,7 +659,6 @@ def _load_netconf_docs( ...@@ -664,7 +659,6 @@ def _load_netconf_docs(
key_pattern=filter_pattern, key_pattern=filter_pattern,
num_threads=10, num_threads=10,
use_next_redis=use_next_redis): use_next_redis=use_next_redis):
yield { yield {
'router': doc['key'][key_prefix_len:], 'router': doc['key'][key_prefix_len:],
'netconf': doc['value'] 'netconf': doc['value']
...@@ -681,6 +675,7 @@ def _load_interfaces( ...@@ -681,6 +675,7 @@ def _load_interfaces(
:param use_next_redis: :param use_next_redis:
:return: :return:
""" """
def _load_docs(key_pattern): def _load_docs(key_pattern):
for doc in _load_netconf_docs(config, key_pattern, use_next_redis): for doc in _load_netconf_docs(config, key_pattern, use_next_redis):
...@@ -705,6 +700,19 @@ def _load_interfaces( ...@@ -705,6 +700,19 @@ def _load_interfaces(
yield from _load_docs(f'lab:{base_key_pattern}') yield from _load_docs(f'lab:{base_key_pattern}')
def _add_speeds(config, interfaces):
all_netconf_interfaces = list(common.load_json_docs(config, 'classifier-cache:netconf-interfaces:all'))
netconf_interface_index = {f"{ifc['router']}---{ifc['name']}": ifc for ifc in all_netconf_interfaces[0]['value']}
for ifc in interfaces:
netconf_interface = netconf_interface_index.get(f"{ifc['router']}---{ifc['name']}", {})
if 'speed' in netconf_interface:
ifc['speed'] = netconf_interface['speed']
else:
ifc['speed'] = ''
yield ifc
def _add_bundle_parents(interfaces, hostname=None): def _add_bundle_parents(interfaces, hostname=None):
""" """
generator that adds bundle-parents info to each interface. generator that adds bundle-parents info to each interface.
...@@ -715,12 +723,16 @@ def _add_bundle_parents(interfaces, hostname=None): ...@@ -715,12 +723,16 @@ def _add_bundle_parents(interfaces, hostname=None):
""" """
bundles = _load_interface_bundles( bundles = _load_interface_bundles(
current_app.config['INVENTORY_PROVIDER_CONFIG'], hostname) current_app.config['INVENTORY_PROVIDER_CONFIG'], hostname)
# create a quick look-up for interface details
interface_index = {f"{ifc['router']}---{ifc['name']}": ifc for ifc in interfaces}
for ifc in interfaces: for ifc in interfaces:
router_bundle = bundles.get(ifc['router'], None) router_bundle = bundles.get(ifc['router'], None)
if router_bundle: if router_bundle:
base_ifc = ifc['name'].split('.')[0] base_ifc = ifc['name'].split('.')[0]
ifc['bundle-parents'] = router_bundle.get(base_ifc, []) bundle_parents = [interface_index.get(f"{ifc['router']}---{bundle_ifc}")
for bundle_ifc in router_bundle.get(base_ifc, [])]
ifc['bundle-parents'] = bundle_parents
yield ifc yield ifc
...@@ -780,6 +792,7 @@ def load_interfaces_to_poll( ...@@ -780,6 +792,7 @@ def load_interfaces_to_poll(
yield ifc yield ifc
else: else:
continue continue
return _get_populated_interfaces(basic_interfaces) return _get_populated_interfaces(basic_interfaces)
...@@ -880,13 +893,14 @@ def interface_speed(ifc): ...@@ -880,13 +893,14 @@ def interface_speed(ifc):
logger.warning(f'unrecognised speed: {speed}, using _name_to_speed fallback') logger.warning(f'unrecognised speed: {speed}, using _name_to_speed fallback')
return _name_to_speed(ifc['name']) return _name_to_speed(ifc['name'])
else: else:
logger.warning(f'no speed data for interface, using _name_to_speed fallback')
return _name_to_speed(ifc['name']) return _name_to_speed(ifc['name'])
if ifc['bundle-parents']: if ifc['bundle-parents']:
if not ifc['name'].startswith('ae'): if not ifc['name'].startswith('ae'):
logger.warning( logger.warning(
f'ifc has bundle-parents, but name is {ifc["name"]}') f'ifc has bundle-parents, but name is {ifc["name"]}')
return sum(_name_to_speed(name) for name in ifc['bundle-parents']) return sum(_get_speed(parent_ifc) for parent_ifc in ifc['bundle-parents'])
return _get_speed(ifc) return _get_speed(ifc)
...@@ -903,7 +917,10 @@ def _load_interfaces_and_speeds(hostname=None): ...@@ -903,7 +917,10 @@ def _load_interfaces_and_speeds(hostname=None):
current_app.config['INVENTORY_PROVIDER_CONFIG'], current_app.config['INVENTORY_PROVIDER_CONFIG'],
hostname, hostname,
no_lab=no_lab) no_lab=no_lab)
with_bundles = _add_bundle_parents(basic_interfaces, hostname) basic_interfaces_with_speeds = _add_speeds(
current_app.config['INVENTORY_PROVIDER_CONFIG'],
basic_interfaces)
with_bundles = _add_bundle_parents(list(basic_interfaces_with_speeds), hostname)
def _result_ifc(ifc): def _result_ifc(ifc):
return { return {
...@@ -1007,9 +1024,9 @@ def eumetsat_multicast(hostname=None): ...@@ -1007,9 +1024,9 @@ def eumetsat_multicast(hostname=None):
} for idx in range(1, 73)] } for idx in range(1, 73)]
SUBSCRIPTIONS.append( SUBSCRIPTIONS.append(
{'subscription': '232.223.223.1', 'endpoint': '193.17.9.7'}) {'subscription': '232.223.223.1', 'endpoint': '193.17.9.7'})
SUBSCRIPTIONS.append( SUBSCRIPTIONS.append(
{'subscription': '232.223.223.22', 'endpoint': '193.17.9.7'}) {'subscription': '232.223.223.22', 'endpoint': '193.17.9.7'})
def _oid(sub): def _oid(sub):
return ('1.3.6.1.2.1.83.1.1.2.1.16' return ('1.3.6.1.2.1.83.1.1.2.1.16'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment