From fd67bbf6e23150e0a74ec1a9cdac5792c3110d28 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Sat, 30 Sep 2017 01:17:58 +0000 Subject: [PATCH 1/2] Flush DB first when loading from minigraph --- config/main.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 6208cc7dda..901add26e7 100644 --- a/config/main.py +++ b/config/main.py @@ -118,6 +118,20 @@ def load(filename): command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) run_command(command, display_cmd=True) +@cli.command() +@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, + expose_value=False, prompt='Clear current and reload all config?') +@click.argument('filename', default='/etc/sonic/config_db.json', type=click.Path(exists=True)) +def reload(filename): + """Clear current configuration and import a previous saved config DB dump file.""" + config_db = ConfigDBConnector() + config_db.connect() + client = config_db.redis_clients[config_db.CONFIG_DB] + client.flushdb() + command = "{} -j {} --write-to-db".format(SONIC_CFGGEN_PATH, filename) + run_command(command, display_cmd=True) + client.set(config_db.INIT_INDICATOR, True) + @cli.command() @click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, expose_value=False, prompt='Reload mgmt config?') @@ -135,14 +149,20 @@ def load_mgmt_config(filename): run_command(command, display_cmd=True) command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid" run_command(command, display_cmd=True) + print "Please note loaded configuration will be lost after system reboot. To preserve setting, run `config save`." @cli.command() @click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, expose_value=False, prompt='Reload config from minigraph?') def load_minigraph(): """Reconfigure based on minigraph.""" + config_db = ConfigDBConnector() + config_db.connect() + client = config_db.redis_clients[config_db.CONFIG_DB] + client.flushdb() command = "{} -m --write-to-db".format(SONIC_CFGGEN_PATH) run_command(command, display_cmd=True) + client.set(config_db.INIT_INDICATOR, True) command = "{} -m -v \"DEVICE_METADATA['localhost']['hostname']\"".format(SONIC_CFGGEN_PATH) p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) p.wait() @@ -159,7 +179,7 @@ def load_minigraph(): run_command("service lldp restart", display_cmd=True) run_command("service snmp restart", display_cmd=True) run_command("service dhcp_relay restart", display_cmd=True) - + print "Please note configuration loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`." # # 'bgp' group # From 47e2a2e437c63a6bd7fc8d9000eaa3158f7fe9aa Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Tue, 3 Oct 2017 00:04:00 +0000 Subject: [PATCH 2/2] Resolve CR comments --- config/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/main.py b/config/main.py index 901add26e7..dcaa9e4fed 100644 --- a/config/main.py +++ b/config/main.py @@ -149,7 +149,7 @@ def load_mgmt_config(filename): run_command(command, display_cmd=True) command = "[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid" run_command(command, display_cmd=True) - print "Please note loaded configuration will be lost after system reboot. To preserve setting, run `config save`." + print "Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`." @cli.command() @click.option('-y', '--yes', is_flag=True, callback=_abort_if_false, @@ -179,7 +179,7 @@ def load_minigraph(): run_command("service lldp restart", display_cmd=True) run_command("service snmp restart", display_cmd=True) run_command("service dhcp_relay restart", display_cmd=True) - print "Please note configuration loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`." + print "Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`." # # 'bgp' group #