Skip to content

Commit f896e63

Browse files
committed
Allow deleting tables before updating
Add table_delete to mod_config in the ConfigDBPipeConnector to allow table cleanup as part of transaction
1 parent 92991f0 commit f896e63

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: src/swsssdk/configdb.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,27 @@ def __mod_entry(self, pipe, table, key, data):
392392
else:
393393
pipe.hmset(_hash, self.typed_to_raw(data))
394394

395-
def mod_config(self, data):
395+
def mod_config(self, data, table_delete=None):
396396
"""Write multiple tables into config db.
397397
Extra entries/fields in the db which are not in the data are kept.
398+
Pass one or more tables in table_delete to delete tables before update.
398399
Args:
399400
data: config data in a dictionary form
400401
{
401402
'TABLE_NAME': { 'row_key': {'column_key': 'value', ...}, ...},
402403
'MULTI_KEY_TABLE_NAME': { ('l1_key', 'l2_key', ...) : {'column_key': 'value', ...}, ...},
403404
...
404405
}
406+
table_delete: Table name(s) that will be deleted first before modify
405407
"""
406408
client = self.get_redis_client(self.db_name)
407409
pipe = client.pipeline()
410+
if table_delete:
411+
if isinstance(table_delete, list):
412+
for t in table_delete:
413+
self.__delete_table(client, pipe, t)
414+
else:
415+
self.__delete_table(client, pipe, table_delete)
408416
for table_name in data:
409417
table_data = data[table_name]
410418
if table_data is None:

0 commit comments

Comments
 (0)