Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[syseeprom] Add a new daemon to populate syseeprom info to state DB #25

Merged
merged 16 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions sonic-post-syseeprom/scripts/post-syseeprom
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python2

'''
post-syseeprom
Syseeprom information gathering tool for SONiC
This tool will be started during the start phase of pmon container, gathering syseeprom info and write to state DB.
It's an one-shot task since syseeprom info are static.
With this tool, show syseeprom CLI will be able to get data from state DB instead of access hw or cache.
'''

try:
from sonic_daemon_base.daemon_base import DaemonBase
import argparse
from swsscommon import swsscommon
from sonic_daemon_base import daemon_base
from sonic_daemon_base.daemon_base import Logger
from sonic_daemon_base.daemon_base import DaemonBase
except ImportError, e:
raise ImportError (str(e) + " - required module not found")

PLATFORM_SPECIFIC_MODULE_NAME = 'eeprom'
PLATFORM_SPECIFIC_CLASS_NAME = 'board'
EEPROM_TABLE_NAME = 'EEPROM_INFO'

ERR_ARISTA_PLATFORM = 1
keboliu marked this conversation as resolved.
Show resolved Hide resolved
ERR_FAILED_EEPROM = 2
ERR_FAILED_UPDATE_DB = 3

SYSLOG_IDENTIFIER = "post-syseeprom"

# Global logger class instance
logger = Logger(SYSLOG_IDENTIFIER)

class PostSyseeprom(DaemonBase):
def __init__(self):
DaemonBase.__init__(self)

def _is_arista_platform(self):
(platform_path, hwsku_path) = self.get_path_to_platform_and_hwsku()

return 'arista' in platform_path

def write_info_to_db(self):
if self._is_arista_platform():
# Arista platform have their own implementation for eeprom tlv parsing, it's not inherited from eeprom base class.
# So for now this tool can not support Arista platform, but this will not cause any issue on them.
# decode-syseeprom scripts will cover Arista case, it will still read from HW/cache instead from DB on Arista platform.
logger.log_warning('Arista platform does not support this yet')
return ERR_ARISTA_PLATFORM

eeprom_util = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME)
eeprom = eeprom_util.read_eeprom()
if eeprom is None :
logger.log_error('Failed to read eeprom')
return ERR_FAILED_EEPROM

err = eeprom_util.update_eeprom_db(eeprom)
keboliu marked this conversation as resolved.
Show resolved Hide resolved
if err:
logger.log_error('Failed to update eeprom info to database')
return ERR_FAILED_UPDATE_DB

def clear_db(self):
# Same case as in above write_info_to_db() function, Arista platform not supported here.
if self._is_arista_platform():
logger.log_warning('Arista platform does not support this yet')
return ERR_ARISTA_PLATFORM

state_db = daemon_base.db_connect(swsscommon.STATE_DB)
eeprom_tbl = swsscommon.Table(state_db, EEPROM_TABLE_NAME)
keys = eeprom_tbl.getKeys()
for key in keys:
eeprom_tbl._del(key)


def main():
keboliu marked this conversation as resolved.
Show resolved Hide resolved
parser = argparse.ArgumentParser(description='post-syseeprom tool')
parser.add_argument("-w", help="write syseeprom info into state DB", action='store_true')
parser.add_argument("-c", help="remove syseeprom info from state DB", action='store_true')
args = parser.parse_args()

post_syseeprom = PostSyseeprom()
if args.w:
post_syseeprom.write_info_to_db()
elif args.c:
post_syseeprom.clear_db()
else:
logger.log_error("Invalid parameter")

if __name__ == '__main__':
main()
keboliu marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions sonic-post-syseeprom/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from setuptools import setup

setup(
name='sonic-post-syseeprom',
version='1.0',
description='Tool which posts syseeprom to DB in SONiC',
license='Apache 2.0',
author='SONiC Team',
author_email='linuxnetdev@microsoft.com',
url='https://github.com/Azure/sonic-platform-daemons',
maintainer='Kebo Liu',
maintainer_email='kebol@mellanox.com',
scripts=[
'scripts/post-syseeprom',
],
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 SYSEEPROM syseeprom POST-SYSEEPROM post-syseeprom',
)