Skip to content
Snippets Groups Projects

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

Merged Sam Roberts requested to merge hotfix/POL1-753-timeout-and-none into develop
2 files
+ 24
14
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -84,6 +84,7 @@ routes = Blueprint('poller-support-routes', __name__)
Mb = 1 << 20
Gb = 1 << 30
OC = Mb * 51.84
class INTERFACE_TYPES(Enum):
@@ -713,8 +714,6 @@ def _add_speeds(interfaces):
nc_ifc = netconf_interface_index.get(f"{ifc['router']}---{ifc['name']}", {})
if 'speed' in nc_ifc:
ifc['speed'] = nc_ifc['speed']
else:
ifc['speed'] = ''
yield ifc
@@ -726,6 +725,9 @@ def _add_bundle_parents(interfaces, hostname=None):
:param hostname: hostname or None for all
:return: generator with bundle-parents populated in each element
"""
def _get_base_name(name):
return name.split('.')[0]
bundles = _load_interface_bundles(
current_app.config['INVENTORY_PROVIDER_CONFIG'], hostname)
# create a quick look-up for interface details
@@ -734,8 +736,8 @@ def _add_bundle_parents(interfaces, hostname=None):
for ifc in interfaces:
router_bundle = bundles.get(ifc['router'], None)
if router_bundle:
base_ifc = ifc['name'].split('.')[0]
bundle_parents = [interface_index.get(f"{ifc['router']}---{bundle_ifc}")
base_ifc = _get_base_name(ifc['name'])
bundle_parents = [interface_index.get(f"{ifc['router']}---{_get_base_name(bundle_ifc)}")
for bundle_ifc in router_bundle.get(base_ifc, [])]
ifc['bundle-parents'] = bundle_parents
yield ifc
@@ -878,25 +880,32 @@ def interface_speed(ifc):
return -1
def _get_speed(ifc):
rate_conversions = {
"mbps": Mb,
"gbps": Gb
}
if "speed" in ifc:
speed = ifc["speed"]
match = re.match(r"(\d+)(.+)", speed)
if match:
value = int(match.group(1))
rate = match.group(2).strip().lower()
rate_match = re.match(r"(\d+)(.+)", speed)
if rate_match:
value = int(rate_match.group(1))
rate = rate_match.group(2).strip().lower()
if rate in rate_conversions:
return value * rate_conversions[rate]
return int(value * rate_conversions[rate])
else:
logger.warning(f'unrecognised rate: {rate}, using _name_to_speed fallback')
return _name_to_speed(ifc['name'])
else:
logger.warning(f'unrecognised speed: {speed}, using _name_to_speed fallback')
return _name_to_speed(ifc['name'])
oc_match = re.match(r"OC(\d+)", speed)
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:
logger.warning('no speed data for interface, using _name_to_speed fallback')
return _name_to_speed(ifc['name'])
@@ -905,9 +914,9 @@ def interface_speed(ifc):
if not ifc['name'].startswith('ae'):
logger.warning(
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):
Loading