Skip to content

Commit

Permalink
Rename sonic_ssd to sonic_storage matching corresponding sonic-platfo…
Browse files Browse the repository at this point in the history
…rm-common change (sonic-net#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 28db41d.

* 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
  • Loading branch information
assrinivasan authored Jun 3, 2024
1 parent 6447308 commit b518ab4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ssdutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions tests/ssdutil_test.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b518ab4

Please sign in to comment.