Skip to content

Commit b44b462

Browse files
jipanyangyxieca
authored andcommitted
Move warm_restart enable/disable config to stateDB WARM_RESTART_ENABL… (sonic-net#458)
* Move warm_restart enable/disable config to stateDB WARM_RESTART_ENABLE_TABLE Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com> * Fix NoneType not iterable error when no warm_restart enable/disable configured yet Signed-off-by: Jipan Yang <jipan.yang@alibaba-inc.com>
1 parent e856b8b commit b44b462

File tree

4 files changed

+56
-18
lines changed

4 files changed

+56
-18
lines changed

config/main.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import sonic_platform
1313
from swsssdk import ConfigDBConnector
14+
from swsssdk import SonicV2Connector
1415
from minigraph import parse_device_desc_xml
1516

1617
import aaa
@@ -591,22 +592,34 @@ def warm_restart(ctx, redis_unix_socket_path):
591592
kwargs['unix_socket_path'] = redis_unix_socket_path
592593
config_db = ConfigDBConnector(**kwargs)
593594
config_db.connect(wait_for_init=False)
594-
ctx.obj = {'db': config_db}
595+
596+
# warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file
597+
state_db = SonicV2Connector(host='127.0.0.1')
598+
state_db.connect(state_db.STATE_DB, False)
599+
TABLE_NAME_SEPARATOR = '|'
600+
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
601+
ctx.obj = {'db': config_db, 'state_db': state_db, 'prefix': prefix}
595602
pass
596603

597604
@warm_restart.command('enable')
598605
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss", "bgp", "teamd"]))
599606
@click.pass_context
600607
def warm_restart_enable(ctx, module):
601-
db = ctx.obj['db']
602-
db.mod_entry('WARM_RESTART', module, {'enable': 'true'})
608+
state_db = ctx.obj['state_db']
609+
prefix = ctx.obj['prefix']
610+
_hash = '{}{}'.format(prefix, module)
611+
state_db.set(state_db.STATE_DB, _hash, 'enable', 'true')
612+
state_db.close(state_db.STATE_DB)
603613

604614
@warm_restart.command('disable')
605615
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss", "bgp", "teamd"]))
606616
@click.pass_context
607617
def warm_restart_enable(ctx, module):
608-
db = ctx.obj['db']
609-
db.mod_entry('WARM_RESTART', module, {'enable': 'false'})
618+
state_db = ctx.obj['state_db']
619+
prefix = ctx.obj['prefix']
620+
_hash = '{}{}'.format(prefix, module)
621+
state_db.set(state_db.STATE_DB, _hash, 'enable', 'false')
622+
state_db.close(state_db.STATE_DB)
610623

611624
@warm_restart.command('neighsyncd_timer')
612625
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
@@ -1053,7 +1066,7 @@ def interval(interval):
10531066
"""Configure watermark telemetry interval"""
10541067
command = 'watermarkcfg --config-interval ' + interval
10551068
run_command(command)
1056-
1069+
10571070

10581071
#
10591072
# 'interface_naming_mode' subgroup ('config interface_naming_mode ...')

scripts/fast-reboot

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ function backup_database()
159159
# Delete keys in stateDB except FDB_TABLE|* and WARM_RESTA*
160160
redis-cli -n 6 eval "
161161
for _, k in ipairs(redis.call('keys', '*')) do
162-
if not string.match(k, 'FDB_TABLE|') and not string.match(k, 'WARM_RESTART_TABLE|') then
162+
if not string.match(k, 'FDB_TABLE|') and not string.match(k, 'WARM_RESTART_TABLE|') \
163+
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') then
163164
redis.call('del', k)
164165
end
165166
end

show/main.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def route_map(route_map_name, verbose):
782782
cmd += ' {}'.format(route_map_name)
783783
cmd += '"'
784784
run_command(cmd, display_cmd=verbose)
785-
785+
786786
#
787787
# 'ip' group ("show ip ...")
788788
#
@@ -1717,21 +1717,40 @@ def config(redis_unix_socket_path):
17171717
config_db = ConfigDBConnector(**kwargs)
17181718
config_db.connect(wait_for_init=False)
17191719
data = config_db.get_table('WARM_RESTART')
1720+
# Python dictionary keys() Method
17201721
keys = data.keys()
17211722

1722-
def tablelize(keys, data):
1723+
state_db = SonicV2Connector(host='127.0.0.1')
1724+
state_db.connect(state_db.STATE_DB, False) # Make one attempt only
1725+
TABLE_NAME_SEPARATOR = '|'
1726+
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
1727+
_hash = '{}{}'.format(prefix, '*')
1728+
# DBInterface keys() method
1729+
enable_table_keys = state_db.keys(state_db.STATE_DB, _hash)
1730+
1731+
def tablelize(keys, data, enable_table_keys, prefix):
17231732
table = []
17241733

1734+
if enable_table_keys is not None:
1735+
for k in enable_table_keys:
1736+
k = k.replace(prefix, "")
1737+
if k not in keys:
1738+
keys.append(k)
1739+
17251740
for k in keys:
17261741
r = []
17271742
r.append(k)
17281743

1729-
if 'enable' not in data[k]:
1744+
enable_k = prefix + k
1745+
if enable_table_keys is None or enable_k not in enable_table_keys:
17301746
r.append("false")
17311747
else:
1732-
r.append(data[k]['enable'])
1748+
r.append(state_db.get(state_db.STATE_DB, enable_k, "enable"))
17331749

1734-
if 'neighsyncd_timer' in data[k]:
1750+
if k not in data:
1751+
r.append("NULL")
1752+
r.append("NULL")
1753+
elif 'neighsyncd_timer' in data[k]:
17351754
r.append("neighsyncd_timer")
17361755
r.append(data[k]['neighsyncd_timer'])
17371756
elif 'bgp_timer' in data[k]:
@@ -1749,8 +1768,8 @@ def tablelize(keys, data):
17491768
return table
17501769

17511770
header = ['name', 'enable', 'timer_name', 'timer_duration']
1752-
click.echo(tabulate(tablelize(keys, data), header))
1753-
1771+
click.echo(tabulate(tablelize(keys, data, enable_table_keys, prefix), header))
1772+
state_db.close(state_db.STATE_DB)
17541773

17551774
if __name__ == '__main__':
17561775
cli()

sonic_installer/main.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import urllib
1111
import subprocess
1212
from swsssdk import ConfigDBConnector
13+
from swsssdk import SonicV2Connector
1314
import collections
1415

1516
HOST_PATH = '/host'
@@ -400,11 +401,15 @@ def upgrade_docker(container_name, url, cleanup_image, enforce_check, tag):
400401
# TODO: Validate the new docker image before disrupting existsing images.
401402

402403
warm = False
403-
config_db = ConfigDBConnector()
404-
config_db.connect()
405-
entry = config_db.get_entry('WARM_RESTART', container_name)
406-
if entry and entry['enable'].lower() == 'true':
404+
# warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file
405+
state_db = SonicV2Connector(host='127.0.0.1')
406+
state_db.connect(state_db.STATE_DB, False)
407+
TABLE_NAME_SEPARATOR = '|'
408+
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
409+
_hash = '{}{}'.format(prefix, container_name)
410+
if state_db.get(state_db.STATE_DB, _hash, "enable") == "true":
407411
warm = True
412+
state_db.close(state_db.STATE_DB)
408413

409414
# warm restart specific procssing for swss, bgp and teamd dockers.
410415
if warm == True:

0 commit comments

Comments
 (0)