[sonic-xcvrd] add new daemon sonic-xcvrd to platform monitor#17
[sonic-xcvrd] add new daemon sonic-xcvrd to platform monitor#17qiluo-msft merged 9 commits intosonic-net:masterfrom keboliu:sonic-xcvrd
Conversation
…tions to DB * This new daemon will periodcally read DOM information from eeprom and post to DB * This new daemon will listen to the SFP plug in/out event and update the DB accordingly * file change list new file: scripts/xcvrd new file: setup.py Signed-off-by Liu Kebo kebol@mellanox.com
sonic-xcvrd/scripts/xcvrd
Outdated
| PHYSICAL_PORT_NOT_EXIST = -1 | ||
| SFP_EEPROM_NOT_READY = -2 | ||
|
|
||
| TEMPE_UNIT = 'C' |
There was a problem hiding this comment.
Suggest rename to TEMP_UNIT as "temp" is a common abbreviation for "temperature." #Resolved
sonic-xcvrd/scripts/xcvrd
Outdated
| REDIS_HOSTNAME = "localhost" | ||
| REDIS_PORT = 6379 | ||
| REDIS_TIMEOUT_USECS = 0 | ||
| SELECT_TIMEOUT = 1000 |
There was a problem hiding this comment.
SELECT_TIMEOUT [](start = 0, length = 14)
SELECT_TIMEOUT_USECS? #Closed
There was a problem hiding this comment.
+1 - add units to name. #Resolved
sonic-xcvrd/scripts/xcvrd
Outdated
|
|
||
| VERSION = '1.0' | ||
|
|
||
| SYSLOG_IDENTIFIER = "xcvrd" |
There was a problem hiding this comment.
xcvrd [](start = 21, length = 5)
get the script basename programatically? #Closed
There was a problem hiding this comment.
+1. This is copied from other daemons I've written, and I've also been meaning to go back over them and obtain the basename programmatically.
SYSLOG_IDENTIFIER = os.path.basename(__file__) should do the trick. #Resolved
sonic-xcvrd/scripts/xcvrd
Outdated
| VERSION = '1.0' | ||
|
|
||
| SYSLOG_IDENTIFIER = "xcvrd" | ||
| XCVRD_MODULE_NAME = "xcvrd" |
There was a problem hiding this comment.
XCVRD_MODULE_NAME [](start = 0, length = 17)
not used. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| REDIS_TIMEOUT_USECS = 0 | ||
| SELECT_TIMEOUT = 1000 | ||
|
|
||
| DOM_INFO_UPDATE_PERIOD = 60 |
There was a problem hiding this comment.
DOM_INFO_UPDATE_PERIOD [](start = 0, length = 22)
in seconds? #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
|
|
||
| DOM_INFO_UPDATE_PERIOD = 60 | ||
|
|
||
| SFP_STATUS_PLUGIN = '1' |
There was a problem hiding this comment.
SFP_STATUS_PLUGIN [](start = 0, length = 17)
plugin->inserted
plugout->removed #Closed
There was a problem hiding this comment.
| log_info("Caught SIGTERM - exiting...") | ||
| sys.exit(128 + sig) | ||
| else: | ||
| log_warning("Caught unhandled signal '" + sig + "'") |
sonic-xcvrd/scripts/xcvrd
Outdated
| @@ -0,0 +1,430 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
python [](start = 15, length = 6)
python2 #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| stdout = proc.communicate()[0] | ||
| proc.wait() | ||
| hwsku = stdout.rstrip('\n') | ||
| except OSError, e: |
There was a problem hiding this comment.
except [](start = 4, length = 6)
try-except added no value except a message which may be not accurate. Suggest remove.
Update: actually you swallow the inner exception, which make it worse. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| (platform, hwsku) = get_platform_and_hwsku() | ||
|
|
||
| # Load platform module from source | ||
| #platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) |
There was a problem hiding this comment.
#platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) [](start = 4, length = 57)
remove all commented code. #Closed
| continue | ||
|
|
||
| (key, op, fvp) = sst.pop() | ||
| if key in ["PortConfigDone", "PortInitDone"]: |
There was a problem hiding this comment.
PortConfigDone", "PortInitDone" [](start = 20, length = 31)
Will it be a problem if port configured down long before you subscribe? #Closed
There was a problem hiding this comment.
No. I have tested, even Xcvrd started after port config already done, still can get this after subscribe.
sonic-xcvrd/scripts/xcvrd
Outdated
|
|
||
| #Spawn the task to handle the SFP plug in/out event | ||
| sfp_change_event_monitoring_thread = MonitoringThread(int_tbl, dom_tbl) | ||
| sfp_change_event_monitoring_thread.start() |
There was a problem hiding this comment.
start [](start = 39, length = 5)
after starting timer and thread, the main thread is doing nothing. maybe you can use one less thread. #Closed
There was a problem hiding this comment.
moved the thread to the main task as the main loop.
sonic-xcvrd/scripts/xcvrd
Outdated
| def monitor_sfp_change_task(int_tbl, dom_tbl): | ||
| log_info('Xcvrd sub thread started....') | ||
| while True: | ||
| status, port_dict = platform_sfputil.get_transceiver_change_event() |
There was a problem hiding this comment.
status [](start = 8, length = 6)
if some error happen, the while-loop will burn CPU. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| post_port_dom_info_to_db(logical_port_name, table) | ||
|
|
||
| global timer | ||
| timer = threading.Timer(DOM_INFO_UPDATE_PERIOD, periodically_post_dom_info_to_db, [table]) |
There was a problem hiding this comment.
periodically_post_dom_info_to_db [](start = 52, length = 32)
This is weird recursion. Lots of timers will be created quickly 1->2->4->... ? #Closed
There was a problem hiding this comment.
No, if using a local variable 'timer' it will be the case as you said, here I am using a global 'timer' variable, so no this issue, timer triggered as expected.
hui-ma
left a comment
There was a problem hiding this comment.
Could you please add Txpower into database and SNMP? If you look at 8436.py and 8472.py the Sonic github (https://github.com/Azure/sonic-platform-common/blob/master/sonic_sfp), there both are a function for reading TX power calc_tx_poweron. Could you use it to get the TX power?
|
|
||
| # Start main loop to listen to the SFP change event. | ||
| log_info("Start main loop") | ||
| while True: |
There was a problem hiding this comment.
while True: [](start = 4, length = 11)
if some error happen immediately in get_transceiver_change_event(), the while-loop will burn CPU #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| log_error("Error: thread_exit_flag is set and timer thread exit") | ||
| thread_exit_flag_lock.release() | ||
| return | ||
| thread_exit_flag_lock.release() |
There was a problem hiding this comment.
You may use threading.Event to reduce code. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| for logical_port_name in logical_port_list: | ||
| post_port_dom_info_to_db(logical_port_name, table) | ||
|
|
||
| global timer |
There was a problem hiding this comment.
global [](start = 4, length = 6)
suggest define a class and move global var used by the thread inside the class. #Closed
| # TODO, SFP return error code, need handle accordingly. | ||
| continue | ||
| else: | ||
| # If get_transceiver_change_event() return error, will clean up the DB and then exit |
There was a problem hiding this comment.
You may just simply break the while loop, and do the clean up with less indentation. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| for logical_port_name in logical_port_list: | ||
| del_port_sfp_dom_info_to_db(logical_port_name, int_tbl, dom_tbl) | ||
| log_error("Error: got error from get_transceiver_change_event, exit") | ||
| return |
There was a problem hiding this comment.
return [](start = 12, length = 6)
return an non zero code to indicate daemon abnormal exit. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
|
|
||
| # Start the dom sensor info update timer thread | ||
| dom_update_threade_event = threading.Event() | ||
| dom_update_thread_timer = None |
There was a problem hiding this comment.
event and timer objects could be hidden in the update class. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| class dom_info_update_task: | ||
| def __init__(self, timer, event, table): | ||
| self.task_running_event = event | ||
| self.task_running_event.set() |
There was a problem hiding this comment.
task_running_event [](start = 13, length = 18)
How about a event for stopping. It is more intuitive and readable. #Closed
sonic-xcvrd/scripts/xcvrd
Outdated
| class dom_info_update_task: | ||
| def __init__(self, table): | ||
| self.task_stopping_event = threading.Event() | ||
| self.task_stopping_event.set() |
There was a problem hiding this comment.
task_stopping_event [](start = 13, length = 19)
self.task_stopping_event.clear() #Closed
There was a problem hiding this comment.
by default the event is set to false, so we don't need to call clear() here.
sonic-xcvrd/scripts/xcvrd
Outdated
| self.dom_table = table | ||
|
|
||
| def task_run(self): | ||
| if not self.task_stopping_event.wait(1): |
There was a problem hiding this comment.
if not self.task_stopping_event.wait(1): [](start = 8, length = 40)
if self.task_stopping_event.isSet(): #Closed
There was a problem hiding this comment.
use isSet() to get the event status.
sonic-xcvrd/scripts/xcvrd
Outdated
| self.task_timer.start() | ||
|
|
||
| def task_stop(self): | ||
| self.task_stopping_event.clear() |
There was a problem hiding this comment.
self.task_stopping_event.clear() [](start = 8, length = 32)
self.task_stopping_event.set() #Closed
Design doc: https://github.com/Azure/SONiC/blob/gh-pages/doc/OIDsforSensorandTransciver.MD