Skip to content

Commit

Permalink
Added UTs, increased coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
assrinivasan committed May 22, 2024
1 parent c72d3c0 commit 09f3c67
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 239 deletions.
15 changes: 0 additions & 15 deletions sonic-stormond/tests/mock_platform.py

This file was deleted.

63 changes: 63 additions & 0 deletions sonic-stormond/tests/mock_swsscommon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'''
Mock implementation of swsscommon package for unit testing
'''

from swsssdk import ConfigDBConnector, SonicDBConfig, SonicV2Connector

STATE_DB = ''


class Table:
def __init__(self, db, table_name):
self.table_name = table_name
self.mock_dict = {}
self.mock_keys = ['sda']

def _del(self, key):
del self.mock_dict[key]
pass

def set(self, key, fvs):
self.mock_dict[key] = fvs.fv_dict
pass

def get(self, key):
if key in self.mock_dict:
return self.mock_dict[key]
return None

def get_size(self):
return (len(self.mock_dict))

def getKeys(self):
return self.mock_keys

def hgetall(self):
return self.mock_dict


class FieldValuePairs:
fv_dict = {}

def __init__(self, tuple_list):
if isinstance(tuple_list, list) and isinstance(tuple_list[0], tuple):
self.fv_dict = dict(tuple_list)

def __setitem__(self, key, kv_tuple):
self.fv_dict[kv_tuple[0]] = kv_tuple[1]

def __getitem__(self, key):
return self.fv_dict[key]

def __eq__(self, other):
if not isinstance(other, FieldValuePairs):
# don't attempt to compare against unrelated types
return NotImplemented

return self.fv_dict == other.fv_dict

def __repr__(self):
return repr(self.fv_dict)

def __str__(self):
return repr(self.fv_dict)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Mock implementation of sonic_platform package for unit testing
"""

from . import ssd
from . import pcie

13 changes: 13 additions & 0 deletions sonic-stormond/tests/mocked_libs/sonic_platform/pcie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Mock implementation of sonic_platform package for unit testing
"""

from sonic_platform_base.pcie_base import PcieBase


class Pcie(PcieBase):
def __init__(self):
self.platform_pcieutil = "/tmp/Pcie"

def __str__(self):
return self.platform_pcieutil
13 changes: 0 additions & 13 deletions sonic-stormond/tests/mocked_libs/sonic_platform/ssd.py

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
#
# storage_base.py
#
# Abstract base class for implementing platform-specific
# Storage information gathering functionality for SONiC
#

try:
import abc
except ImportError as e:
raise ImportError(str(e) + " - required module not found")

#
# storage_base.py
#
# Base class for implementing common Storage Device health features
# Base class for implementing common SSD health features
#


Expand All @@ -30,7 +18,6 @@ def __init__(self, diskdev):
"""
pass

@abc.abstractmethod
def get_health(self):
"""
Retrieves current disk health in percentages
Expand All @@ -39,9 +26,8 @@ def get_health(self):
A float number of current ssd health
e.g. 83.5
"""
return 91.6
raise NotImplementedError

@abc.abstractmethod
def get_temperature(self):
"""
Retrieves current disk temperature in Celsius
Expand All @@ -50,73 +36,67 @@ def get_temperature(self):
A float number of current temperature in Celsius
e.g. 40.1
"""
return 32.3
raise NotImplementedError

@abc.abstractmethod
def get_model(self):
"""
Retrieves model for the given disk device
Returns:
A string holding disk model as provided by the manufacturer
"""
return ''
raise NotImplementedError

@abc.abstractmethod
def get_firmware(self):
"""
Retrieves firmware version for the given disk device
Returns:
A string holding disk firmware version as provided by the manufacturer
"""
return ''
raise NotImplementedError

@abc.abstractmethod
def get_serial(self):
"""
Retrieves serial number for the given disk device
Returns:
A string holding disk serial number as provided by the manufacturer
"""
return ''
raise NotImplementedError

@abc.abstractmethod
def get_vendor_output(self):
"""
Retrieves vendor specific data for the given disk device
Returns:
A string holding some vendor specific disk information
"""
return ''
raise NotImplementedError

def get_io_reads(self):
def get_disk_io_reads(self):
"""
Retrieves the total number of Input/Output (I/O) reads done on an SSD
Retrieves the total number of Input/Output (I/O) reads done on a storage disk
Returns:
An integer value of the total number of I/O reads
"""
return 20000
raise NotImplementedError

@abc.abstractmethod
def get_io_writes(self):
def get_disk_io_writes(self):
"""
Retrieves the total number of Input/Output (I/O) writes done on an SSD
Retrieves the total number of Input/Output (I/O) writes done on a storage disk
Returns:
An integer value of the total number of I/O writes
"""
return 20005
raise NotImplementedError

@abc.abstractmethod
def get_reserves_blocks(self):
def get_reserved_blocks(self):
"""
Retrieves the total number of reserved blocks in an SSD
Retrieves the total number of reserved blocks in an storage disk
Returns:
An integer value of the total number of reserved blocks
"""
return 3746218
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

BLKDEV_BASE_PATH = ''

class StorageDevices:
def __init__(self):
self.devices = {'sda' : None}

def _get_storage_devices(self):
pass

def _storage_device_object_factory(self, key):
pass
Loading

0 comments on commit 09f3c67

Please sign in to comment.