Skip to content

Commit 9be6e9c

Browse files
jipanyanglguohan
authored andcommitted
Warm reboot: warm_restart config and show commands (sonic-net#294)
* warm_restart config and show commands Signed-off-by: Jipan Yang <[email protected]> * Add syncd service into config reload list Signed-off-by: Jipan Yang <[email protected]> * Remove syncd service from config reload, syncd service not available yet Signed-off-by: Jipan Yang <[email protected]> * Adapt to the new warm restart schema for timer Signed-off-by: Jipan Yang <[email protected]>
1 parent 006ccf3 commit 9be6e9c

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed

config/main.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _get_neighbor_ipaddress_list_by_hostname(hostname):
138138
return addrs
139139

140140
def _change_bgp_session_status_by_addr(ipaddress, status, verbose):
141-
"""Start up or shut down BGP session by IP address
141+
"""Start up or shut down BGP session by IP address
142142
"""
143143
verb = 'Starting' if status == 'up' else 'Shutting'
144144
click.echo("{} {} BGP session with neighbor {}...".format(verb, status, ipaddress))
@@ -427,6 +427,46 @@ def reload():
427427
else:
428428
click.secho('Buffer definition template not found at {}'.format(buffer_template_file), fg='yellow')
429429

430+
#
431+
# 'warm_restart' group
432+
#
433+
@cli.group()
434+
@click.pass_context
435+
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
436+
def warm_restart(ctx, redis_unix_socket_path):
437+
"""warm_restart-related configuration tasks"""
438+
kwargs = {}
439+
if redis_unix_socket_path:
440+
kwargs['unix_socket_path'] = redis_unix_socket_path
441+
config_db = ConfigDBConnector(**kwargs)
442+
config_db.connect(wait_for_init=False)
443+
ctx.obj = {'db': config_db}
444+
pass
445+
446+
@warm_restart.command('enable')
447+
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss"]))
448+
@click.pass_context
449+
def warm_restart_enable(ctx, module):
450+
db = ctx.obj['db']
451+
db.mod_entry('WARM_RESTART', module, {'enable': 'true'})
452+
453+
@warm_restart.command('disable')
454+
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss"]))
455+
@click.pass_context
456+
def warm_restart_enable(ctx, module):
457+
db = ctx.obj['db']
458+
db.mod_entry('WARM_RESTART', module, {'enable': 'false'})
459+
460+
@warm_restart.command('neighsyncd_timer')
461+
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
462+
@click.pass_context
463+
def warm_restart_neighsyncd_timer(ctx, seconds):
464+
db = ctx.obj['db']
465+
if seconds not in range(1,9999):
466+
print "neighsyncd warm restart timer must be in range 1-9999"
467+
raise click.Abort
468+
db.mod_entry('WARM_RESTART', 'swss', {'neighsyncd_timer': seconds})
469+
430470
#
431471
# 'vlan' group
432472
#

show/main.py

+86-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from natsort import natsorted
1212
from tabulate import tabulate
1313
from swsssdk import ConfigDBConnector
14+
from swsssdk import SonicV2Connector
1415

1516
import mlnx
1617

@@ -780,7 +781,7 @@ def cpu(verbose):
780781
# Run top in batch mode to prevent unexpected newline after each newline
781782
cmd = "top -bn 1 -o %CPU"
782783
run_command(cmd, display_cmd=verbose)
783-
784+
784785
# 'memory' subcommand
785786
@processes.command()
786787
@click.option('--verbose', is_flag=True, help="Enable verbose output")
@@ -1174,6 +1175,90 @@ def line():
11741175
"""Show all /dev/ttyUSB lines and their info"""
11751176
cmd = "consutil show"
11761177
run_command(cmd, display_cmd=verbose)
1178+
return
1179+
1180+
1181+
@cli.group(cls=AliasedGroup, default_if_no_args=False)
1182+
def warm_restart():
1183+
"""Show warm restart configuration and state"""
1184+
pass
1185+
1186+
@warm_restart.command()
1187+
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
1188+
def state(redis_unix_socket_path):
1189+
"""Show warm restart state"""
1190+
kwargs = {}
1191+
if redis_unix_socket_path:
1192+
kwargs['unix_socket_path'] = redis_unix_socket_path
1193+
1194+
data = {}
1195+
db = SonicV2Connector(host='127.0.0.1')
1196+
db.connect(db.STATE_DB, False) # Make one attempt only
1197+
1198+
TABLE_NAME_SEPARATOR = '|'
1199+
prefix = 'WARM_RESTART_TABLE' + TABLE_NAME_SEPARATOR
1200+
_hash = '{}{}'.format(prefix, '*')
1201+
table_keys = db.keys(db.STATE_DB, _hash)
1202+
1203+
def remove_prefix(text, prefix):
1204+
if text.startswith(prefix):
1205+
return text[len(prefix):]
1206+
return text
1207+
1208+
table = []
1209+
for tk in table_keys:
1210+
entry = db.get_all(db.STATE_DB, tk)
1211+
r = []
1212+
r.append(remove_prefix(tk, prefix))
1213+
r.append(entry['restart_count'])
1214+
1215+
if 'state' not in entry:
1216+
r.append("")
1217+
else:
1218+
r.append(entry['state'])
1219+
1220+
table.append(r)
1221+
1222+
header = ['name', 'restart_count', 'state']
1223+
click.echo(tabulate(table, header))
1224+
1225+
@warm_restart.command()
1226+
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
1227+
def config(redis_unix_socket_path):
1228+
"""Show warm restart config"""
1229+
kwargs = {}
1230+
if redis_unix_socket_path:
1231+
kwargs['unix_socket_path'] = redis_unix_socket_path
1232+
config_db = ConfigDBConnector(**kwargs)
1233+
config_db.connect(wait_for_init=False)
1234+
data = config_db.get_table('WARM_RESTART')
1235+
keys = data.keys()
1236+
1237+
def tablelize(keys, data):
1238+
table = []
1239+
1240+
for k in keys:
1241+
r = []
1242+
r.append(k)
1243+
1244+
if 'enable' not in data[k]:
1245+
r.append("false")
1246+
else:
1247+
r.append(data[k]['enable'])
1248+
1249+
if 'neighsyncd_timer' in data[k]:
1250+
r.append("neighsyncd_timer")
1251+
r.append(data[k]['neighsyncd_timer'])
1252+
else:
1253+
r.append("NULL")
1254+
r.append("NULL")
1255+
1256+
table.append(r)
1257+
1258+
return table
1259+
1260+
header = ['name', 'enable', 'timer_name', 'timer_duration']
1261+
click.echo(tabulate(tablelize(keys, data), header))
11771262

11781263

11791264
if __name__ == '__main__':

0 commit comments

Comments
 (0)