diff --git a/inventory_provider/routes/ims_classifier.py b/inventory_provider/routes/ims_classifier.py index deee1741e175cf24848815a16f6d4d8715641408..393babe68661b7d5d7cacc6be6f4456c023f6601 100644 --- a/inventory_provider/routes/ims_classifier.py +++ b/inventory_provider/routes/ims_classifier.py @@ -4,10 +4,11 @@ import json import logging import re from copy import copy +from distutils.util import strtobool from functools import lru_cache from typing import Optional, Iterator, List -from flask import Blueprint, Response, current_app +from flask import Blueprint, Response, current_app, request from redis import Redis from inventory_provider.db.ims import IMS_SERVICE_NAMES @@ -296,8 +297,15 @@ def get_juniper_link_info(source_equipment: str, interface: str) -> Response: cache_key = \ f'ims-classifier-cache:juniper:{ims_source_equipment}:{ims_interface}' - # result = r.get(cache_key) - result = False + ignore_cache = request.args.get('ignore-cache', default='false', type=str) + try: + ignore_cache = strtobool(ignore_cache) + except ValueError: + ignore_cache = False + if ignore_cache: + result = False + else: + result = r.get(cache_key) if result: result = result.decode('utf-8') @@ -420,8 +428,15 @@ def peer_info(address_str: str) -> Response: cache_key = f'ims-classifier-cache:peer:{address_str}' - # result = r.get(cache_key) - result = False + ignore_cache = request.args.get('ignore-cache', default='false', type=str) + try: + ignore_cache = strtobool(ignore_cache) + except ValueError: + ignore_cache = False + if ignore_cache: + result = False + else: + result = r.get(cache_key) if result: result = result.decode('utf-8') @@ -494,8 +509,15 @@ def get_trap_metadata(source_equipment: str, interface: str, circuit_id: str) \ r = common.get_current_redis() - result = r.get(cache_key) - result = False + ignore_cache = request.args.get('ignore-cache', default='false', type=str) + try: + ignore_cache = strtobool(ignore_cache) + except ValueError: + ignore_cache = False + if ignore_cache: + result = False + else: + result = r.get(cache_key) if result: result = result.decode('utf-8') @@ -573,8 +595,15 @@ def get_fiberlink_trap_metadata(ne_name_str: str, object_name_str: str) \ cache_key = \ f'ims-classifier-cache:fiberlink:{ne_name_str}:{object_name_str}' - # result = r.get(cache_key) - result = False + ignore_cache = request.args.get('ignore-cache', default='false', type=str) + try: + ignore_cache = strtobool(ignore_cache) + except ValueError: + ignore_cache = False + if ignore_cache: + result = False + else: + result = r.get(cache_key) if result: result = result.decode('utf-8') @@ -656,8 +685,15 @@ def get_coriant_info(equipment_name: str, entity_string: str) -> Response: cache_key = 'ims-classifier-cache:coriant:%s:%s' % ( equipment_name, entity_string) - # result = r.get(cache_key) - result = False + ignore_cache = request.args.get('ignore-cache', default='false', type=str) + try: + ignore_cache = strtobool(ignore_cache) + except ValueError: + ignore_cache = False + if ignore_cache: + result = False + else: + result = r.get(cache_key) if result: result = result.decode('utf-8') diff --git a/inventory_provider/tasks/ims_worker.py b/inventory_provider/tasks/ims_worker.py index d792cabc89ec8012a74fa78d0c8d6a475ff3a673..123872c25cef32bdd8eeef1ad5fc27b040f2e09a 100644 --- a/inventory_provider/tasks/ims_worker.py +++ b/inventory_provider/tasks/ims_worker.py @@ -25,7 +25,12 @@ logger = logging.getLogger(__name__) @app.task(base=InventoryTask, bind=True, name='update_fibre_spans_ims') @log_task_entry_and_exit def update_fibre_spans(self, use_current=False): - r = get_next_redis(InventoryTask.config) + + if use_current: + r = get_current_redis(InventoryTask.config) + # scan with bigger batches, to mitigate network latency effects + else: + r = get_next_redis(InventoryTask.config) rp = r.pipeline() # scan with bigger batches, to mitigate network latency effects for key in r.scan_iter('ims:ne_fibre_spans:*', count=1000): @@ -50,7 +55,6 @@ def update_interfaces_to_port_ids_ims(self, use_current=False): if use_current: r = get_current_redis(InventoryTask.config) - # scan with bigger batches, to mitigate network latency effects else: r = get_next_redis(InventoryTask.config)