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

remove all cached classifier responses for any changes

parent 9fa293f7
No related branches found
No related tags found
No related merge requests found
......@@ -253,24 +253,37 @@ def load_netconf_data(hostname):
return etree.fromstring(netconf.decode('utf-8'))
def clear_cached_classifier_responses(hostname):
def clear_cached_classifier_responses(hostname=None):
logger = logging.getLogger(__name__)
logger.debug(
'removing cached classifier responses for %r' % hostname)
if hostname:
logger.debug(
'removing cached classifier responses for %r' % hostname)
else:
logger.debug('removing all cached classifier responses')
r = get_redis(InventoryTask.config)
for k in r.keys('classifier:cache:%s:*' % hostname):
r.delete(k)
# TODO: very inefficient ... but logically simplest at this point
for k in r.keys('classifier:peer-cache:*'):
value = r.get(k.decode('utf-8'))
if not value:
# deleted in another thread
continue
value = json.loads(value.decode('utf-8'))
interfaces = value.get('interfaces', [])
if hostname in [i['interface']['router'] for i in interfaces]:
r.delete(k)
def _hostname_keys():
for k in r.keys('classifier:cache:%s:*' % hostname):
yield k
# TODO: very inefficient ... but logically simplest at this point
for k in r.keys('classifier:peer-cache:*'):
value = r.get(k.decode('utf-8'))
if not value:
# deleted in another thread
continue
value = json.loads(value.decode('utf-8'))
interfaces = value.get('interfaces', [])
if hostname in [i['interface']['router'] for i in interfaces]:
yield k
def _all_keys():
return r.keys('classifier:*')
keys_to_delete = _hostname_keys() if hostname else _all_keys()
for k in keys_to_delete:
r.delete(k)
def _refresh_peers(hostname, key_base, peers):
......@@ -386,7 +399,7 @@ def reload_router_config(self, hostname):
refresh_vpn_rr_peers(hostname, netconf_doc)
refresh_interface_address_lookups(hostname, netconf_doc)
refresh_juniper_interface_list(hostname, netconf_doc)
clear_cached_classifier_responses(hostname)
# clear_cached_classifier_responses(hostname)
# load snmp indexes
community = juniper.snmp_community_string(netconf_doc)
......@@ -403,6 +416,8 @@ def reload_router_config(self, hostname):
})
snmp_refresh_interfaces.apply(args=[hostname, community])
clear_cached_classifier_responses(None)
logger.debug('<<< reload_router_config')
return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment