-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[systemd] ASIC status based service bringup on VOQ chassis #7477
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
Changes from all commits
bf1cb37
3e85c0a
2d69f91
4d157ba
2a9e6a1
c795150
d6426f6
c4d98b5
f714bcd
7e8b847
3c2c615
05ca42e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """ | ||
| bootstrap-asic | ||
| """ | ||
| try: | ||
| import re | ||
| import sys | ||
| from sonic_py_common import daemon_base | ||
| from swsscommon import swsscommon | ||
| from sonic_py_common import multi_asic | ||
| from sonic_py_common.logger import Logger | ||
| except ImportError as e: | ||
| raise ImportError(str(e) + " - required module not found") | ||
|
|
||
| # | ||
| # Constants ==================================================================== | ||
| # | ||
| SYSLOG_IDENTIFIER = 'asic_status.py' | ||
| CHASSIS_ASIC_INFO_TABLE = 'CHASSIS_ASIC_TABLE' | ||
| SELECT_TIMEOUT_MSECS = 5000 | ||
|
|
||
| def main(): | ||
| logger = Logger(SYSLOG_IDENTIFIER) | ||
| logger.set_min_log_priority_info() | ||
|
|
||
| if len(sys.argv) != 3: | ||
| raise Exception('Pass service and valid asic-id as arguments') | ||
|
|
||
| service = sys.argv[1] | ||
| args_asic_id = sys.argv[2] | ||
|
|
||
| # Get num asics | ||
| num_asics = multi_asic.get_num_asics() | ||
| if num_asics == 0: | ||
| logger.log_error('Detected no asics on this platform for service {}'.format(service)) | ||
| sys.exit(1) | ||
|
|
||
| # Connect to STATE_DB and subscribe to chassis-module table notifications | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Connect to CHASSIS_STATE_DB? |
||
| state_db = daemon_base.db_connect("CHASSIS_STATE_DB") | ||
|
|
||
| sel = swsscommon.Select() | ||
| sst = swsscommon.SubscriberStateTable(state_db, CHASSIS_ASIC_INFO_TABLE) | ||
| sel.addSelectable(sst) | ||
|
|
||
| while True: | ||
| (state, c) = sel.select(SELECT_TIMEOUT_MSECS) | ||
mprabhu-nokia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if state == swsscommon.Select.TIMEOUT: | ||
| continue | ||
| if state != swsscommon.Select.OBJECT: | ||
| continue | ||
|
|
||
| (asic_key, asic_op, asic_fvp) = sst.pop() | ||
| asic_id=re.search(r'\d+$', asic_key) | ||
| global_asic_id = asic_id.group(0) | ||
|
|
||
| if asic_op == 'SET': | ||
| asic_fvs = dict(asic_fvp) | ||
| asic_name = asic_fvs.get('name') | ||
| if asic_name is None: | ||
| logger.log_info('Unable to get asic_name for asic{}'.format(global_asic_id)) | ||
| continue | ||
|
|
||
| if asic_name.startswith('FABRIC-CARD') is False: | ||
| logger.log_info('Skipping module with asic_name {} for asic{}'.format(asic_name, global_asic_id)) | ||
| continue | ||
|
|
||
| if (global_asic_id == args_asic_id): | ||
| logger.log_info('Detected asic{} is online'.format(global_asic_id)) | ||
| sys.exit(0) | ||
| elif asic_op == 'DEL': | ||
| logger.log_info('Detected asic{} is offline'.format(global_asic_id)) | ||
| sys.exit(1) | ||
| else: | ||
| continue | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/bin/bash | ||
|
|
||
| is_chassis_supervisor() { | ||
| if [ -f /etc/sonic/chassisdb.conf ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to find a different way to identify it is supervisor or linecard as this file /etc/sonic/chassisdb.conf is present in both sup and linecard
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @judyjoseph @abdosi
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, yes - there is a similar reference here https://github.com/Azure/sonic-buildimage/blob/c508a10c08636c78a3fb4d7454cc93769b8fbf92/files/image_config/config-chassisdb/config-chassisdb#L40. So even though the file /usr/share/sonic/device/$platform/chassisdb.conf, is present in both supervisor and linecard, the variable "start_chassis_db=1" is set in supervisor which is used to copy the file to /etc/sonic/chassisdb.conf @mprabhu-nokia, @vganesan-nokia , @shyam77git, @anamehra -- Could you confirm this approach is followed in different chassis models ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shyam77git, @anamehra can you confirm and sign-off these changes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the outset, this seems OK i.e. having and checking chassisdb.conf presence on/for Supervisor.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of /etc/sonic/chassisdb.conf, may we have be some other mechanism like an entry in DEVICE_METADATA to distinguish between Supervisor and other cards? Non VOQ chassis may not need a chassis db.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As suggested in PR #8065 (in review comments) we can have a variable like "supervisor=1" in platform_env.conf.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, once that gets committed, we can take it up as part of a bug fix PR. Don't want to block this PR with additional dependencies now. Let me know if that is ok to proceed. |
||
| true | ||
| return | ||
| fi | ||
| false | ||
| return | ||
| } | ||
|
|
||
| check_asic_status() { | ||
| # Ignore services that are not started in namespace. | ||
| if [[ -z $DEV ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # For chassis supervisor, wait for asic to be online | ||
| /usr/local/bin/asic_status.py $SERVICE $DEV | ||
| if [[ $? = 0 ]]; then | ||
| debug "$SERVICE successfully detected asic $DEV..." | ||
| return 0 | ||
| fi | ||
| debug "$SERVICE failed to detect asic $DEV..." | ||
| return 1 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/bash | ||
mprabhu-nokia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| . /usr/local/bin/asic_status.sh | ||
judyjoseph marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function debug() | ||
| { | ||
| /usr/bin/logger $1 | ||
| /bin/echo `date` "- $1" >> ${DEBUGLOG} | ||
| } | ||
|
|
||
| start() { | ||
| debug "Starting ${SERVICE}$DEV service..." | ||
|
|
||
| # On supervisor card, skip starting asic related services here. In wait(), | ||
| # wait until the asic is detected by pmon and published via database. | ||
| if ! is_chassis_supervisor; then | ||
| # start service docker | ||
| /usr/bin/${SERVICE}.sh start $DEV | ||
| debug "Started ${SERVICE}$DEV service..." | ||
| fi | ||
| } | ||
|
|
||
| wait() { | ||
| # On supervisor card, wait for asic to be online before starting the docker. | ||
| if is_chassis_supervisor; then | ||
| check_asic_status | ||
| ASIC_STATUS=$? | ||
|
|
||
| # start service docker | ||
| if [[ $ASIC_STATUS == 0 ]]; then | ||
| /usr/bin/${SERVICE}.sh start $DEV | ||
| debug "Started ${SERVICE}$DEV service..." | ||
| fi | ||
| fi | ||
|
|
||
| /usr/bin/${SERVICE}.sh wait $DEV | ||
| } | ||
|
|
||
| stop() { | ||
| debug "Stopping ${SERVICE}$DEV service..." | ||
|
|
||
| /usr/bin/${SERVICE}.sh stop $DEV | ||
| debug "Stopped ${SERVICE}$DEV service..." | ||
| } | ||
|
|
||
| DEV=$2 | ||
|
|
||
| SERVICE="lldp" | ||
| DEBUGLOG="/tmp/lldp-debug$DEV.log" | ||
|
|
||
| case "$1" in | ||
| start|wait|stop) | ||
| $1 | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 {start|wait|stop}" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
Uh oh!
There was an error while loading. Please reload this page.