-
Notifications
You must be signed in to change notification settings - Fork 664
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
[config][generic-update] Implementing patch sorting #1599
Conversation
This pull request introduces 10 alerts when merging ba2b1d6bf6a1ddf011327887a697d89b778e1dea into 9a88cb6 - view on LGTM.com new alerts:
|
This pull request introduces 10 alerts when merging 97bc24c4c75dc1b37ecf7bd9d79337c71aba7c08 into ad801bf - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging d61839670813af4455476e788c10fa70280cca82 into ad801bf - view on LGTM.com new alerts:
|
2cad759
to
c20679f
Compare
from enum import Enum | ||
from .gu_common import OperationWrapper, OperationType, GenericConfigUpdaterError, JsonChange, PathAddressing | ||
|
||
# from gu_common import OperationWrapper, OperationType, GenericConfigUpdaterError, JsonChange, PathAddressing |
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.
Remove unused code or comments. #Closed
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.
updated
def __hash__(self): | ||
cc = json.dumps(self.current_config, sort_keys=True) | ||
tc = json.dumps(self.target_config, sort_keys=True) | ||
return hash(cc) ^ hash(tc) |
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.
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.
good idea. updated
import generic_config_updater.gu_common as gu_common | ||
|
||
# from gutest_helpers import create_side_effect_dict, Files | ||
# import sys | ||
# sys.path.insert(0,'../../generic_config_updater') | ||
# import gu_common |
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.
remove unused code. #Closed
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.
updated
generic_config_updater/gu_common.py
Outdated
tokens = path.split(PathAddressing.PATH_SEPARATOR)[1:] | ||
|
||
# Because the characters '~' (%x7E) and '/' (%x2F) have special | ||
# meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/' |
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.
# meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
Did you try https://pypi.org/project/jsonpointer/ ? #Closed
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.
still looking into this
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.
updated
generic_config_updater/gu_common.py
Outdated
|
||
def _is_leaf_node(self, node): | ||
schema = node.schema() | ||
return ly.LYS_LEAF == schema.nodetype() # or ly.LYS_LEAFLIST == schema.nodetype() |
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.
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.
updated
generic_config_updater/gu_common.py
Outdated
return set(ref_paths) | ||
|
||
def _get_inner_leaf_xpaths(self, xpath, sy): | ||
if xpath=="/": # Point to Root element which contains all xpaths |
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.
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.
updated
generic_config_updater/gu_common.py
Outdated
return ly.LYS_LEAF == schema.nodetype() # or ly.LYS_LEAFLIST == schema.nodetype() | ||
|
||
# TODO: YANG SONiC lib has this function but with a bug in handling null backlinks. | ||
# It is OK to have null backlinks if there is no backlinks. |
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.
# It is OK to have null backlinks if there is no backlinks.
Could you create a Github issue or submit a PR if you already know how to fix? #Closed
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.
PR submitted: sonic-net/sonic-buildimage#7939
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.
NOTE: unit-tests in the current PR (patch-sorting) will fail until the PR submitted above is completed
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.
created PR on forked repo: sonic-net/sonic-buildimage#8187
generic_config_updater/gu_common.py
Outdated
node = sy.root | ||
try: | ||
data_node = sy._find_data_node(data_xpath) | ||
except Exception as e: |
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.
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.
code removed locally
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.
code removed
generic_config_updater/gu_common.py
Outdated
casted = data_set.subtype() | ||
if value == casted.value_str(): | ||
ref_list.append(data_set.path()) | ||
except Exception as e: |
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.
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.
code removed locally
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.
code removed
generic_config_updater/gu_common.py
Outdated
# src: https://tools.ietf.org/html/rfc6901 | ||
mod_tokens = [] | ||
for token in tokens: | ||
mod_token = str(token) |
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.
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.
good catch, updated locally
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.
updated
return [token] | ||
list_config = config[token] | ||
value=list_config[int(path_tokens[token_index+1])] | ||
return [f"{token}[.='{value}']"] |
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.
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.
To get a leaf-list instance with the value 'val'
/module-name:container/leaf-list[.='val']
Source: Check examples in https://netopeer.liberouter.org/doc/libyang/master/html/howto_x_path.html
Added a comment to explain this '.' locally.
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.
updated
generic_config_updater/gu_common.py
Outdated
clist = model.get('list') | ||
# Container contains a single list, just return it | ||
# TODO: check if matching also by name is necessary | ||
if isinstance(clist, dict): # and clist['@name'] == token+"_LIST": |
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.
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.
removed
generic_config_updater/gu_common.py
Outdated
if len(xpath_tokens)-1 == token_index: | ||
return path_tokens | ||
|
||
nxt_token = xpath_tokens[token_index+1] |
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.
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.
updated
""" | ||
def __init__(self, diff, op_type, current_config_tokens, target_config_tokens=None): | ||
operation = JsonMove._to_jsonpatch_operation(diff, op_type, current_config_tokens, target_config_tokens) | ||
self.patch=jsonpatch.JsonPatch([operation]) |
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.
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.
added
return False | ||
|
||
def __hash__(self): | ||
return hash(self.op_type) ^ hash(self.path) ^ hash(json.dumps(self.value)) |
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.
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.
updated
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.
As comments
d3d04d2
to
c554f6d
Compare
@ghooo , please note since this pr is causing unit testing failure, it has been reverted. Please check the error here. https://dev.azure.com/mssonic/build/_build/results?buildId=29578&view=logs&j=cef3d8a9-152e-5193-620b-567dc18af272&t=359769c4-8b5e-5976-a793-85da132e0a6f&s=ff05ad62-bb9a-53b6-ce9f-72f329a63e7c please check attempt #1 |
…onic-net#1599)"" This reverts commit e6122e9.
) #### What I did Implemented [JSON Patch Ordering using YANG Models Design Doc](https://github.com/Azure/SONiC/blob/master/doc/config-generic-update-rollback/Json_Patch_Ordering_using_YANG_Models_Design.md) #### How to verify it Unit-Tests **NOTE: The code in this PR was [reverted](github.com/Azure/sonic-utilities/commit/0a145e8027380e8d4decb36bdfc647062c722612) before because of some [build issues](#1761). Build issues have been fixed [here](sonic-net/sonic-buildimage#8632). To check the original PR comments please go [here](#1599
…794) #### What I did Implemented [JSON Patch Ordering using YANG Models Design Doc](https://github.com/Azure/SONiC/blob/master/doc/config-generic-update-rollback/Json_Patch_Ordering_using_YANG_Models_Design.md) #### How to verify it Unit-Tests **NOTE: The code in this PR was [reverted](github.com/Azure/sonic-utilities/commit/0a145e8027380e8d4decb36bdfc647062c722612) before because of some [build issues](sonic-net/sonic-utilities#1761). Build issues have been fixed [here](sonic-net/sonic-buildimage#8632). To check the original PR comments please go [here](sonic-net/sonic-utilities#1599
What I did
Implemented JSON Patch Ordering using YANG Models Design Doc
How I did it
How to verify it
Unit-Tests
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)