@@ -71,7 +71,6 @@ def __init__(self, match_engine=None):
71
71
self .trap_group = ""
72
72
self .trap_id = ""
73
73
self .ns = ""
74
- self .ret_temp = {}
75
74
76
75
def fetch_all_trap_ids (self , ret ):
77
76
traps = []
@@ -108,17 +107,11 @@ def execute(self, params):
108
107
def handle_state_db (self ):
109
108
req = MatchRequest (db = "STATE_DB" , table = "COPP_TRAP_TABLE" , key_pattern = self .copp_trap_cfg_key )
110
109
ret = self .match_engine .fetch (req )
111
- if not ret ["error" ] and len (ret ["keys" ]) > 0 :
112
- self .ret_temp ["STATE_DB" ]["keys" ].append (ret ["keys" ][0 ])
113
- else :
114
- self .ret_temp ["STATE_DB" ]["tables_not_found" ].append ("COPP_TRAP_TABLE" )
110
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ])
115
111
116
112
req = MatchRequest (db = "STATE_DB" , table = "COPP_GROUP_TABLE" , key_pattern = self .trap_group )
117
113
ret = self .match_engine .fetch (req )
118
- if not ret ["error" ] and len (ret ["keys" ]) > 0 :
119
- self .ret_temp ["STATE_DB" ]["keys" ].append (ret ["keys" ][0 ])
120
- else :
121
- self .ret_temp ["STATE_DB" ]["tables_not_found" ].append ("COPP_GROUP_TABLE" )
114
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ])
122
115
123
116
def handle_appl_db (self ):
124
117
req = MatchRequest (db = "APPL_DB" , table = APP_COPP_TABLE_NAME , key_pattern = "*" , field = "trap_ids" ,
@@ -207,17 +200,15 @@ def __get_asic_policer_obj(self, policer_sai_obj):
207
200
return
208
201
req = MatchRequest (db = "ASIC_DB" , table = ASIC_POLICER_OBJ , key_pattern = policer_sai_obj , ns = self .ns )
209
202
ret = self .match_engine .fetch (req )
210
- if not ret ["error" ] and len (ret ["keys" ]) > 0 :
211
- self .ret_temp ["ASIC_DB" ]["keys" ].append (ret ["keys" ][0 ])
203
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ], False )
212
204
213
205
def __get_asic_queue_obj (self , queue_sai_obj ):
214
206
# Not adding tp tables_not_found because of the type of reason specified for policer obj
215
207
if not queue_sai_obj :
216
208
return
217
209
req = MatchRequest (db = "ASIC_DB" , table = ASIC_QUEUE_OBJ , field = "SAI_QUEUE_ATTR_INDEX" , value = queue_sai_obj , ns = self .ns )
218
210
ret = self .match_engine .fetch (req )
219
- if not ret ["error" ] and len (ret ["keys" ]) > 0 :
220
- self .ret_temp ["ASIC_DB" ]["keys" ].append (ret ["keys" ][0 ])
211
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ], False )
221
212
222
213
def __get_asic_hostif_entry_obj (self , sai_trap_key ):
223
214
# Not adding tp tables_not_found because of the type of reason specified for policer obj
@@ -231,9 +222,9 @@ def __get_asic_hostif_entry_obj(self, sai_trap_key):
231
222
req = MatchRequest (db = "ASIC_DB" , table = ASIC_HOSTIF_TABLE_ENTRY , field = "SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID" ,
232
223
value = sai_trap_vid , return_fields = ["SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF" ], ns = self .ns )
233
224
ret = self .match_engine .fetch (req )
225
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ], False )
234
226
if not ret ["error" ] and len (ret ["keys" ]) > 0 :
235
227
sai_hostif_table_entry_key = ret ["keys" ][0 ]
236
- self .ret_temp ["ASIC_DB" ]["keys" ].append (sai_hostif_table_entry_key )
237
228
sai_hostif_vid = ret ["return_values" ][sai_hostif_table_entry_key ]["SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF" ]
238
229
return sai_hostif_vid
239
230
@@ -243,8 +234,7 @@ def __get_asic_hostif_obj(self, sai_hostif_vid):
243
234
return
244
235
req = MatchRequest (db = "ASIC_DB" , table = ASIC_HOSTIF , key_pattern = sai_hostif_vid , ns = self .ns )
245
236
ret = self .match_engine .fetch (req )
246
- if not ret ["error" ] and len (ret ["keys" ]) > 0 :
247
- self .ret_temp ["ASIC_DB" ]["keys" ].append (ret ["keys" ][0 ])
237
+ self .add_to_ret_template (req .table , req .db , ret ["keys" ], ret ["error" ], False )
248
238
249
239
# When the user writes config to CONFIG_DB, that takes precedence over default config
250
240
def handle_user_and_default_config (self ):
0 commit comments