mirror of
				https://github.com/Telecominfraproject/ols-nos.git
				synced 2025-11-04 03:57:57 +00:00 
			
		
		
		
	Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan arlakshm@microsoft.com Why I did it Fixes #12575 and #12575 How I did it In the PR sonic-net/sonic-platform-daemons#311 chassisd updates to CHASSIS_FABRIC_ASIC_INFO with the fabric asic info. Updating the asic_status.py to read from the correct table. How to verify it test on chassis Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan <arlakshm@microsoft.com>
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/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_FABRIC_ASIC_INFO_TABLE = 'CHASSIS_FABRIC_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
 | 
						|
    state_db = daemon_base.db_connect("CHASSIS_STATE_DB")
 | 
						|
 | 
						|
    sel = swsscommon.Select()
 | 
						|
    sst = swsscommon.SubscriberStateTable(state_db, CHASSIS_FABRIC_ASIC_INFO_TABLE)
 | 
						|
    sel.addSelectable(sst)
 | 
						|
 | 
						|
    while True:
 | 
						|
        (state, c) = sel.select(SELECT_TIMEOUT_MSECS)
 | 
						|
        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()
 |