Skip to content

Commit 7ad4347

Browse files
li-pingmaoPraveen Chaudhary
authored and
Praveen Chaudhary
committed
Address feedback from pull request Azure#3874 upstream github
1 parent 982a618 commit 7ad4347

11 files changed

+180
-311
lines changed

src/sonic-yang-mgmt/sonic_yang.py

+45-45
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ def load_schema_modules_ctx(self, yang_dir=None):
128128
"""
129129
def load_data_file(self, data_file):
130130
try:
131-
node = self.ctx.parse_data_path(data_file, ly.LYD_JSON, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT)
131+
data_node = self.ctx.parse_data_path(data_file, ly.LYD_JSON, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT)
132132
except Exception as e:
133133
print("Failed to load data file: " + str(data_file))
134134
self.fail(e)
135135
else:
136-
self.root = node
136+
self.root = data_node
137137

138138
"""
139139
get module name from xpath
@@ -169,7 +169,7 @@ def load_data_model (self, yang_dir, yang_files, data_files, output=None):
169169

170170
self.load_data_file(data_files[0])
171171

172-
for i in range(2, len(data_files)):
172+
for i in range(1, len(data_files)):
173173
self.merge_data(data_files[i])
174174
except Exception as e:
175175
print("Failed to load data files")
@@ -256,59 +256,59 @@ def validate_data_tree (self):
256256
self.fail(e)
257257

258258
"""
259-
find_parent_node(): find the parent node object
259+
find_parent_data_node(): find the parent node object
260260
input: data_xpath - xpath of the data node
261261
returns: parent node
262262
"""
263-
def find_parent_node (self, data_xpath):
263+
def find_parent_data_node (self, data_xpath):
264264
if (self.root is None):
265265
print("data not loaded")
266266
return None
267267
try:
268-
node = self.find_data_node(data_xpath)
268+
data_node = self.find_data_node(data_xpath)
269269
except Exception as e:
270270
print("Failed to find data node from xpath: " + str(data_xpath))
271271
self.fail(e)
272272
else:
273-
if node is not None:
274-
return node.parent()
273+
if data_node is not None:
274+
return data_node.parent()
275275

276276
return None
277277

278278
"""
279-
get_parent_xpath(): find the parent node xpath
279+
get_parent_data_xpath(): find the parent data node's xpath
280280
input: data_xpath - xpathof the data node
281-
returns: - xpath of parent node
281+
returns: - xpath of parent data node
282282
- Exception if error
283283
"""
284-
def get_parent_xpath (self, data_xpath):
284+
def get_parent_data_xpath (self, data_xpath):
285285
path=""
286286
try:
287-
node = self.find_parent_node(data_xpath)
287+
data_node = self.find_parent_data_node(data_xpath)
288288
except Exception as e:
289289
print("Failed to find parent node from xpath: " + str(data_xpath))
290290
self.fail(e)
291291
else:
292-
if (node is not None):
293-
path = node.path()
292+
if (data_node is not None):
293+
path = data_node.path()
294294
return path
295295

296296
"""
297-
new_node(): create a new data node in the data tree
297+
new_data_node(): create a new data node in the data tree
298298
input:
299299
xpath: xpath of the new node
300300
value: value of the new node
301301
returns: new Data_Node object if success, Exception if falied
302302
"""
303-
def new_node(self, xpath, value):
303+
def new_data_node(self, xpath, value):
304304
val = str(value)
305305
try:
306-
node = self.root.new_path(self.ctx, xpath, val, 0, 0)
306+
data_node = self.root.new_path(self.ctx, xpath, val, 0, 0)
307307
except Exception as e:
308308
print("Failed to add data node for path: " + str(xpath))
309309
self.fail(e)
310310
else:
311-
return node
311+
return data_node
312312

313313
"""
314314
find_data_node(): find the data node from xpath
@@ -325,9 +325,9 @@ def find_data_node(self, data_xpath):
325325
self.fail(e)
326326
else:
327327
if set is not None:
328-
for node in set.data():
329-
if (data_xpath == node.path()):
330-
return node
328+
for data_node in set.data():
329+
if (data_xpath == data_node.path()):
330+
return data_node
331331
return None
332332
"""
333333
find_schema_node(): find the schema node from schema xpath
@@ -339,47 +339,47 @@ def find_data_node(self, data_xpath):
339339
def find_schema_node(self, schema_xpath):
340340
try:
341341
schema_set = self.ctx.find_path(schema_xpath)
342-
for snode in schema_set.schema():
343-
if (schema_xpath == snode.path()):
344-
return snode
342+
for schema_node in schema_set.schema():
343+
if (schema_xpath == schema_node.path()):
344+
return schema_node
345345
except Exception as e:
346346
self.fail(e)
347347
return None
348348
else:
349-
for snode in schema_set.schema():
350-
if schema_xapth == snode.path():
351-
return snode
349+
for schema_node in schema_set.schema():
350+
if schema_xapth == schema_node.path():
351+
return schema_node
352352
return None
353353
"""
354-
find_node_schema_xpath(): find the xpath of the schema node from data xpath
354+
find_data_node_schema_xpath(): find the xpath of the schema node from data xpath
355355
data xpath example:
356356
"/sonic-port:sonic-port/PORT/PORT_LIST[port_name='Ethernet0']/port_name"
357357
input: data_xpath - xpath of the data node
358358
returns: - xpath of the schema node if success
359359
- Exception if error
360360
"""
361-
def find_node_schema_xpath(self, data_xpath):
361+
def find_data_node_schema_xpath(self, data_xpath):
362362
path = ""
363363
try:
364364
set = self.root.find_path(data_xpath)
365365
except Exception as e:
366366
self.fail(e)
367367
else:
368-
for node in set.data():
369-
if data_xpath == node.path():
370-
return node.schema().path()
368+
for data_node in set.data():
369+
if data_xpath == data_node.path():
370+
return data_node.schema().path()
371371
return path
372372

