Skip to content

Commit

Permalink
fix validated configdb connector
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelmsft committed Sep 23, 2022
1 parent 1777e61 commit 7084ccb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions config/validated_config_db_connector.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import jsonpatch
from jsonpointer import JsonPointer
from jsonpatch import JsonPatchConflict

from sonic_py_common import device_info
from generic_config_updater.generic_updater import GenericUpdater, ConfigFormat
from generic_config_updater.gu_common import EmptyTableError
from generic_config_updater.gu_common import EmptyTableError, genericUpdaterLogging
from swsscommon.swsscommon import ConfigDBConnector

def ValidatedConfigDBConnector(config_db_connector):
Expand All @@ -23,7 +24,10 @@ def make_path_value_jsonpatch_compatible(table, key, value):
return path, value

def create_gcu_patch(op, table, key=None, value=None):
path, value = make_path_value_jsonpatch_compatible(table, key, value)
if key:
path, value = make_path_value_jsonpatch_compatible(table, key, value)
else:
path = "/{}".format(table)

gcu_json_input = []
gcu_json = {"op": "{}".format(op),
Expand All @@ -39,7 +43,11 @@ def validated_delete_table(table):
gcu_patch = create_gcu_patch("remove", table)
format = ConfigFormat.CONFIGDB.name
config_format = ConfigFormat[format.upper()]
GenericUpdater().apply_patch(patch=gcu_patch, config_format=config_format, verbose=False, dry_run=False, ignore_non_yang_tables=False, ignore_paths=None)
try:
GenericUpdater().apply_patch(patch=gcu_patch, config_format=config_format, verbose=False, dry_run=False, ignore_non_yang_tables=False, ignore_paths=None)
except ValueError as e:
logger = genericUpdaterLogging.get_logger(title="Patch Applier", print_all_to_console=True)
logger.log_notice("Unable to remove entry, as doing so will result in invalid config. Error: {}".format(e))

def validated_set_entry(table, key, value):
if value is not None:
Expand Down

0 comments on commit 7084ccb

Please sign in to comment.