Skip to content

Commit

Permalink
Allow deleting tables before updating
Browse files Browse the repository at this point in the history
Add table_delete to mod_config in the ConfigDBPipeConnector to allow table cleanup as part of transaction
  • Loading branch information
ericseifert committed May 26, 2023
1 parent 92991f0 commit f896e63
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,27 @@ def __mod_entry(self, pipe, table, key, data):
else:
pipe.hmset(_hash, self.typed_to_raw(data))

def mod_config(self, data):
def mod_config(self, data, table_delete=None):
"""Write multiple tables into config db.
Extra entries/fields in the db which are not in the data are kept.
Pass one or more tables in table_delete to delete tables before update.
Args:
data: config data in a dictionary form
{
'TABLE_NAME': { 'row_key': {'column_key': 'value', ...}, ...},
'MULTI_KEY_TABLE_NAME': { ('l1_key', 'l2_key', ...) : {'column_key': 'value', ...}, ...},
...
}
table_delete: Table name(s) that will be deleted first before modify
"""
client = self.get_redis_client(self.db_name)
pipe = client.pipeline()
if table_delete:
if isinstance(table_delete, list):
for t in table_delete:
self.__delete_table(client, pipe, t)
else:
self.__delete_table(client, pipe, table_delete)
for table_name in data:
table_data = data[table_name]
if table_data is None:
Expand Down

0 comments on commit f896e63

Please sign in to comment.