373373
"""
374374
add_node(): add a node to Yang schema or data tree
375375
input: xpath and value of the node to be added
376376
returns: Exception if failed
377377
"""
378-
def add_node(self, xpath, value):
378+
def add_data_node(self, data_xpath, value):
379379
try:
380-
node = self.new_node(xpath, value)
380+
data_node = self.new_data_node(data_xpath, value)
381381
#check if the node added to the data tree
382-
self.find_data_node(xpath)
382+
self.find_data_node(data_xpath)
383383
except Exception as e:
384384
print("add_node(): Failed to add data node for xpath: " + str(data_xpath))
385385
self.fail(e)
@@ -429,20 +429,20 @@ def _delete_node(self, xpath=None, node=None):
429429
return False
430430

431431
"""
432-
find_node_value(): find the value of a node from the schema/data tree
432+
find_data_node_value(): find the value of a node from the data tree
433433
input: data_xpath of the data node
434434
returns: value string of the node
435435
"""
436-
def find_node_value(self, data_xpath):
436+
def find_data_node_value(self, data_xpath):
437437
output = ""
438438
try:
439-
node = self.find_data_node(data_xpath)
439+
data_node = self.find_data_node(data_xpath)
440440
except Exception as e:
441-
print("find_node_value(): Failed to find data node from xpath: {}".format(data_xpath))
441+
print("find_data_node_value(): Failed to find data node from xpath: {}".format(data_xpath))
442442
self.fail(e)
443443
else:
444-
if (node is not None):
445-
subtype = node.subtype()
444+
if (data_node is not None):
445+
subtype = data_node.subtype()
446446
if (subtype is not None):
447447
value = subtype.value_str()
448448
return value
@@ -453,9 +453,9 @@ def find_node_value(self, data_xpath):
453453
input: xpath of the data node
454454
returns: Exception if failed
455455
"""
456-
def set_dnode_value(self, data_xpath, value):
456+
def set_data_node_value(self, data_xpath, value):
457457
try:
458-
node = self.root.new_path(self.ctx, data_xpath, str(value), ly.LYD_ANYDATA_STRING, ly.LYD_PATH_OPT_UPDATE)
458+
data_node = self.root.new_path(self.ctx, data_xpath, str(value), ly.LYD_ANYDATA_STRING, ly.LYD_PATH_OPT_UPDATE)
459459
except Exception as e:
460460
print("set data node value failed for xpath: " + str(data_xpath))
461461
self.fail(e)
@@ -497,8 +497,8 @@ def find_schema_dependencies (self, schema_xpath):
497497
self.fail(e)
498498
return ref_list
499499

500-
snode = ly.Schema_Node_Leaf(schema_node)
501-
backlinks = snode.backlinks()
500+
schema_node = ly.Schema_Node_Leaf(schema_node)
501+
backlinks = schema_node.backlinks()
502502
if backlinks.number() > 0:
503503
for link in backlinks.schema():
504504
print("backlink schema: {}".format(link.path()))

src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-module.yang

-144
This file was deleted.

src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/sonic-acl.yang renamed to src/sonic-yang-mgmt/tests/libyang-python-tests/sample-yang-models/test-sonic-acl.yang

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module sonic-acl {
1+
module test-sonic-acl {
22

33
yang-version 1.1;
44

@@ -13,17 +13,17 @@ module sonic-acl {
1313
prefix inet;
1414
}
1515

16-
import sonic-head {
16+
import test-sonic-head {
1717
prefix head;
1818
revision-date 2019-07-01;
1919
}
2020

21-
import sonic-port {
21+
import test-sonic-port {
2222
prefix port;
2323
revision-date 2019-07-01;
2424
}
2525

26-
import sonic-portchannel {
26+
import test-sonic-portchannel {
2727
prefix lag;
2828
revision-date 2019-07-01;
2929
}

0 commit comments

Comments
 (0)