Skip to content

Commit

Permalink
Implementation of a Monitoring Daemon for storage devices in SONiC sw…
Browse files Browse the repository at this point in the history
…itches
  • Loading branch information
dgsudharsan committed May 22, 2024
1 parent 9ffce20 commit 42c7d90
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sonic-stormond/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=scripts --cov-report html --cov-report term --cov-report xml --junitxml=test-results.xml -vv
375 changes: 375 additions & 0 deletions sonic-stormond/scripts/stormond

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions sonic-stormond/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test=pytest
43 changes: 43 additions & 0 deletions sonic-stormond/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from setuptools import setup

setup(
name='sonic-stormond',
version='1.0',
description='Storage Device Monitoring Daemon for SONiC',
license='Apache 2.0',
author='SONiC Team',
author_email='[email protected]',
url='https://github.com/sonic-net/sonic-platform-daemons',
maintainer='Ashwin Srinivasan',
maintainer_email='[email protected]',
scripts=[
'scripts/stormond',
],
setup_requires=[
'pytest-runner',
'wheel'
],
install_requires=[
'enum34; python_version < "3.4"',
'sonic-py-common',
],
tests_require=[
'mock>=2.0.0; python_version < "3.3"',
'pytest',
'pytest-cov',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: No Input/Output (Daemon)',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Topic :: System :: Hardware',
],
keywords='sonic SONiC ssd Ssd SSD ssdmond storage stormond storagemond',
test_suite='setup.get_test_suite'
)
Empty file.
15 changes: 15 additions & 0 deletions sonic-stormond/tests/mock_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

"""
Mock implementation of sonic_platform package for unit testing
"""

# TODO: Clean this up once we no longer need to support Python 2
import sys
if sys.version_info.major == 3:
from unittest import mock
else:
import mock

class MockStorageDevice():
def __init__(self):
super(MockStorageDevice, self).__init__()
6 changes: 6 additions & 0 deletions sonic-stormond/tests/mocked_libs/sonic_platform/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Mock implementation of sonic_platform package for unit testing
"""

from . import ssd

13 changes: 13 additions & 0 deletions sonic-stormond/tests/mocked_libs/sonic_platform/ssd.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.storage_base import StorageBase


class Storage(StorageBase):
def __init__(self):
self.platform_Storageutil = "/tmp/Storage"

def __str__(self):
return self.platform_Storageutil
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#
# ssd.py
#
# Generic implementation of the SSD health API
# SSD models supported:
# - InnoDisk
# - StorFly
# - Virtium

try:
import re
import subprocess
from .storage_base import StorageBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

SMARTCTL = "smartctl {} -a"
INNODISK = "iSmart -d {}"
VIRTIUM = "SmartCmd -m {}"

NOT_AVAILABLE = "N/A"

# Set Vendor Specific IDs
INNODISK_HEALTH_ID = 169
INNODISK_TEMPERATURE_ID = 194
SWISSBIT_HEALTH_ID = 248
SWISSBIT_TEMPERATURE_ID = 194

class SsdUtil(StorageBase):
"""
Generic implementation of the SSD health API
"""

def __init__(self, diskdev):
model = 'InnoDisk Corp. - mSATA 3IE3'
serial = 'BCA11712190600251'
firmware = 'S16425cG'
temperature = 32.3
health = 91.6
ssd_info = NOT_AVAILABLE
vendor_ssd_info = NOT_AVAILABLE
io_reads = 20000
io_writes = 20005
reserved_blocks = 3746218

def get_health(self):
"""
Retrieves current disk health in percentages
Returns:
A float number of current ssd health
e.g. 83.5
"""
return self.health

def get_temperature(self):
"""
Retrieves current disk temperature in Celsius
Returns:
A float number of current temperature in Celsius
e.g. 40.1
"""
return self.temperature

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

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 self.firmware

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 self.serial

def get_vendor_output(self):
"""
Retrieves vendor specific data for the given disk device
Returns:
A string holding some vendor specific disk information
"""
return self.vendor_ssd_info

def get_io_writes(self):
"""
Retrieves the total number of Input/Output (I/O) writes done on an SSD
Returns:
An integer value of the total number of I/O writes
"""
return self.io_writes

def get_io_reads(self):
"""
Retrieves the total number of Input/Output (I/O) writes done on an SSD
Returns:
An integer value of the total number of I/O writes
"""
return self.io_reads

def get_reserves_blocks(self):
"""
Retrieves the total number of reserved blocks in an SSD
Returns:
An integer value of the total number of reserved blocks
"""
return self.reserved_blocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#
# 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
#


class StorageBase(object):
"""
Base class for interfacing with a SSD
"""
def __init__(self, diskdev):
"""
Constructor
Args:
diskdev: Linux device name to get parameters for
"""
pass

@abc.abstractmethod
def get_health(self):
"""
Retrieves current disk health in percentages
Returns:
A float number of current ssd health
e.g. 83.5
"""
return 91.6

@abc.abstractmethod
def get_temperature(self):
"""
Retrieves current disk temperature in Celsius
Returns:
A float number of current temperature in Celsius
e.g. 40.1
"""
return 32.3

@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 ''

@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 ''

@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 ''

@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 ''

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

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

@abc.abstractmethod
def get_reserves_blocks(self):
"""
Retrieves the total number of reserved blocks in an SSD
Returns:
An integer value of the total number of reserved blocks
"""
return 3746218
5 changes: 5 additions & 0 deletions sonic-stormond/tests/mocked_libs/swsscommon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'''
Mock implementation of swsscommon package for unit testing
'''

from . import swsscommon
Loading

0 comments on commit 42c7d90

Please sign in to comment.