From 9de2f4a6504167f510bb79cb8432964f45ed7a6c Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Mon, 18 Jul 2022 14:05:41 -0700 Subject: [PATCH 1/2] [decode-syseeprom] Fix use_db in decode-syseeprom --- scripts/decode-syseeprom | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/decode-syseeprom b/scripts/decode-syseeprom index eeb38306b0..3d0b8d1db9 100755 --- a/scripts/decode-syseeprom +++ b/scripts/decode-syseeprom @@ -228,8 +228,6 @@ def main(): (opts, args) = get_cmdline_opts() - use_db = opts.db and support_eeprom_db - # Get platform name platform = device_info.get_platform() @@ -238,6 +236,8 @@ def main(): if any(re.match(p, platform) for p in platforms_without_eeprom_db): support_eeprom_db = False + use_db = opts.db and support_eeprom_db + if opts.mgmtmac: print_mgmt_mac(use_db) elif opts.serial: From 1ccd77471664dcb622d5e4e30fb9d2c7ff0f81a4 Mon Sep 17 00:00:00 2001 From: Boyang Yu Date: Wed, 3 Aug 2022 15:45:32 -0700 Subject: [PATCH 2/2] Add unit test for the fix --- tests/decode_syseeprom_test.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/decode_syseeprom_test.py b/tests/decode_syseeprom_test.py index ae3801d369..50c7667453 100644 --- a/tests/decode_syseeprom_test.py +++ b/tests/decode_syseeprom_test.py @@ -192,3 +192,12 @@ def test_print_model(self, capsys): decode_syseeprom.print_model(True) captured = capsys.readouterr() assert captured.out == 'S6100-ON\n' + + @mock.patch('os.geteuid', lambda: 0) + @mock.patch('sonic_py_common.device_info.get_platform', lambda: 'arista') + @mock.patch('decode-syseeprom.read_and_print_eeprom') + @mock.patch('decode-syseeprom.read_eeprom_from_db') + def test_support_platforms_not_db_based(self, mockDbBased, mockNotDbBased): + decode_syseeprom.main() + assert mockNotDbBased.called + assert not mockDbBased.called