Skip to content
Snippets Groups Projects
Commit 1bf78e22 authored by David Schmitz's avatar David Schmitz
Browse files

fix/checksync_use_getconfig_cache

parent 2174a639
Branches
No related tags found
No related merge requests found
......@@ -467,18 +467,27 @@ class Route(models.Model):
self.save()
def check_sync(self):
if not self.is_synced():
def check_sync(self, netconf_device_queried=None):
if not self.is_synced(netconf_device_queried=netconf_device_queried):
#self.status = "OUTOFSYNC"
#self.save()
self.update_status("OUTOFSYNC")
def is_synced(self):
def is_synced(self, netconf_device_queried=None):
logger.info('models::is_synced(): self='+str(self))
found = False
try:
get_device = PR.Retriever()
device = get_device.fetch_device()
routes = device.routing_options[0].routes
# allows for caching of NETCONF GetConfig query, e.g., during tasks::check_sync
if netconf_device_queried==None:
logger.info("models::is_synced(): querying routes newly from NETCONF router")
get_device = PR.Retriever()
parsed_netconf_xml__device_obj = get_device.fetch_device()
else:
logger.info("models::is_synced(): reusing cached query from NETCONF router")
parsed_netconf_xml__device_obj = netconf_device_queried
parsed_netconf_xml__flows = parsed_netconf_xml__device_obj.routing_options
#logger.info('models::is_synced(): parsed_netconf_xml__flows='+str(parsed_netconf_xml__flows))
except Exception as e:
#self.status = "EXPIRED"
#self.save()
......@@ -486,7 +495,9 @@ class Route(models.Model):
logger.error('models::is_synced(): No routing options on device. Exception: %s' % e)
return True
for route in routes:
for flow in parsed_netconf_xml__flows:
for route in flow.routes:
#logger.debug('models::is_synced(): loop flow='+str(flow)+' route='+str(route))
if route.name == self.name:
found = True
logger.debug('models::is_synced(): Found a matching rule name')
......
......@@ -278,6 +278,15 @@ def check_sync(route_name=None, selected_routes=[]):
routes = selected_routes
if route_name:
routes = routes.filter(name=route_name)
try:
logger.info("tasks::check_sync(): making single query whose result is to be used during loop processing")
get_device = PR.Retriever()
device = get_device.fetch_device()
except Exception as e:
logger.info("tasks::check_sync(): exception occured during get active routes on router: "+str(e))
return
for route in routes:
if route.has_expired() and (route.status != 'EXPIRED' and route.status != 'ADMININACTIVE' and route.status != 'INACTIVE' and route.status != 'INACTIVE_TODELETE' and route.status != 'PENDING_TODELETE'):
if route.status != 'ERROR':
......@@ -286,7 +295,7 @@ def check_sync(route_name=None, selected_routes=[]):
else:
if route.status != 'EXPIRED':
old_status = route.status
route.check_sync()
route.check_sync(netconf_device_queried=device)
new_status = route.status
if old_status != new_status:
logger.info('status of rule changed during check_sync %s : %s -> %s' % (route.name, old_status, new_status))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment