Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Checkpoint and Rollback for Multi ASIC. #3299

Merged
merged 48 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
be43d9b
Add Checkpoint and Rollback for Multi ASIC.
xincunli-sonic Apr 30, 2024
a322004
Fix scope
xincunli-sonic May 1, 2024
406f3f9
Fix syntax
xincunli-sonic May 1, 2024
029d0d0
Fix pre commit check
xincunli-sonic May 1, 2024
3aec0f9
fix pre commit test
xincunli-sonic May 1, 2024
b296200
Refactor scope parameter comment
xincunli-sonic May 1, 2024
3eabf79
Add Checkpoint and Rollback for Multi ASIC.
xincunli-sonic Apr 30, 2024
9fe2bd4
Fix scope
xincunli-sonic May 1, 2024
5c1e8fa
Fix syntax
xincunli-sonic May 1, 2024
9cdff48
Fix pre commit check
xincunli-sonic May 1, 2024
6cdd6a2
fix pre commit test
xincunli-sonic May 1, 2024
edfa2dd
Refactor scope parameter comment
xincunli-sonic May 1, 2024
bebbdb5
Merge branch 'master' into xincun/multiasic-checkpoint-rollback
xincunli-sonic May 17, 2024
328a9bb
Merge branch 'xincun/multiasic-checkpoint-rollback' of https://github…
xincunli-sonic May 17, 2024
ab8fc14
Refactor replace with single config file.
xincunli-sonic May 17, 2024
c61344d
Fix pre-commit and replace function
xincunli-sonic May 18, 2024
8016675
Fix precommit
xincunli-sonic May 18, 2024
9c47e38
Refactor checkpoint and rollback.
xincunli-sonic May 22, 2024
e257b78
fix format
xincunli-sonic May 23, 2024
1cd4b88
Fix format
xincunli-sonic May 23, 2024
87760a1
Fix UT
xincunli-sonic May 23, 2024
e9a9971
Merge branch 'sonic-net:master' into xincun/multiasic-checkpoint-roll…
xincunli-sonic May 23, 2024
cf2f399
Fix UT.
xincunli-sonic May 24, 2024
57e9d3a
Add UT.
xincunli-sonic May 24, 2024
4716f4d
Fix format.
xincunli-sonic May 24, 2024
1bfb020
Fix UT
xincunli-sonic May 25, 2024
bcdfb8f
Fix UT.
xincunli-sonic May 25, 2024
c8371eb
Refactor replacer and rollbacker
xincunli-sonic May 29, 2024
7fd927e
Merge branch 'xincun/multiasic-checkpoint-rollback' of https://github…
xincunli-sonic May 29, 2024
e66d9af
fix generic_updater format
xincunli-sonic May 29, 2024
326023c
fix format
xincunli-sonic May 29, 2024
49ceca0
Refactor code.
xincunli-sonic May 31, 2024
33d6801
remove unused part.
xincunli-sonic May 31, 2024
ac85032
fix show import
xincunli-sonic May 31, 2024
d0116e1
fix ut.
xincunli-sonic May 31, 2024
26c84cc
fix format
xincunli-sonic May 31, 2024
4465fdc
fix ut.
xincunli-sonic May 31, 2024
906e903
fix ut
xincunli-sonic Jun 3, 2024
698959b
fix ut
xincunli-sonic Jun 3, 2024
5f2c6a6
fix ut.
xincunli-sonic Jun 3, 2024
e469185
fix scope
xincunli-sonic Jun 3, 2024
3e610da
fix ut.
xincunli-sonic Jun 3, 2024
acf663c
improve coverage.
xincunli-sonic Jun 4, 2024
ff036e7
fix replacer
xincunli-sonic Jun 5, 2024
3569037
fix format.
xincunli-sonic Jun 5, 2024
fbbc34e
Remove unused parts
xincunli-sonic Jun 5, 2024
c4d20c6
add get_config_db_as_text ut
xincunli-sonic Jun 6, 2024
05cb10f
Change get_config_json implementation
xincunli-sonic Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ def apply_patch_for_scope(scope_changes, results, config_format, verbose, dry_ru
scope_for_log = scope if scope else HOST_NAMESPACE
try:
# Call apply_patch with the ASIC-specific changes and predefined parameters
GenericUpdater(namespace=scope).apply_patch(jsonpatch.JsonPatch(changes),
GenericUpdater(scope=scope).apply_patch(jsonpatch.JsonPatch(changes),
config_format,
verbose,
dry_run,
Expand Down
32 changes: 14 additions & 18 deletions generic_config_updater/change_applier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

print_to_console = False


def set_verbose(verbose=False):
global print_to_console, logger

Expand All @@ -34,11 +35,12 @@ def log_error(m):
logger.log(logger.LOG_PRIORITY_ERROR, m, print_to_console)


def get_config_db(namespace=multi_asic.DEFAULT_NAMESPACE):
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
def get_config_db(scope=multi_asic.DEFAULT_NAMESPACE):
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=scope)
config_db.connect()
return config_db


def set_config(config_db, tbl, key, data):
config_db.set_entry(tbl, key, data)

Expand All @@ -61,11 +63,9 @@ class DryRunChangeApplier:
def __init__(self, config_wrapper):
self.config_wrapper = config_wrapper


def apply(self, change):
self.config_wrapper.apply_change_to_config_db(change)


def remove_backend_tables_from_config(self, data):
return data

Expand All @@ -74,9 +74,9 @@ class ChangeApplier:

updater_conf = None

def __init__(self, namespace=multi_asic.DEFAULT_NAMESPACE):
self.namespace = namespace
self.config_db = get_config_db(self.namespace)
def __init__(self, scope=multi_asic.DEFAULT_NAMESPACE):
self.scope = scope
self.config_db = get_config_db(self.scope)
self.backend_tables = [
"BUFFER_PG",
"BUFFER_PROFILE",
Expand All @@ -86,7 +86,6 @@ def __init__(self, namespace=multi_asic.DEFAULT_NAMESPACE):
with open(UPDATER_CONF_FILE, "r") as s:
ChangeApplier.updater_conf = json.load(s)


def _invoke_cmd(self, cmd, old_cfg, upd_cfg, keys):
# cmd is in the format as <package/module name>.<method name>
#
Expand All @@ -98,7 +97,6 @@ def _invoke_cmd(self, cmd, old_cfg, upd_cfg, keys):

return method_to_call(old_cfg, upd_cfg, keys)


def _services_validate(self, old_cfg, upd_cfg, keys):
lst_svcs = set()
lst_cmds = set()
Expand All @@ -124,7 +122,6 @@ def _services_validate(self, old_cfg, upd_cfg, keys):
log_debug("service invoked: {}".format(cmd))
return 0


def _upd_data(self, tbl, run_tbl, upd_tbl, upd_keys):
for key in set(run_tbl.keys()).union(set(upd_tbl.keys())):
run_data = run_tbl.get(key, None)
Expand All @@ -135,20 +132,17 @@ def _upd_data(self, tbl, run_tbl, upd_tbl, upd_keys):
upd_keys[tbl][key] = {}
log_debug("Patch affected tbl={} key={}".format(tbl, key))


def _report_mismatch(self, run_data, upd_data):
log_error("run_data vs expected_data: {}".format(
str(jsondiff.diff(run_data, upd_data))[0:40]))


def apply(self, change):
run_data = self._get_running_config()
upd_data = prune_empty_table(change.apply(copy.deepcopy(run_data)))
upd_keys = defaultdict(dict)

for tbl in sorted(set(run_data.keys()).union(set(upd_data.keys()))):
self._upd_data(tbl, run_data.get(tbl, {}),
upd_data.get(tbl, {}), upd_keys)
self._upd_data(tbl, run_data.get(tbl, {}), upd_data.get(tbl, {}), upd_keys)

ret = self._services_validate(run_data, upd_data, upd_keys)
if not ret:
Expand All @@ -168,9 +162,9 @@ def remove_backend_tables_from_config(self, data):

def _get_running_config(self):
_, fname = tempfile.mkstemp(suffix="_changeApplier")
if self.namespace:
cmd = ['sonic-cfggen', '-d', '--print-data', '-n', self.namespace]

if self.scope:
cmd = ['sonic-cfggen', '-d', '--print-data', '-n', self.scope]
else:
cmd = ['sonic-cfggen', '-d', '--print-data']

Expand All @@ -181,7 +175,9 @@ def _get_running_config(self):
return_code = result.returncode
if return_code:
os.remove(fname)
raise GenericConfigUpdaterError(f"Failed to get running config for namespace: {self.namespace}, Return code: {return_code}, Error: {err}")
raise GenericConfigUpdaterError(
f"Failed to get running config for scope: {self.scope}," +
f"Return code: {return_code}, Error: {err}")

run_data = {}
try:
Expand Down
Loading
Loading