Skip to content

Commit

Permalink
[kdump] Remove automatic saving of kdump config in startup config (so…
Browse files Browse the repository at this point in the history
…nic-net#1859)

Fix sonic-net#8888

Warn user to save the config instead of saving the kdump config
in config_db.json under the covers. Having more than one actors
operate on config_db.json can result in an exception.
  • Loading branch information
rajendra-dendukuri authored Oct 7, 2021
1 parent 88baf3d commit d13955a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 40 deletions.
6 changes: 6 additions & 0 deletions config/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def kdump_disable(db):
check_kdump_table_existence(kdump_table)

db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "false"})
click.echo("KDUMP configuration changes may require a reboot to take effect.")
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")


#
Expand All @@ -56,6 +58,8 @@ def kdump_enable(db):
check_kdump_table_existence(kdump_table)

db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "true"})
click.echo("KDUMP configuration changes may require a reboot to take effect.")
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")


#
Expand All @@ -70,6 +74,8 @@ def kdump_memory(db, kdump_memory):
check_kdump_table_existence(kdump_table)

db.cfgdb.mod_entry("KDUMP", "config", {"memory": kdump_memory})
click.echo("KDUMP configuration changes may require a reboot to take effect.")
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")


#
Expand Down
39 changes: 0 additions & 39 deletions scripts/sonic-kdump-config
Original file line number Diff line number Diff line change
Expand Up @@ -356,39 +356,6 @@ def write_num_dumps(num_dumps):
print_err("Error while writing KDUMP_NUM_DUMPS into %s" % kdump_cfg)
sys.exit(1)

## Save kdump configuration into the startup configuration
# @kdump_enabled Administrative mode (False/True)
# @memory Amount of memory allocated for the capture kernel
# @num_dumps Max number of core files saved locally
def save_config(kdump_enabled, memory, num_dumps):

configdb_fname = '/etc/sonic/config_db.json'

# Read current configuration
if not os.path.exists(configdb_fname):
print_err("Startup configuration not found, Kdump configuration is not saved")
return
else:
try:
with open(configdb_fname) as json_file:
data = json.load(json_file)
except Exception as e:
print_err("Error [%s] while reading startup configuration" % e)
return

# Rewrite configuration
try:
kdump_data = {'config': {'enabled': '', 'num_dumps': '', 'memory': ''}}
(kdump_data['config'])['enabled'] = str(kdump_enabled).lower()
(kdump_data['config'])['num_dumps'] = str(num_dumps)
(kdump_data['config'])['memory'] = memory
data['KDUMP'] = kdump_data
with open(configdb_fname, 'w') as fp:
json.dump(data, fp, indent=4, sort_keys=False)
print("Kdump configuration has been updated in the startup configuration")
except Exception as e:
print_err("Error [%s] while saving Kdump configuration to startup configuration" % e)

## Enable kdump
#
# @param verbose If True, the function will display a few additinal information
Expand Down Expand Up @@ -432,9 +399,6 @@ def kdump_enable(verbose, kdump_enabled, memory, num_dumps, image, cmdline_file)

if changed:
rewrite_cfg(lines, cmdline_file)
save_config(kdump_enabled, memory, num_dumps)
else:
save_config(kdump_enabled, memory, num_dumps)

write_use_kdump(1)
if crash_kernel_in_cmdline is not None:
Expand Down Expand Up @@ -545,7 +509,6 @@ def kdump_disable(verbose, kdump_enabled, memory, num_dumps, image, cmdline_file

if changed:
rewrite_grub_cfg(lines, grub_cfg)
save_config(kdump_enabled, memory, num_dumps)

return changed

Expand Down Expand Up @@ -590,7 +553,6 @@ def cmd_kdump_memory(verbose, memory):
print("Kdump updated memory will be only operational after the system reboots")
else:
num_dumps = get_kdump_num_dumps()
save_config(False, memory, num_dumps)

## Command: Set / Get num_dumps
#
Expand All @@ -605,7 +567,6 @@ def cmd_kdump_num_dumps(verbose, num_dumps):
write_num_dumps(num_dumps)
kdump_enabled = get_kdump_administrative_mode()
kdump_memory = get_kdump_memory()
save_config(kdump_enabled, kdump_memory, num_dumps)


def main():
Expand Down
2 changes: 1 addition & 1 deletion show/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def config():
click.echo("Kdump operational mode: {}".format(oper_mode))

mem_config = get_kdump_config("memory")
click.echo("Kdump memory researvation: {}".format(mem_config))
click.echo("Kdump memory reservation: {}".format(mem_config))

num_files_config = get_kdump_config("num_dumps")
click.echo("Maximum number of Kdump files: {}".format(num_files_config))
Expand Down

0 comments on commit d13955a

Please sign in to comment.