@@ -30,7 +30,7 @@ except KeyError:
30
30
31
31
# CONFIG_DB Tables
32
32
DEBUG_COUNTER_CONFIG_TABLE = 'DEBUG_COUNTER'
33
- DROP_REASON_TABLE_PREFIX = 'DEBUG_COUNTER_DROP_REASON'
33
+ DROP_REASON_CONFIG_TABLE = 'DEBUG_COUNTER_DROP_REASON'
34
34
35
35
# STATE_DB Tables
36
36
DEBUG_COUNTER_CAPABILITY_TABLE = 'DEBUG_COUNTER_CAPABILITIES'
@@ -136,10 +136,7 @@ class DropConfig(object):
136
136
raise InvalidArgumentError ('One or more provided drop reason not supported on this device' )
137
137
138
138
for reason in reasons :
139
- self .config_db .set_entry (self .config_db .serialize_key (
140
- (DROP_REASON_TABLE_PREFIX , counter_name )),
141
- reason ,
142
- {})
139
+ self .config_db .set_entry (DROP_REASON_CONFIG_TABLE , (counter_name , reason ), {})
143
140
144
141
drop_counter_entry = {'type' : counter_type }
145
142
@@ -168,8 +165,12 @@ class DropConfig(object):
168
165
self .config_db .set_entry (DEBUG_COUNTER_CONFIG_TABLE ,
169
166
counter_name ,
170
167
None )
171
- self .config_db .delete_table (self .config_db .serialize_key (
172
- (DROP_REASON_TABLE_PREFIX , counter_name )))
168
+
169
+ # We can't use `delete_table` here because table names are normalized to uppercase.
170
+ # Counter names can be lowercase (e.g. "test_counter|ACL_ANY"), so we have to go
171
+ # through and treat each drop reason as an entry to get the correct behavior.
172
+ for reason in self .get_counter_drop_reasons (counter_name ):
173
+ self .config_db .set_entry (DROP_REASON_CONFIG_TABLE , reason , None )
173
174
174
175
def add_reasons (self , counter_name , reasons ):
175
176
"""
@@ -192,10 +193,7 @@ class DropConfig(object):
192
193
raise InvalidArgumentError ('One or more provided drop reason not supported on this device' )
193
194
194
195
for reason in reasons :
195
- self .config_db .set_entry (self .config_db .serialize_key (
196
- (DROP_REASON_TABLE_PREFIX , counter_name )),
197
- reason ,
198
- {})
196
+ self .config_db .set_entry (DROP_REASON_CONFIG_TABLE , (counter_name , reason ), {})
199
197
200
198
def remove_reasons (self , counter_name , reasons ):
201
199
"""
@@ -212,10 +210,7 @@ class DropConfig(object):
212
210
raise InvalidArgumentError ('Counter \' {}\' not found' .format (counter_name ))
213
211
214
212
for reason in reasons :
215
- self .config_db .set_entry (self .config_db .serialize_key (
216
- (DROP_REASON_TABLE_PREFIX , counter_name )),
217
- reason ,
218
- None )
213
+ self .config_db .set_entry (DROP_REASON_CONFIG_TABLE , (counter_name , reason ), None )
219
214
220
215
def get_config (self , group ):
221
216
"""
@@ -236,7 +231,7 @@ class DropConfig(object):
236
231
}
237
232
238
233
# Get the drop reasons for this counter
239
- drop_reason_keys = sorted (self .config_db . get_keys ( self . config_db . serialize_key (( DROP_REASON_TABLE_PREFIX , counter_name )) ), key = lambda x : x [1 ])
234
+ drop_reason_keys = sorted (self .get_counter_drop_reasons ( counter_name ), key = lambda x : x [1 ])
240
235
241
236
# Fill in the first drop reason
242
237
num_reasons = len (drop_reason_keys )
@@ -308,6 +303,11 @@ class DropConfig(object):
308
303
309
304
return deserialize_reason_list (cap_query .get ('reasons' , '' ))
310
305
306
+ def get_counter_drop_reasons (self , counter_name ):
307
+ # get_keys won't filter on counter_name for us because the counter name is case sensitive and
308
+ # get_keys will normalize the table name to uppercase.
309
+ return [key for key in self .config_db .get_keys (DROP_REASON_CONFIG_TABLE ) if key [0 ] == counter_name ]
310
+
311
311
312
312
def deserialize_reason_list (list_str ):
313
313
if list_str is None :
0 commit comments