From 831e34f185a26de4c87ac5e882602268e6470187 Mon Sep 17 00:00:00 2001 From: David Schmitz <schmitz@lrz.de> Date: Wed, 3 May 2023 13:24:03 +0000 Subject: [PATCH] fix/checksync broken when no active routes exist on the router --- flowspec/models.py | 9 ++++++--- flowspec/tasks.py | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/flowspec/models.py b/flowspec/models.py index 9181bd98..a81a9655 100644 --- a/flowspec/models.py +++ b/flowspec/models.py @@ -475,7 +475,7 @@ class Route(models.Model): self.update_status("OUTOFSYNC") def is_synced(self, netconf_device_queried=None): - logger.info('models::is_synced(): self='+str(self)) + logger.info('models::is_synced(): self='+str(self)+" status="+str(self.status)) found = False try: # allows for caching of NETCONF GetConfig query, e.g., during tasks::check_sync @@ -640,14 +640,17 @@ class Route(models.Model): logger.info('models::is_synced(): self='+str(self)+': icmp type fields do not match') except: pass + if found and self.status != "ACTIVE": logger.error('models::is_synced(): rule '+str(self)+' is applied on device but appears in DB as offline') #self.status = "ACTIVE" #self.save() self.update_status("ACTIVE") found = True - if self.status == "ADMININACTIVE" or self.status == "INACTIVE" or self.status == "INACTIVE_TODELETE" or self.status == "PENDING_TODELETE" or self.status == "EXPIRED": - found = True + + logger.info('models::is_synced(): self='+str(self)+ " status="+str(self.status)+" pre found="+str(found)) + if not found and (self.status == "ADMININACTIVE" or self.status == "INACTIVE" or self.status == "INACTIVE_TODELETE" or self.status == "PENDING_TODELETE" or self.status == "EXPIRED"): + found = True logger.info('models::is_synced(): self='+str(self)+ " => returning found="+str(found)) return found diff --git a/flowspec/tasks.py b/flowspec/tasks.py index 69821feb..bca9e4eb 100644 --- a/flowspec/tasks.py +++ b/flowspec/tasks.py @@ -290,15 +290,16 @@ def check_sync(route_name=None, selected_routes=[]): 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': - logger.info('Expiring %s route %s' %(route.status, route.name)) + logger.info('tasks::check_sync(): expiring %s route %s' %(route.status, route.name)) subtask(deactivate_route).delay(str(route.id), reason="EXPIRED") else: if route.status != 'EXPIRED': old_status = route.status + logger.debug('tasks::check_sync(): calling route.check_sync for %s : %s' % (route.name, old_status)) 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)) + logger.info('tasks::check_sync(): status of rule changed during check_sync %s : %s -> %s' % (route.name, old_status, new_status)) announce("[%s] Rule status change after sync check: %s - Result: %s" % ("-", route.name_visible, ""), route.applier, route) -- GitLab