From b518ab46aede4313928f037b5169facb06edf980 Mon Sep 17 00:00:00 2001 From: Ashwin Srinivasan <93744978+assrinivasan@users.noreply.github.com> Date: Mon, 3 Jun 2024 07:23:17 -0700 Subject: [PATCH] Rename sonic_ssd to sonic_storage matching corresponding sonic-platform-common change (#3334) * Renamed sonic_ssd to sonic_storage matching corresponding sonic-platform-common change * Added ssdutil UT * Flake8 test recommendations fixed * Workaround for circular dependency * Made ssdutil UT backwards compatible * Flake8 test fixes * More flake8 fixes * Test failure fix * Filled out init files in mocked libs to prevent unintentional module hiding * Revert "Filled out init files in mocked libs to prevent unintentional module hiding" This reverts commit 28db41d3bbaaff3d48540f3848d941ce4cec5889. * Forced mock of sonic_storage * Removed unused files and code * Dialed back the aggressive mocking of argparse module * Fixed flake8 test issues * Cleaned up ssdutil code and UT --- ssdutil/main.py | 2 +- tests/ssdutil_test.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/ssdutil_test.py diff --git a/ssdutil/main.py b/ssdutil/main.py index 62f43037e7..7b6f2c1ca1 100755 --- a/ssdutil/main.py +++ b/ssdutil/main.py @@ -39,7 +39,7 @@ def import_ssd_api(diskdev): except ImportError as e: log.log_warning("Platform specific SsdUtil module not found. Falling down to the generic implementation") try: - from sonic_platform_base.sonic_ssd.ssd_generic import SsdUtil + from sonic_platform_base.sonic_storage.ssd import SsdUtil except ImportError as e: log.log_error("Failed to import default SsdUtil. Error: {}".format(str(e)), True) raise e diff --git a/tests/ssdutil_test.py b/tests/ssdutil_test.py new file mode 100644 index 0000000000..bd57b0cbe7 --- /dev/null +++ b/tests/ssdutil_test.py @@ -0,0 +1,42 @@ +import sys +import argparse +from unittest.mock import patch, MagicMock +import sonic_platform_base # noqa: F401 + +sys.modules['sonic_platform'] = MagicMock() +sys.modules['sonic_platform_base.sonic_ssd.ssd_generic'] = MagicMock() + +import ssdutil.main as ssdutil # noqa: E402 + + +class Ssd(): + + def get_model(self): + return 'SkyNet' + + def get_firmware(self): + return 'ABC' + + def get_serial(self): + return 'T1000' + + def get_health(self): + return 5 + + def get_temperature(self): + return 3000 + + def get_vendor_output(self): + return 'SONiC Test' + + +class TestSsdutil: + + @patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', MagicMock(return_value=("test_path", ""))) # noqa: E501 + @patch('os.geteuid', MagicMock(return_value=0)) + def test_sonic_storage_path(self): + + with patch('argparse.ArgumentParser.parse_args', MagicMock()) as mock_args: # noqa: E501 + sys.modules['sonic_platform_base.sonic_storage.ssd'] = MagicMock(return_value=Ssd()) # noqa: E501 + mock_args.return_value = argparse.Namespace(device='/dev/sda', verbose=True, vendor=True) # noqa: E501 + ssdutil.ssdutil()