Skip to content

Commit

Permalink
Handle exception to avoid lldp_syncd crash (#65)
Browse files Browse the repository at this point in the history
* Handle exception smooth to avoid lldp_syncd crash

Signed-off-by: Zhaohui Sun <[email protected]>
  • Loading branch information
ZhaohuiS authored May 23, 2024
1 parent bc63571 commit d5fa793
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def source_update(self):
logger.debug("Invoking lldpcli with: {}".format(cmd_local))

lldp_json = self._scrap_output(cmd)
if lldp_json is None:
return None
lldp_json['lldp_loc_chassis'] = self._scrap_output(cmd_local)

return lldp_json
Expand Down
41 changes: 40 additions & 1 deletion tests/test_lldpSyncDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,43 @@ def test_changed_deleted_interface(self):
else:
jo[k] = db.get_all(db.APPL_DB, k)
if 'LLDP_ENTRY_TABLE:Ethernet104' in jo:
self.fail("After removing Ethernet104, it is still found in APPL_DB!")
self.fail("After removing Ethernet104, it is still found in APPL_DB!")

@mock.patch('subprocess.check_output')
def test_invalid_chassis_name(self, mock_check_output):
# mock the invalid chassis name
mock_check_output.return_value = '''
{
"local-chassis": {
"chassis": {
"chassis_name\1": {
"id": {
"type": "mac",
"value": "aa:bb:cc:dd:ee:ff"
},
"descr": "SONiC Software Version: SONiC.20230531.22",
"capability": [
{
"type": "Bridge",
"enabled": true
},
{
"type": "Router",
"enabled": true
},
{
"type": "Wlan",
"enabled": false
},
{
"type": "Station",
"enabled": false
}
]
}
}
}
}
'''
result = self.daemon.source_update()
self.assertIsNone(result)

0 comments on commit d5fa793

Please sign in to comment.