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

Merge branch 'hotfix/POL1-753-timeout-and-none' into 'develop'

address issues with some speeds not being recognised, a timeout issue not...

See merge request !23
parents e9277c75 2798ae5c
No related branches found
No related tags found
1 merge request!23address issues with some speeds not being recognised, a timeout issue not...
...@@ -4,6 +4,7 @@ import re ...@@ -4,6 +4,7 @@ import re
import ipaddress import ipaddress
import ncclient import ncclient
import ncclient.operations
import ncclient.manager import ncclient.manager
from jnpr.junos import Device from jnpr.junos import Device
from jnpr.junos import exception as EzErrors from jnpr.junos import exception as EzErrors
...@@ -138,7 +139,7 @@ def _nc_connection(host_params, ssh_params): ...@@ -138,7 +139,7 @@ def _nc_connection(host_params, ssh_params):
try: try:
yield conn # wait here until caller context ends yield conn # wait here until caller context ends
except EzErrors.ConnectTimeoutError: except (EzErrors.ConnectTimeoutError, ncclient.operations.errors.TimeoutExpiredError):
raise TimeoutError raise TimeoutError
finally: finally:
conn.close_session() conn.close_session()
......
...@@ -84,6 +84,7 @@ routes = Blueprint('poller-support-routes', __name__) ...@@ -84,6 +84,7 @@ routes = Blueprint('poller-support-routes', __name__)
Mb = 1 << 20 Mb = 1 << 20
Gb = 1 << 30 Gb = 1 << 30
OC = Mb * 51.84
class INTERFACE_TYPES(Enum): class INTERFACE_TYPES(Enum):
...@@ -713,8 +714,6 @@ def _add_speeds(interfaces): ...@@ -713,8 +714,6 @@ def _add_speeds(interfaces):
nc_ifc = netconf_interface_index.get(f"{ifc['router']}---{ifc['name']}", {}) nc_ifc = netconf_interface_index.get(f"{ifc['router']}---{ifc['name']}", {})
if 'speed' in nc_ifc: if 'speed' in nc_ifc:
ifc['speed'] = nc_ifc['speed'] ifc['speed'] = nc_ifc['speed']
else:
ifc['speed'] = ''
yield ifc yield ifc
...@@ -726,6 +725,9 @@ def _add_bundle_parents(interfaces, hostname=None): ...@@ -726,6 +725,9 @@ def _add_bundle_parents(interfaces, hostname=None):
:param hostname: hostname or None for all :param hostname: hostname or None for all
:return: generator with bundle-parents populated in each element :return: generator with bundle-parents populated in each element
""" """
def _get_base_name(name):
return name.split('.')[0]
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 # create a quick look-up for interface details
...@@ -734,8 +736,8 @@ def _add_bundle_parents(interfaces, hostname=None): ...@@ -734,8 +736,8 @@ def _add_bundle_parents(interfaces, hostname=None):
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 = _get_base_name(ifc['name'])
bundle_parents = [interface_index.get(f"{ifc['router']}---{bundle_ifc}") bundle_parents = [interface_index.get(f"{ifc['router']}---{_get_base_name(bundle_ifc)}")
for bundle_ifc in router_bundle.get(base_ifc, [])] for bundle_ifc in router_bundle.get(base_ifc, [])]
ifc['bundle-parents'] = bundle_parents ifc['bundle-parents'] = bundle_parents
yield ifc yield ifc
...@@ -878,25 +880,32 @@ def interface_speed(ifc): ...@@ -878,25 +880,32 @@ def interface_speed(ifc):
return -1 return -1
def _get_speed(ifc): def _get_speed(ifc):
rate_conversions = { rate_conversions = {
"mbps": Mb, "mbps": Mb,
"gbps": Gb "gbps": Gb
} }
if "speed" in ifc: if "speed" in ifc:
speed = ifc["speed"] speed = ifc["speed"]
match = re.match(r"(\d+)(.+)", speed) rate_match = re.match(r"(\d+)(.+)", speed)
if match: if rate_match:
value = int(match.group(1)) value = int(rate_match.group(1))
rate = match.group(2).strip().lower() rate = rate_match.group(2).strip().lower()
if rate in rate_conversions: if rate in rate_conversions:
return value * rate_conversions[rate] return int(value * rate_conversions[rate])
else: else:
logger.warning(f'unrecognised rate: {rate}, using _name_to_speed fallback') logger.warning(f'unrecognised rate: {rate}, using _name_to_speed fallback')
return _name_to_speed(ifc['name']) return _name_to_speed(ifc['name'])
else: else:
logger.warning(f'unrecognised speed: {speed}, using _name_to_speed fallback') oc_match = re.match(r"OC(\d+)", speed)
return _name_to_speed(ifc['name']) if oc_match:
value = int(oc_match.group(1))
return int(value * OC)
else:
logger.warning(f'unrecognised speed: {speed}, using _name_to_speed fallback')
return _name_to_speed(ifc['name'])
else: else:
logger.warning('no speed data for interface, using _name_to_speed fallback') logger.warning('no speed data for interface, using _name_to_speed fallback')
return _name_to_speed(ifc['name']) return _name_to_speed(ifc['name'])
...@@ -905,9 +914,9 @@ def interface_speed(ifc): ...@@ -905,9 +914,9 @@ def interface_speed(ifc):
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(_get_speed(parent_ifc) for parent_ifc in ifc['bundle-parents']) return int(sum(_get_speed(parent_ifc) for parent_ifc in ifc['bundle-parents']))
return _get_speed(ifc) return int(_get_speed(ifc))
def _load_interfaces_and_speeds(hostname=None): def _load_interfaces_and_speeds(hostname=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment