-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sonic-sairedis] Add support for PoE
Add SwitchPoe to vslib Add a python script to spawn the PoE syncd process Signed-off-by: Serhiy Boiko <[email protected]>
- Loading branch information
1 parent
a988dd1
commit 76f90a0
Showing
12 changed files
with
601 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,76 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import signal | ||
import subprocess | ||
import sys | ||
import syslog | ||
import time | ||
|
||
|
||
SYSLOG_IDENTIFIER = os.path.basename(__file__) | ||
|
||
EXIT_SUCCESS = 0 | ||
EXIT_INSUFFICIENT_PERMISSIONS = 1 | ||
EXIT_UNKNOWN = 2 | ||
|
||
running = True | ||
exit_code = EXIT_UNKNOWN | ||
|
||
|
||
def fatal_signal_handler(sig, frame): | ||
global running | ||
|
||
signal_name = signal.Signals(sig).name | ||
|
||
syslog.syslog(syslog.LOG_NOTICE, 'Caught signal {} - exiting...'.format(signal_name)) | ||
exit_code = sig + 128 | ||
running = False | ||
|
||
|
||
def main(): | ||
# Only privileged users can run this daemon | ||
if os.geteuid() != 0: | ||
print('Root privileges required for this operation') | ||
return EXIT_INSUFFICIENT_PERMISSIONS | ||
|
||
syslog.openlog(SYSLOG_IDENTIFIER) | ||
|
||
# Register our signal handlers | ||
signal.signal(signal.SIGTERM, fatal_signal_handler) | ||
|
||
# Check if a poe config exists | ||
if not os.path.isfile('/usr/share/sonic/hwsku/poe_config.json'): | ||
syslog.syslog(syslog.LOG_NOTICE, 'PoE is not supported on this platform. Exiting ...') | ||
syslog.closelog() | ||
time.sleep(2) | ||
return EXIT_SUCCESS | ||
|
||
# Spawn poe syncd process | ||
cmd = '/usr/bin/syncd -s -p /etc/sai.d/poe.profile -x /usr/share/sonic/hwsku/context_config.json -g 1' | ||
proc = subprocess.Popen(cmd.split(), close_fds=True) | ||
|
||
global running | ||
|
||
# Check all of our subprocesses. If any exit, we should too. | ||
while running: | ||
proc.poll() | ||
if proc.returncode is not None: | ||
syslog.syslog(syslog.LOG_NOTICE, 'Subprocess PID {} exited. Shutting down ...'.format(proc.pid)) | ||
running = False | ||
break | ||
time.sleep(1) | ||
|
||
# If we get here, either the subprocess exited or we recieved a signal to exit | ||
# so we send SIGTERM to the subprocesses (if it is still running) before exiting | ||
if proc.returncode is None: | ||
syslog.syslog(syslog.LOG_INFO, 'Terminating PID {} ...'.format(proc.pid)) | ||
proc.terminate() | ||
|
||
syslog.closelog() | ||
|
||
return exit_code | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.