-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix key missing exception when invalied transiver info in STATE_DB (#289
) Fix PhysicalSensorTableMIBUpdater crash when 'type' attribute missing. #### Work item tracking Microsoft ADO (number only): 24869277 **- What I did** Fix PhysicalSensorTableMIBUpdater crash when 'type' attribute missing. **- How I did it** Check 'type' attribute, if missing write error log in PhysicalSensorTableMIBUpdater. **- How to verify it** Manually test. Pass all UT **- Description for the changelog** Fix PhysicalSensorTableMIBUpdater crash when 'type' attribute missing.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
from unittest import TestCase | ||
|
||
if sys.version_info.major == 3: | ||
from unittest import mock | ||
else: | ||
import mock | ||
|
||
modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
sys.path.insert(0, os.path.join(modules_path, 'src')) | ||
|
||
from sonic_ax_impl.mibs.ietf.rfc3433 import PhysicalSensorTableMIBUpdater | ||
|
||
class TestPhysicalSensorTableMIBUpdater(TestCase): | ||
|
||
@mock.patch('sonic_ax_impl.mibs.Namespace.dbs_get_all', mock.MagicMock(return_value=({"hardwarerev": "1.0"}))) | ||
def test_PhysicalSensorTableMIBUpdater_transceiver_info_key_missing(self): | ||
updater = PhysicalSensorTableMIBUpdater() | ||
updater.transceiver_dom.append("TRANSCEIVER_INFO|Ethernet0") | ||
|
||
with mock.patch('sonic_ax_impl.mibs.logger.warn') as mocked_warn: | ||
updater.update_data() | ||
|
||
# check warning | ||
mocked_warn.assert_called() | ||
|
||
self.assertTrue(len(updater.sub_ids) == 0) |