From 54ebfc8efd7331e948944fbbd817b299fb30b617 Mon Sep 17 00:00:00 2001 From: zhenggen-xu Date: Fri, 5 Oct 2018 22:02:58 -0700 Subject: [PATCH] Add a "-l/--load-sysinfo" option for "config reload" to merge the system info on device (#324) The information includes: -- platform string -- system mac -- port configuration: alias, lanes, speed, index This is useful when we first load the configuration from config_db.json generated outside which does not have the information on the device. The default behaviour is not changed, so it won't impact the system unless you use this option. This can be used for ZTP to config the box the first time and avoid any addtional work which could cause inconsistency. --- config/main.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 6664aee08cf1..bbd715b6e774 100755 --- a/config/main.py +++ b/config/main.py @@ -276,17 +276,33 @@ def load(filename, yes): @cli.command() @click.option('-y', '--yes', is_flag=True) +@click.option('-l', '--load-sysinfo', is_flag=True, help='load system default information (mac, portmap etc) first.') @click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True)) -def reload(filename, yes): +def reload(filename, yes, load_sysinfo): """Clear current configuration and import a previous saved config DB dump file.""" if not yes: click.confirm('Clear current config and reload config from the file %s?' % filename, abort=True) + + if load_sysinfo: + command = "{} -j {} -v DEVICE_METADATA.localhost.hwsku".format(SONIC_CFGGEN_PATH, filename) + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + cfg_hwsku, err = proc.communicate() + if err: + click.echo("Could not get the HWSKU from config file, exiting") + sys.exit(1) + else: + cfg_hwsku = cfg_hwsku.strip() + #Stop services before config push _stop_services() config_db = ConfigDBConnector() config_db.connect() client = config_db.redis_clients[config_db.CONFIG_DB] client.flushdb() + if load_sysinfo: + command = "{} -H -k {} --write-to-db".format(SONIC_CFGGEN_PATH, cfg_hwsku) + run_command(command, display_cmd=True) + command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) run_command(command, display_cmd=True) client.set(config_db.INIT_INDICATOR, 1)