-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathasic_status.py
executable file
·79 lines (65 loc) · 2.46 KB
/
asic_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/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':
if (global_asic_id == args_asic_id):
logger.log_info('Detected asic{} is offline'.format(global_asic_id))
sys.exit(1)
else:
continue
if __name__ == "__main__":
main()