Skip to content

Commit

Permalink
[yang_models]: yang models for device_metadata, device_neighbor, flex… (
Browse files Browse the repository at this point in the history
#4442)

Changes:
1.) yang models for device_metadata, device_neighbor, flex_counters, crm, versions.
2.) Test cases for above yang models.
Signed-off-by: Praveen Chaudhary [email protected]:
  • Loading branch information
Praveen Chaudhary authored Nov 18, 2020
1 parent 6c4092d commit 2fe79c2
Show file tree
Hide file tree
Showing 18 changed files with 1,019 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/sonic-yang-mgmt/sonic_yang_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ def _xlateContainer(self, model, yang, config, table):

## Handle other leaves in container,
leafDict = self._createLeafDict(model)
for vKey in configC.keys():
vKeys = list(configC.keys())
for vKey in vKeys:
#vkey must be a leaf\leaf-list\choice in container
if leafDict.get(vKey):
self.sysLog(syslog.LOG_DEBUG, "xlateContainer vkey {}".format(vKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ def test_xlate_rev_xlate(self, sonic_yang_data):
syc = sonic_yang_data['syc']

jIn = self.readIjsonInput(test_file, 'SAMPLE_CONFIG_DB_JSON')
jIn = json.loads(jIn)
numTables = len(jIn)

syc.loadData(json.loads(jIn))

# TODO: Make sure no extra table is loaded
syc.loadData(jIn)
# check all tables are loaded and no tables is without Yang Models
assert len(syc.jIn) == numTables
assert len(syc.tablesWithOutYang) == 0

syc.getData()

Expand Down
10 changes: 8 additions & 2 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@
packages=find_packages(),
version='1.0',
data_files=[
('yang-models', ['./yang-models/sonic-types.yang',
('yang-models', ['./yang-models/sonic-acl.yang',
'./yang-models/sonic-breakout_cfg.yang',
'./yang-models/sonic-crm.yang',
'./yang-models/sonic-device_metadata.yang',
'./yang-models/sonic-device_neighbor.yang',
'./yang-models/sonic-extension.yang',
'./yang-models/sonic-acl.yang',
'./yang-models/sonic-flex_counter.yang',
'./yang-models/sonic-interface.yang',
'./yang-models/sonic-loopback-interface.yang',
'./yang-models/sonic-port.yang',
'./yang-models/sonic-portchannel.yang',
'./yang-models/sonic-types.yang',
'./yang-models/sonic-versions.yang',
'./yang-models/sonic-vlan.yang',
'./yang-models/sonic_yang_tree']),
],
Expand Down
63 changes: 57 additions & 6 deletions src/sonic-yang-models/tests/yang_model_tests/test_yang_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def initTest(self):
'desc': 'Loopback Ip-prefix port-name must condition failure.',
'eStr': self.defaultYANGFailure['Must']
},
'CRM_BRK_CFG_FLEX_TABLE': {
'desc': 'CRM BREAKOUT CFG FLEX COUNTER TABLE.',
'eStr': self.defaultYANGFailure['None']
},
'INCORRECT_VLAN_NAME': {
'desc': 'INCORRECT VLAN_NAME FIELD IN VLAN TABLE.',
'eStr': self.defaultYANGFailure['Pattern'] + ["Vlan"]
Expand Down Expand Up @@ -168,6 +172,52 @@ def initTest(self):
'PORT_NEG_TEST': {
'desc': 'LOAD PORT TABLE FEC PATTERN FAILURE',
'eStr': self.defaultYANGFailure['Pattern'] + ['rc']
},
'CRM_WITH_WRONG_PERCENTAGE': {
'desc': 'CRM_WITH_WRONG_PERCENTAGE must condition failure.',
'eStr': self.defaultYANGFailure['Must']
},
'CRM_WITH_HIGH_THRESHOLD_ERR': {
'desc': 'CRM_WITH_HIGH_THRESHOLD_ERR must condition failure \
about high threshold being lower than low threshold.',
'eStr': self.defaultYANGFailure['high_threshold should be more \
than low_threshold']
},
'CRM_WITH_CORRECT_USED_VALUE': {
'desc': 'CRM_WITH_CORRECT_USED_VALUE no failure.',
'eStr': self.defaultYANGFailure['None']
},
'FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE': {
'desc': 'FLEX_COUNTER_TABLE_WITH_CORRECT_USED_VALUE no failure.',
'eStr': self.defaultYANGFailure['None']
},
'VERSIONS_WITH_INCORRECT_PATTERN': {
'desc': 'VERSIONS_WITH_INCORRECT_PATTERN pattern failure.',
'eStr': self.defaultYANGFailure['Pattern']
},
'VERSIONS_WITH_INCORRECT_PATTERN2': {
'desc': 'VERSIONS_WITH_INCORRECT_PATTERN pattern failure.',
'eStr': self.defaultYANGFailure['Pattern']
},
'DEVICE_METADATA_DEFAULT_BGP_STATUS': {
'desc': 'DEVICE_METADATA DEFAULT VALUE FOR BGP_STATUS FIELD.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': '/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname',
'key': 'sonic-device_metadata:default_bgp_status',
'value': 'up'
}
},
'DEVICE_METADATA_DEFAULT_PFCWD_STATUS': {
'desc': 'DEVICE_METADATA DEFAULT VALUE FOR PFCWD FIELD.',
'eStr': self.defaultYANGFailure['Verify'],
'verify': {'xpath': '/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname',
'key': 'sonic-device_metadata:default_pfcwd_status',
'value': 'disable'
}
},
'DEVICE_METADATA_TYPE_INCORRECT_PATTERN': {
'desc': 'DEVICE_METADATA_TYPE_INCORRECT_PATTERN pattern failure.',
'eStr': self.defaultYANGFailure['Pattern']
}
}

Expand Down Expand Up @@ -260,20 +310,20 @@ def loadConfigData(self, jInput, verify=None):
# verify the data tree if asked
if verify is not None:
xpath = verify['xpath']
log.debug("Verify xpath: {}".format(xpath))
log.info("Verify xpath: {}".format(xpath))
set = node.find_path(xpath)
for dnode in set.data():
if (xpath == dnode.path()):
log.debug("Verify dnode: {}".format(dnode.path()))
log.info("Verify dnode: {}".format(dnode.path()))
data = dnode.print_mem(ly.LYD_JSON, ly.LYP_WITHSIBLINGS \
| ly.LYP_FORMAT | ly.LYP_WD_ALL)
data = json.loads(data)
log.debug("Verify data: {}".format(data))
log.info("Verify data: {}".format(data))
assert (data[verify['key']] == verify['value'])
s = 'verified'
except Exception as e:
s = str(e)
log.debug(s)
log.info(s)
return s

"""
Expand All @@ -294,7 +344,7 @@ def runExceptionTest(self, test):
log.info(desc + " Passed\n")
return PASS
else:
raise Exception("Unknown Error")
raise Exception("Mismatch {} and {}".format(eStr, s))
except Exception as e:
printExceptionDetails()
log.info(desc + " Failed\n")
Expand Down Expand Up @@ -336,10 +386,10 @@ def runVlanSpecialTest(self, test):
Run all tests from list self.tests
"""
def test_run_tests(self):
ret = 0
try:
self.initTest()
self.loadYangModel(self.yangDir)
ret = 0
for test in self.tests:
test = test.strip()
if test in self.ExceptionTests:
Expand All @@ -350,6 +400,7 @@ def test_run_tests(self):
raise Exception("Unexpected Test")
except Exception as e:
printExceptionDetails()

assert ret == 0
return
# End of Class
Expand Down
Loading

1 comment on commit 2fe79c2

@otikare1990
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add description or know what the different routing mode mean - split, unified, separated. If there is any other documentation for this, it would be great if you could provide the pointer for it.

Please sign in to comment.