diff --git a/src/lldp_syncd/daemon.py b/src/lldp_syncd/daemon.py index fde3002..73c9675 100644 --- a/src/lldp_syncd/daemon.py +++ b/src/lldp_syncd/daemon.py @@ -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 diff --git a/tests/test_lldpSyncDaemon.py b/tests/test_lldpSyncDaemon.py index 28897bf..727ace5 100644 --- a/tests/test_lldpSyncDaemon.py +++ b/tests/test_lldpSyncDaemon.py @@ -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!") \ No newline at end of file + 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)