-
Notifications
You must be signed in to change notification settings - Fork 157
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
[sonic-xcvrd] add new daemon sonic-xcvrd to platform monitor #17
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest rename to TEMP_UNIT
as "temp" is a common abbreviation for "temperature." #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT_TIMEOUT [](start = 0, length = 14)
SELECT_TIMEOUT_USECS? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 - add units to name. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
sonic-xcvrd/scripts/xcvrd
Outdated
|
||
VERSION = '1.0' | ||
|
||
SYSLOG_IDENTIFIER = "xcvrd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xcvrd [](start = 21, length = 5)
get the script basename programatically? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
sonic-xcvrd/scripts/xcvrd
Outdated
VERSION = '1.0' | ||
|
||
SYSLOG_IDENTIFIER = "xcvrd" | ||
XCVRD_MODULE_NAME = "xcvrd" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XCVRD_MODULE_NAME [](start = 0, length = 17)
not used. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
sonic-xcvrd/scripts/xcvrd
Outdated
REDIS_TIMEOUT_USECS = 0 | ||
SELECT_TIMEOUT = 1000 | ||
|
||
DOM_INFO_UPDATE_PERIOD = 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOM_INFO_UPDATE_PERIOD [](start = 0, length = 22)
in seconds? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, and revised
sonic-xcvrd/scripts/xcvrd
Outdated
|
||
DOM_INFO_UPDATE_PERIOD = 60 | ||
|
||
SFP_STATUS_PLUGIN = '1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SFP_STATUS_PLUGIN [](start = 0, length = 17)
plugin->inserted
plugout->removed #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
log_info("Caught SIGTERM - exiting...") | ||
sys.exit(128 + sig) | ||
else: | ||
log_warning("Caught unhandled signal '" + sig + "'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and return? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
sonic-xcvrd/scripts/xcvrd
Outdated
@@ -0,0 +1,430 @@ | |||
#!/usr/bin/env python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python [](start = 15, length = 6)
python2 #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) [](start = 4, length = 57)
remove all commented code. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
continue | ||
|
||
(key, op, fvp) = sst.pop() | ||
if key in ["PortConfigDone", "PortInitDone"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and there are still open comments.
sonic-xcvrd/scripts/xcvrd
Outdated
|
||
# Start main loop to listen to the SFP change event. | ||
log_info("Start main loop") | ||
while True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while True: [](start = 4, length = 11)
if some error happen immediately in get_transceiver_change_event(), the while-loop will burn CPU #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use threading.Event to reduce code. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global [](start = 4, length = 6)
suggest define a class and move global var used by the thread inside the class. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may just simply break the while loop, and do the clean up with less indentation. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [](start = 12, length = 6)
return an non zero code to indicate daemon abnormal exit. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event and timer objects could be hidden in the update class. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task_running_event [](start = 13, length = 18)
How about a event for stopping. It is more intuitive and readable. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task_stopping_event [](start = 13, length = 19)
self.task_stopping_event.clear() #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.task_stopping_event.clear() [](start = 8, length = 32)
self.task_stopping_event.set() #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised.
Design doc: https://github.com/Azure/SONiC/blob/gh-pages/doc/OIDsforSensorandTransciver.MD