From b44b462a14b9a4b7c2d6091b5355c046acd9dac8 Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Thu, 14 Feb 2019 08:02:29 -0800 Subject: [PATCH] =?UTF-8?q?Move=20warm=5Frestart=20enable/disable=20config?= =?UTF-8?q?=20to=20stateDB=20WARM=5FRESTART=5FENABL=E2=80=A6=20(#458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move warm_restart enable/disable config to stateDB WARM_RESTART_ENABLE_TABLE Signed-off-by: Jipan Yang * Fix NoneType not iterable error when no warm_restart enable/disable configured yet Signed-off-by: Jipan Yang --- config/main.py | 25 +++++++++++++++++++------ scripts/fast-reboot | 3 ++- show/main.py | 33 ++++++++++++++++++++++++++------- sonic_installer/main.py | 13 +++++++++---- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/config/main.py b/config/main.py index 1cd172c05134..5af9ddb80ea0 100755 --- a/config/main.py +++ b/config/main.py @@ -11,6 +11,7 @@ import sonic_platform from swsssdk import ConfigDBConnector +from swsssdk import SonicV2Connector from minigraph import parse_device_desc_xml import aaa @@ -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='', 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='', 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='', required=True, type=int) @@ -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 ...') diff --git a/scripts/fast-reboot b/scripts/fast-reboot index 73d4edea7912..2927b8f4b7c5 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -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 diff --git a/show/main.py b/show/main.py index 47cc4b724813..001a68b3232d 100755 --- a/show/main.py +++ b/show/main.py @@ -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 ...") # @@ -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]: @@ -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() diff --git a/sonic_installer/main.py b/sonic_installer/main.py index 4751f151a828..c68adabb510c 100644 --- a/sonic_installer/main.py +++ b/sonic_installer/main.py @@ -10,6 +10,7 @@ import urllib import subprocess from swsssdk import ConfigDBConnector +from swsssdk import SonicV2Connector import collections HOST_PATH = '/host' @@ -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: