forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 3
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 following APIs and test cases: #44
Merged
zhenggen-xu
merged 2 commits into
zhenggen-xu:sonic-cfg-mgmt
from
li-pingmao:sonic-cfg-new
Feb 13, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -540,3 +540,122 @@ def find_data_dependencies (self, data_xpath): | |
self.fail(e) | ||
|
||
return ref_list | ||
|
||
""" | ||
get_module_prefix: get the prefix of a Yang module | ||
input: name of the Yang module | ||
output: prefix of the Yang module | ||
""" | ||
def get_module_prefix(self, module_name): | ||
prefix = "" | ||
try: | ||
module = self.get_module(module_name) | ||
except Exception as e: | ||
self.fail(e) | ||
return prefix | ||
else: | ||
return module.prefix() | ||
|
||
""" | ||
str_to_type: map string to type of node | ||
input: string | ||
output: type | ||
""" | ||
def str_to_type (self, type_str): | ||
mapped_type = { | ||
"LY_TYPE_DER":ly.LY_TYPE_DER, | ||
"LY_TYPE_BINARY":ly.LY_TYPE_BINARY, | ||
"LY_TYPE_BITS":ly.LY_TYPE_BITS, | ||
"LY_TYPE_BOOL":ly.LY_TYPE_BOOL, | ||
"LY_TYPE_DEC64":ly.LY_TYPE_DEC64, | ||
"LY_TYPE_EMPTY":ly.LY_TYPE_EMPTY, | ||
"LY_TYPE_ENUM":ly.LY_TYPE_ENUM, | ||
"LY_TYPE_IDENT":ly.LY_TYPE_IDENT, | ||
"LY_TYPE_INST":ly.LY_TYPE_INST, | ||
"LY_TYPE_LEAFREF":ly.LY_TYPE_LEAFREF, | ||
"LY_TYPE_STRING":ly.LY_TYPE_STRING, | ||
"LY_TYPE_UNION":ly.LY_TYPE_UNION, | ||
"LY_TYPE_INT8":ly.LY_TYPE_INT8, | ||
"LY_TYPE_UINT8":ly.LY_TYPE_UINT8, | ||
"LY_TYPE_INT16":ly.LY_TYPE_INT16, | ||
"LY_TYPE_UINT16":ly.LY_TYPE_UINT16, | ||
"LY_TYPE_INT32":ly.LY_TYPE_INT32, | ||
"LY_TYPE_UINT32":ly.LY_TYPE_UINT32, | ||
"LY_TYPE_INT64":ly.LY_TYPE_INT64, | ||
"LY_TYPE_UINT64":ly.LY_TYPE_UINT64, | ||
"LY_TYPE_UNKNOWN":ly.LY_TYPE_UNKNOWN | ||
} | ||
|
||
if type_str not in mapped_type: | ||
return ly.LY_TYPE_UNKNOWN | ||
|
||
return mapped_type[type_str] | ||
|
||
def get_data_type (self, schema_xpath): | ||
try: | ||
schema_node = self.find_schema_node(schema_xpath) | ||
except Exception as e: | ||
print("get_data_type(): Failed to find schema node from xpath: {}".format(schema_xpath)) | ||
self.fail(e) | ||
return None | ||
|
||
if (schema_node is not None): | ||
return schema_node.subtype().type().base() | ||
|
||
return ly.LY_TYPE_UNKNOWN | ||
|
||
""" | ||
get_leafref_type: find the type of node that leafref references to | ||
input: data_xpath - xpath of a data node | ||
output: type of the node this leafref references to | ||
""" | ||
def get_leafref_type (self, data_xpath): | ||
li-pingmao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data_node = self.find_data_node(data_xpath) | ||
if (data_node is not None): | ||
subtype = data_node.subtype() | ||
if (subtype is not None): | ||
if data_node.schema().subtype().type().base() != ly.LY_TYPE_LEAFREF: | ||
print("get_leafref_type() node type for data xpath: {} is not LEAFREF".format(data_xpath)) | ||
return ly.LY_TYPE_UNKNOWN | ||
else: | ||
return subtype.value_type() | ||
|
||
return ly.LY_TYPE_UNKNOWN | ||
|
||
""" | ||
get_leafref_path(): find the leafref path | ||
input: schema_xpath - xpath of a schema node | ||
output: path value of the leafref node | ||
""" | ||
def get_leafref_path (self, schema_xpath): | ||
schema_node = self.find_schema_node(schema_xpath) | ||
if (schema_node is not None): | ||
subtype = schema_node.subtype() | ||
if (subtype is not None): | ||
if subtype.type().base() != ly.LY_TYPE_LEAFREF: | ||
return None | ||
else: | ||
return subtype.type().info().lref().path() | ||
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. This gives value of leafref, right? |
||
|
||
return None | ||
|
||
""" | ||
get_leafref_type_schema: find the type of node that leafref references to | ||
input: schema_xpath - xpath of a schema node | ||
output: type of the node this leafref references to | ||
""" | ||
def get_leafref_type_schema (self, schema_xpath): | ||
schema_node = self.find_schema_node(schema_xpath) | ||
if (schema_node is not None): | ||
subtype = schema_node.subtype() | ||
if (subtype is not None): | ||
if subtype.type().base() != ly.LY_TYPE_LEAFREF: | ||
return None | ||
else: | ||
leafref_path = subtype.type().info().lref().path() | ||
target = subtype.type().info().lref().target() | ||
target_path = target.path() | ||
target_type = self.get_data_type(target_path) | ||
return target_type | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,5 +99,43 @@ | |
"parent":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='10.1.1.64/26']"}, | ||
{"xpath":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']/speed", | ||
"parent":"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet9']"} | ||
] | ||
], | ||
"prefix":[ | ||
{"module_name":"sonic-head", "module_prefix":"sonic-head"}, | ||
{"module_name":"sonic-port", "module_prefix":"port"}, | ||
{"module_name":"sonic-acl", "module_prefix":"acl"}, | ||
{"module_name":"sonic-interface", "module_prefix":"intf"}, | ||
{"module_name":"sonic-portchannel", "module_prefix":"lag"}, | ||
{"module_name":"sonic-vlan", "module_prefix":"vlan"} | ||
], | ||
"data_type":[ | ||
{"xpath":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name", "data_type":"LY_TYPE_STRING"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", "data_type":"LY_TYPE_LEAFREF"} | ||
], | ||
"leafref_type":[ | ||
{"xpath":"/sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='111'][ip-prefix='2000:f500:45:6709::/64']/vlanid", "data_type":"LY_TYPE_UINT16"}, | ||
{"xpath":"/sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='2000:f500:40:a749::/126']/interface", "data_type":"LY_TYPE_STRING"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/port", "data_type":"LY_TYPE_STRING"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='111'][port='Ethernet0']/vlanid", "data_type":"LY_TYPE_UINT16"} | ||
], | ||
"leafref_type_schema":[ | ||
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. This is really useful, good. |
||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", | ||
"data_type":"LY_TYPE_UINT16"}, | ||
{"xpath":"/sonic-interface:sonic-interface/sonic-interface:INTERFACE/sonic-interface:INTERFACE_LIST/sonic-interface:interface", | ||
"data_type":"LY_TYPE_STRING"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:port", | ||
"data_type":"LY_TYPE_STRING"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:vlanid", | ||
"data_type":"LY_TYPE_UINT16"} | ||
], | ||
"leafref_path":[ | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_INTERFACE/sonic-vlan:VLAN_INTERFACE_LIST/sonic-vlan:vlanid", | ||
"leafref_path":"../../../VLAN/VLAN_LIST/vlanid"}, | ||
{"xpath":"/sonic-interface:sonic-interface/sonic-interface:INTERFACE/sonic-interface:INTERFACE_LIST/sonic-interface:interface", | ||
"leafref_path":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:port", | ||
"leafref_path":"/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name"}, | ||
{"xpath":"/sonic-vlan:sonic-vlan/sonic-vlan:VLAN_MEMBER/sonic-vlan:VLAN_MEMBER_LIST/sonic-vlan:vlanid", | ||
"leafref_path":"../../../VLAN/VLAN_LIST/vlanid"} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hi Ping
Actually, This prefix is not the one which is used in leafref. This is the prefix defined for each module, where as we need the prefix which is used in import statement. Import statement can use a name which is different then module prefix.
For example in sonic-acl, we can have port leafref.
Here port prefix comes from import statement:
Whereas, this API will return below prefix: