Skip to content

Commit

Permalink
Move warm_restart enable/disable config to stateDB WARM_RESTART_ENABL… (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
jipanyang authored and yxieca committed Feb 14, 2019
1 parent e856b8b commit b44b462
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
25 changes: 19 additions & 6 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import sonic_platform
from swsssdk import ConfigDBConnector
from swsssdk import SonicV2Connector
from minigraph import parse_device_desc_xml

import aaa
Expand Down Expand Up @@ -591,22 +592,34 @@ def warm_restart(ctx, redis_unix_socket_path):
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
ctx.obj = {'db': config_db}

# warm restart enable/disable config is put in stateDB, not persistent across cold reboot, not saved to config_DB.json file
state_db = SonicV2Connector(host='127.0.0.1')
state_db.connect(state_db.STATE_DB, False)
TABLE_NAME_SEPARATOR = '|'
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
ctx.obj = {'db': config_db, 'state_db': state_db, 'prefix': prefix}
pass

@warm_restart.command('enable')
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss", "bgp", "teamd"]))
@click.pass_context
def warm_restart_enable(ctx, module):
db = ctx.obj['db']
db.mod_entry('WARM_RESTART', module, {'enable': 'true'})
state_db = ctx.obj['state_db']
prefix = ctx.obj['prefix']
_hash = '{}{}'.format(prefix, module)
state_db.set(state_db.STATE_DB, _hash, 'enable', 'true')
state_db.close(state_db.STATE_DB)

@warm_restart.command('disable')
@click.argument('module', metavar='<module>', default='system', required=False, type=click.Choice(["system", "swss", "bgp", "teamd"]))
@click.pass_context
def warm_restart_enable(ctx, module):
db = ctx.obj['db']
db.mod_entry('WARM_RESTART', module, {'enable': 'false'})
state_db = ctx.obj['state_db']
prefix = ctx.obj['prefix']
_hash = '{}{}'.format(prefix, module)
state_db.set(state_db.STATE_DB, _hash, 'enable', 'false')
state_db.close(state_db.STATE_DB)

@warm_restart.command('neighsyncd_timer')
@click.argument('seconds', metavar='<seconds>', required=True, type=int)
Expand Down Expand Up @@ -1053,7 +1066,7 @@ def interval(interval):
"""Configure watermark telemetry interval"""
command = 'watermarkcfg --config-interval ' + interval
run_command(command)


#
# 'interface_naming_mode' subgroup ('config interface_naming_mode ...')
Expand Down
3 changes: 2 additions & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ function backup_database()
# Delete keys in stateDB except FDB_TABLE|* and WARM_RESTA*
redis-cli -n 6 eval "
for _, k in ipairs(redis.call('keys', '*')) do
if not string.match(k, 'FDB_TABLE|') and not string.match(k, 'WARM_RESTART_TABLE|') then
if not string.match(k, 'FDB_TABLE|') and not string.match(k, 'WARM_RESTART_TABLE|') \
and not string.match(k, 'WARM_RESTART_ENABLE_TABLE|') then
redis.call('del', k)
end
end
Expand Down
33 changes: 26 additions & 7 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def route_map(route_map_name, verbose):
cmd += ' {}'.format(route_map_name)
cmd += '"'
run_command(cmd, display_cmd=verbose)

#
# 'ip' group ("show ip ...")
#
Expand Down Expand Up @@ -1717,21 +1717,40 @@ def config(redis_unix_socket_path):
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
data = config_db.get_table('WARM_RESTART')
# Python dictionary keys() Method
keys = data.keys()

def tablelize(keys, data):
state_db = SonicV2Connector(host='127.0.0.1')
state_db.connect(state_db.STATE_DB, False) # Make one attempt only
TABLE_NAME_SEPARATOR = '|'
prefix = 'WARM_RESTART_ENABLE_TABLE' + TABLE_NAME_SEPARATOR
_hash = '{}{}'.format(prefix, '*')
# DBInterface keys() method
enable_table_keys = state_db.keys(state_db.STATE_DB, _hash)

def tablelize(keys, data, enable_table_keys, prefix):
table = []

if enable_table_keys is not None:
for k in enable_table_keys:
k = k.replace(prefix, "")
if k not in keys:
keys.append(k)

for k in keys:
r = []
r.append(k)

if 'enable' not in data[k]:
enable_k = prefix + k
if enable_table_keys is None or enable_k not in enable_table_keys:
r.append("false")
else:
r.append(data[k]['enable'])
r.append(state_db.get(state_db.STATE_DB, enable_k, "enable"))

if 'neighsyncd_timer' in data[k]:
if k not in data:
r.append("NULL")
r.append("NULL")
elif 'neighsyncd_timer' in data[k]:
r.append("neighsyncd_timer")
r.append(data[k]['neighsyncd_timer'])
elif 'bgp_timer' in data[k]:
Expand All @@ -1749,8 +1768,8 @@ def tablelize(keys, data):
return table

header = ['name', 'enable', 'timer_name', 'timer_duration']
click.echo(tabulate(tablelize(keys, data), header))

click.echo(tabulate(tablelize(keys, data, enable_table_keys, prefix), header))
state_db.close(state_db.STATE_DB)

if __name__ == '__main__':
cli()
13 changes: 9 additions & 4 deletions sonic_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import urllib
import subprocess
from swsssdk import ConfigDBConnector
from swsssdk import SonicV2Connector
import collections

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

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

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

0 comments on commit b44b462

Please sign in to comment.