From 2125e2a245c7b6d246ff2e5bfb50dbd9c077f2fc Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Mon, 3 May 2021 22:45:05 +0000 Subject: [PATCH 1/4] Config reload fix --- config/main.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 828c447e5f..b2fbcdd871 100644 --- a/config/main.py +++ b/config/main.py @@ -702,6 +702,32 @@ def _restart_services(): click.echo("Reloading Monit configuration ...") clicommon.run_command("sudo monit reload") +def _get_delay_timers(): + out = clicommon.run_command("systemctl list-dependencies delay.target --plain |sed '1d'", return_cmd=True) + return [timer.strip() for timer in out.splitlines()] + +def _delay_timers_elapsed(): + for timer in _get_delay_timers(): + out = clicommon.run_command("systemctl show {} --property=LastTriggerUSecMonotonic --value".format(timer), return_cmd=True) + if out.strip() == "0": + return False + return True + +def _swss_ready(): + out = clicommon.run_command("systemctl show swss.service --property ActiveState --value", return_cmd=True) + if out.strip() != "active": + return False + out = clicommon.run_command("systemctl show swss.service --property ActiveEnterTimestampMonotonic --value", return_cmd=True) + swss_up_time = float(out.strip())/1000000 + now = time.monotonic() + if (now - swss_up_time > 120): + return True + else: + return False + +def _system_running(): + out = clicommon.run_command("sudo systemctl is-system-running", return_cmd=True) + return out.strip() == "running" def interface_is_in_vlan(vlan_member_table, interface_name): """ Check if an interface is in a vlan """ @@ -1191,12 +1217,26 @@ def list_checkpoints(ctx, verbose): @click.option('-l', '--load-sysinfo', is_flag=True, help='load system default information (mac, portmap etc) first.') @click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services') @click.option('-d', '--disable_arp_cache', default=False, is_flag=True, help='Do not cache ARP table before reloading (applies to dual ToR systems only)') +@click.option('-f', '--force', default=False, is_flag=True, help='Force config reload without system checks') @click.argument('filename', required=False) @clicommon.pass_db -def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cache): +def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cache, force): """Clear current configuration and import a previous saved config DB dump file. : Names of configuration file(s) to load, separated by comma with no spaces in between """ + if not force and not no_service_restart: + if not _system_running(): + click.echo("System is not up") + return + + if not _delay_timers_elapsed(): + click.echo("Services are not up") + return + + if not _swss_ready(): + click.echo("SWSS is not ready") + return + if filename is None: message = 'Clear current config and reload config from the default config file(s) ?' else: From 6b7df06c51c6642be14a2a634166585915470407 Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Fri, 4 Jun 2021 17:12:57 +0000 Subject: [PATCH 2/4] Review comments --- config/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/main.py b/config/main.py index b2fbcdd871..51f94e3715 100644 --- a/config/main.py +++ b/config/main.py @@ -1226,15 +1226,15 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach """ if not force and not no_service_restart: if not _system_running(): - click.echo("System is not up") + click.echo("System is not up. Retry later or use -f to avoid system checks") return if not _delay_timers_elapsed(): - click.echo("Services are not up") + click.echo("Relevant services are not up. Retry later or use -f to avoid system checks") return if not _swss_ready(): - click.echo("SWSS is not ready") + click.echo("Orchagent container is not up. Retry later or use -f to avoid system checks") return if filename is None: From 4b248ac6a25b0ed21b20ceee3e619b02cb8e518b Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Mon, 14 Jun 2021 16:28:58 +0000 Subject: [PATCH 3/4] Addressing review comments --- config/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 51f94e3715..dac71d5b87 100644 --- a/config/main.py +++ b/config/main.py @@ -1234,7 +1234,7 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, disable_arp_cach return if not _swss_ready(): - click.echo("Orchagent container is not up. Retry later or use -f to avoid system checks") + click.echo("SwSS container is not ready. Retry later or use -f to avoid system checks") return if filename is None: From 637b6641529d8f24fa2cc2d315cac593e42f958a Mon Sep 17 00:00:00 2001 From: Sudharsan Dhamal Gopalarathnam Date: Wed, 16 Jun 2021 21:40:28 +0000 Subject: [PATCH 4/4] Renaming delay.target to sonic-delayed.target --- config/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index dac71d5b87..9d6cdd2b40 100644 --- a/config/main.py +++ b/config/main.py @@ -703,7 +703,7 @@ def _restart_services(): clicommon.run_command("sudo monit reload") def _get_delay_timers(): - out = clicommon.run_command("systemctl list-dependencies delay.target --plain |sed '1d'", return_cmd=True) + out = clicommon.run_command("systemctl list-dependencies sonic-delayed.target --plain |sed '1d'", return_cmd=True) return [timer.strip() for timer in out.splitlines()] def _delay_timers_elapsed():