-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more UTs, fixed issue surafced by said UTs
- Loading branch information
1 parent
b13ad3f
commit 5b4f5d1
Showing
4 changed files
with
108 additions
and
6 deletions.
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
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,53 @@ | ||
import os | ||
import sys | ||
import types | ||
from mock import MagicMock, patch | ||
#import psutil | ||
|
||
from sonic_platform_base.sonic_storage.storage_common import StorageCommon | ||
|
||
class DiskIOCounters(): | ||
def __init__(self, perdisk=True, nowrap=True): | ||
|
||
self.read_count = 18038 | ||
self.write_count = 95836 | ||
|
||
class TestStorageCommon: | ||
|
||
@patch('psutil.disk_io_counters', MagicMock(return_value={'sda': DiskIOCounters()})) | ||
def test_get_reads_writes(self): | ||
|
||
common_object = StorageCommon('/dev/sda') | ||
|
||
reads = common_object.get_fs_io_reads() | ||
writes = common_object.get_fs_io_writes() | ||
|
||
assert (reads == 18038) | ||
assert (writes == 95836) | ||
|
||
|
||
def test_init(self): | ||
common_object = StorageCommon('/dev/sda') | ||
|
||
assert common_object.storage_disk == 'sda' | ||
assert common_object.fsstats_reads == 0 | ||
assert common_object.fsstats_writes == 0 | ||
|
||
|
||
|
||
def test_get_reads_writes_bad_disk(self): | ||
common_object = StorageCommon('/dev/glorp') | ||
|
||
with patch('psutil.disk_io_counters', MagicMock()) as mock_psutil_output: | ||
|
||
class DiskIOCounters(): | ||
def __init__(self, perdisk=True, nowrap=True): | ||
pass | ||
|
||
mock_psutil_output.return_value = {'glorp': DiskIOCounters()} | ||
reads = common_object.get_fs_io_reads() | ||
writes = common_object.get_fs_io_writes() | ||
|
||
assert (reads == 0) | ||
assert (writes == 0) | ||
|
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,46 @@ | ||
import sys | ||
from unittest import mock | ||
from pytest import raises | ||
|
||
from sonic_platform_base.sonic_storage.storage_devices import StorageDevices | ||
|
||
log_identifier = "test_storage_devices" | ||
|
||
mocked_basepath = ['loop1', 'mmcblk0', 'loop6', 'mmcblk0boot0', 'loop4', 'loop2', 'loop0', 'loop7', 'mmcblk0boot1', 'sda', 'loop5', 'loop3'] | ||
mocked_devices = { 'mmcblk0' : None, 'sda' : None} | ||
|
||
|
||
class TestStorageDevices: | ||
|
||
@mock.patch('os.listdir', mock.MagicMock(return_value=mocked_basepath)) | ||
def test_get_storage_devices_none(self): | ||
|
||
def mock_factory(self, dummy_key): | ||
return None | ||
|
||
with mock.patch.object(StorageDevices, '_storage_device_object_factory', new=mock_factory): | ||
storage = StorageDevices(log_identifier) | ||
assert storage.devices == mocked_devices | ||
|
||
|
||
@mock.patch('os.listdir', mock.MagicMock(return_value=mocked_basepath)) | ||
@mock.patch('sonic_platform_base.sonic_storage.emmc') | ||
@mock.patch('sonic_platform_base.sonic_storage.ssd') | ||
def test_get_storage_devices_mockobjs(self, mock_emmc, mock_ssd): | ||
|
||
mock_emmc = mock.MagicMock() | ||
mock_ssd = mock.MagicMock() | ||
|
||
def mock_factory(self, dummy_key): | ||
if dummy_key == "mmcblk0": return mock_emmc | ||
else: return mock_ssd | ||
|
||
with mock.patch.object(StorageDevices, '_storage_device_object_factory', new=mock_factory): | ||
storage = StorageDevices(log_identifier) | ||
|
||
assert (list(storage.devices.keys()) == ['mmcblk0', 'sda']) | ||
assert isinstance(storage.devices['mmcblk0'], mock.MagicMock) | ||
assert isinstance(storage.devices['sda'], mock.MagicMock) | ||
assert (storage.devices['mmcblk0'] == mock_emmc) | ||
assert (storage.devices['sda'] == mock_ssd) | ||
|