@@ -812,3 +812,46 @@ def validate_listeners_state(self, context, listeners, host=None):
812812 e .message )
813813 listener_status [listener_id ] = 'Unknown'
814814 return listener_status
815+
816+ # validate a list of l7policys id - assure they are not deleted
817+ @log_helpers .log_method_call
818+ def validate_l7policys_state_by_listener (self , context , listeners ):
819+ """Performs a validation against l7policies with a list of listeners
820+
821+ This method will attempt to check the Neutron DB for a list of
822+ l7policies that reference the given list of listener_id's.
823+
824+ This will return a dict of:
825+ {listener_id_0: bool,
826+ ...
827+ }
828+ The bool will indicate that true: there are l7policies here, false:
829+ there are none on this listener.
830+ """
831+ has_l7policy = {}
832+ try :
833+ # NOTE: neutron_lbaas has a deprecated code filter for queries
834+ # that appears to silence filter queries for 'listener_id'
835+ l7policy_db = self .driver .plugin .db .get_l7policies (context )
836+ except Exception as error :
837+ LOG .exception ("Exception: plugin.db.get_l7policies({}): "
838+ "({})" .format (listeners , error ))
839+ return {}
840+ LOG .debug ("({}) = get_l7policies({})" .format (l7policy_db , context ))
841+ for listener_id in listeners :
842+ # Given filter limitations, double-loop iterator results
843+ result = False
844+ if l7policy_db :
845+ if isinstance (l7policy_db , list ):
846+ for l7policy in l7policy_db :
847+ if l7policy .listener_id == listener_id :
848+ result = True
849+ break
850+ else :
851+ if l7policy_db .listener_id == listener_id :
852+ result = True
853+ else :
854+ result = False
855+ has_l7policy [listener_id ] = result
856+ LOG .debug ("has_l7policy: ({})" .format (has_l7policy ))
857+ return has_l7policy
0 commit comments