-
Notifications
You must be signed in to change notification settings - Fork 661
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
YANG validation for ConfigDB Updates: MIRROR_SESSION use case #2430
Changes from 1 commit
ab72eef
ae0e613
366b582
151ce68
d226e17
914a547
b89db6e
a17fef7
6a0c851
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import jsonpatch | ||
import subprocess | ||
from jsonpointer import JsonPointer | ||
|
||
from sonic_py_common import device_info | ||
|
@@ -12,6 +13,15 @@ def ValidatedConfigDBConnector(config_db_connector): | |
config_db_connector.delete_table = validated_delete_table | ||
return config_db_connector | ||
|
||
def is_table_present_config_db(table): | ||
cmd = "sonic-cfggen -d --print-data" | ||
result = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
text, err = result.communicate() | ||
return_code = result.returncode | ||
if return_code: # non-zero means failure | ||
raise Exception(f"Failed to get running config, Return code: {return_code}, Error: {err}") | ||
return table in text | ||
|
||
def make_path_value_jsonpatch_compatible(table, key, value): | ||
if type(key) == tuple: | ||
path = JsonPointer.from_parts([table, '|'.join(key)]).path | ||
|
@@ -22,6 +32,13 @@ def make_path_value_jsonpatch_compatible(table, key, value): | |
return path, value | ||
|
||
def create_gcu_patch(op, table, key=None, value=None): | ||
gcu_json_input = [] | ||
if op == "add" and not is_table_present_config_db(table): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also addressed this comment in PR #2452 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see it resolved in 2452. |
||
gcu_json = {"op": "{}".format(op), | ||
"path": "/{}".format(table), | ||
"value": {}} | ||
gcu_json_input.append(gcu_json) | ||
|
||
if key: | ||
path, value = make_path_value_jsonpatch_compatible(table, key, value) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this implementation is not efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made implementation more efficient in this PR- #2452
After PR 2452 is merged, I will rebase this MIRROR_SESSION PR to include those changes because this MIRROR_SESSION PR is blocked by YANG issue sonic-net/sonic-buildimage#12397 , and PR 2452 will likely be merged first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2452 is merged. Could you rebase this one?