-
Notifications
You must be signed in to change notification settings - Fork 209
[syseeprom] Add a new daemon to populate syseeprom info to state DB #25
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
94583f5
Merge pull request #1 from Azure/master
keboliu 263b266
add post-syseeprom scripts to pmon
keboliu 99f7b7f
remove hardcoded magic numbers
keboliu c932c61
reword and fix typo
keboliu df6fdf9
add options for scripts to handle clear db function
keboliu 674b981
refactor the scripts with adding class
keboliu aaf358f
Revert "refactor the scripts with adding class"
keboliu ea1a8ce
fix logger
keboliu 4018560
add long arguments and rename one error code
keboliu ae372c4
add return code for some error case
keboliu 9edaa9c
add return code
keboliu 6070223
change one shot task to a daemon
keboliu f56bb5a
fix typo
keboliu 1fc9549
fix typo
keboliu 5e82cae
rewording the comments and rename a variable
keboliu 181bd9f
adjust the polling period according to the review comments
keboliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,143 @@ | ||
| #!/usr/bin/env python2 | ||
|
|
||
| ''' | ||
| syseepromd | ||
| Syseeprom information gathering daemon for SONiC | ||
| This daemon will be started during the start phase of pmon container, gathering syseeprom info and write to state DB. | ||
| It will continue monitoring the state DB for the syseeprom table, if table been deleted, it will write again. | ||
| With this daemon, show syseeprom CLI will be able to get data from state DB instead of access hw or cache. | ||
| ''' | ||
|
|
||
| try: | ||
| import signal | ||
| import threading | ||
| from sonic_daemon_base.daemon_base import DaemonBase | ||
| from sonic_daemon_base.daemon_base import Logger | ||
| from sonic_daemon_base import daemon_base | ||
| from swsscommon import swsscommon | ||
| except ImportError, e: | ||
| raise ImportError (str(e) + " - required module not found") | ||
|
|
||
| PLATFORM_SPECIFIC_MODULE_NAME = 'eeprom' | ||
| PLATFORM_SPECIFIC_CLASS_NAME = 'board' | ||
|
|
||
| EEPROM_INFO_UPDATE_PERIOD_SECS = 10 | ||
keboliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| POST_EEPROM_SUCCESS = 0 | ||
| ERR_PLATFORM_NOT_SUPPORT = 1 | ||
| ERR_FAILED_EEPROM = 2 | ||
| ERR_FAILED_UPDATE_DB = 3 | ||
| ERR_INVALID_PARAMETER = 4 | ||
| ERR_PSUUTIL_LOAD = 4 | ||
|
|
||
| EEPROM_TABLE_NAME = 'EEPROM_INFO' | ||
| SYSLOG_IDENTIFIER = 'syseepromd' | ||
|
|
||
| # Global logger class instance | ||
| logger = Logger(SYSLOG_IDENTIFIER) | ||
|
|
||
| class DaemonSyseeprom(DaemonBase): | ||
| def __init__(self): | ||
| DaemonBase.__init__(self) | ||
|
|
||
| self.stop = threading.Event() | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self.eeprom_util = None | ||
|
|
||
| state_db = daemon_base.db_connect(swsscommon.STATE_DB) | ||
| self.eeprom_tbl = swsscommon.Table(state_db, EEPROM_TABLE_NAME) | ||
| self.eepromtbl_keys = [] | ||
|
|
||
| def load_eeprom_util(self): | ||
| try: | ||
| self.eeprom_util = self.load_platform_util(PLATFORM_SPECIFIC_MODULE_NAME, PLATFORM_SPECIFIC_CLASS_NAME) | ||
| except Exception as e: | ||
| logger.log_error("Failed to load psuutil: %s" % (str(e)), True) | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sys.exit(ERR_PSUUTIL_LOAD) | ||
|
|
||
| def post_eeprom_to_db(self): | ||
| eeprom = self.eeprom_util.read_eeprom() | ||
| if eeprom is None : | ||
| logger.log_error("Failed to read eeprom") | ||
| return ERR_FAILED_EEPROM | ||
|
|
||
| err = self.eeprom_util.update_eeprom_db(eeprom) | ||
| if err: | ||
| logger.log_error("Failed to update eeprom info to database") | ||
| return ERR_FAILED_UPDATE_DB | ||
|
|
||
| self.eepromtbl_keys = self.eeprom_tbl.getKeys() | ||
|
|
||
| return POST_EEPROM_SUCCESS | ||
|
|
||
| def clear_db(self): | ||
| keys = self.eeprom_tbl.getKeys() | ||
| for key in keys: | ||
| self.eeprom_tbl._del(key) | ||
|
|
||
| def detect_eeprom_table_integrity(self): | ||
| keys = self.eeprom_tbl.getKeys() | ||
|
|
||
| if len(keys) != len(self.eepromtbl_keys): | ||
| return False | ||
|
|
||
| for key in self.eepromtbl_keys: | ||
| if key not in keys: | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| # Signal handler | ||
| def signal_handler(self, sig, frame): | ||
| if sig == signal.SIGHUP: | ||
| logger.log_info("Caught SIGHUP - ignoring...") | ||
| elif sig == signal.SIGINT: | ||
| logger.log_info("Caught SIGINT - exiting...") | ||
| self.stop.set() | ||
| elif sig == signal.SIGTERM: | ||
| logger.log_info("Caught SIGTERM - exiting...") | ||
| self.stop.set() | ||
| else: | ||
| logger.log_warning("Caught unhandled signal '" + sig + "'") | ||
|
|
||
| # Run daemon | ||
| def run(self): | ||
| logger.log_info("Starting up...") | ||
|
|
||
| # Load platform-specific eepromutil class | ||
| self.load_eeprom_util() | ||
|
|
||
| # Connect to STATE_DB and post syseeprom info to state DB | ||
| rc = self.post_eeprom_to_db() | ||
| if rc != POST_EEPROM_SUCCESS: | ||
| return rc | ||
|
|
||
| # Start main loop | ||
| logger.log_info("Start daemon main loop") | ||
|
|
||
| while not self.stop.wait(EEPROM_INFO_UPDATE_PERIOD_SECS): | ||
| rc = self.detect_eeprom_table_integrity() | ||
| if not rc: | ||
| logger.log_info("sys eeprom table was changed, need update") | ||
| self.clear_db() | ||
| rcs = self.post_eeprom_to_db() | ||
| if rcs != POST_EEPROM_SUCCESS: | ||
| self.stop.set() | ||
|
|
||
| logger.log_info("Stop daemon main loop") | ||
|
|
||
| # Delete all the information from DB and then exit | ||
| self.clear_db() | ||
|
|
||
| logger.log_info("Shutting down...") | ||
|
|
||
| # | ||
| # Main ========================================================================= | ||
| # | ||
|
|
||
| def main(): | ||
| syseepromd = DaemonSyseeprom() | ||
| syseepromd.run() | ||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
|
|
||
This file contains hidden or 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,29 @@ | ||
| from setuptools import setup | ||
|
|
||
| setup( | ||
| name='sonic-syseepromd', | ||
| version='1.0', | ||
| description='Syseeprom gathering daemon for 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/syseepromd', | ||
| ], | ||
| 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 SYSEEPROMD syseepromd', | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.