Skip to content

Commit

Permalink
Make configlet application script idempotent for updates. (sonic-net#728
Browse files Browse the repository at this point in the history
)

* Make script idempotent, for updates.
Delete of non-existing table/keys is a no-op, hence can be ignored.

* Name change
  • Loading branch information
renukamanavalan authored Nov 7, 2019
1 parent 4740617 commit 2bce9ce
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions scripts/configlet
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,27 @@ def init():

def db_update(t, k, lst):
init()
db.mod_entry(t, k, lst)
to_upd = False
data = db.get_entry(t, k)
for i in lst.keys():
if not data.has_key(i) or data[i] != lst[i]:
to_upd = True
break

def db_filtered_upd(t, k, lst):
if to_upd:
db.mod_entry(t, k, lst)

def db_delete_fields(t, k, lst):
init()
to_set = False
data = db.get_entry(t, k)
for i in lst.keys():
data.pop(i)
db.set_entry(t, k, data)
if data.has_key(i):
data.pop(i)
to_set = True

if to_set:
db.set_entry(t, k, data)


def db_delete_deep(t, k):
Expand All @@ -119,7 +132,7 @@ def db_delete_deep(t, k):
def db_delete(t, k, lst):
init()
if lst:
db_filtered_upd(t, k, lst)
db_delete_fields(t, k, lst)
else:
db_delete_deep(t, k)

Expand Down

0 comments on commit 2bce9ce

Please sign in to comment.