Skip to content

Commit 7281308

Browse files
[kdump] Remove automatic saving of kdump config in startup config (#1882)
* [kdump] Remove automatic saving of kdump config in startup config 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. * [kdump] Remove unused variables
1 parent d2baedb commit 7281308

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

config/kdump.py

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def disable():
1616
if config_db is not None:
1717
config_db.connect()
1818
config_db.mod_entry("KDUMP", "config", {"enabled": "false"})
19+
click.echo("KDUMP configuration changes may require a reboot to take effect.")
20+
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")
1921

2022
@kdump.command()
2123
def enable():
@@ -24,6 +26,8 @@ def enable():
2426
if config_db is not None:
2527
config_db.connect()
2628
config_db.mod_entry("KDUMP", "config", {"enabled": "true"})
29+
click.echo("KDUMP configuration changes may require a reboot to take effect.")
30+
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")
2731

2832
@kdump.command()
2933
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
@@ -33,6 +37,8 @@ def memory(kdump_memory):
3337
if config_db is not None:
3438
config_db.connect()
3539
config_db.mod_entry("KDUMP", "config", {"memory": kdump_memory})
40+
click.echo("KDUMP configuration changes may require a reboot to take effect.")
41+
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.")
3642

3743
@kdump.command('num-dumps')
3844
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)

scripts/sonic-kdump-config

-43
Original file line numberDiff line numberDiff line change
@@ -356,39 +356,6 @@ def write_num_dumps(num_dumps):
356356
print_err("Error while writing KDUMP_NUM_DUMPS into %s" % kdump_cfg)
357357
sys.exit(1)
358358

359-
## Save kdump configuration into the startup configuration
360-
# @kdump_enabled Administrative mode (False/True)
361-
# @memory Amount of memory allocated for the capture kernel
362-
# @num_dumps Max number of core files saved locally
363-
def save_config(kdump_enabled, memory, num_dumps):
364-
365-
configdb_fname = '/etc/sonic/config_db.json'
366-
367-
# Read current configuration
368-
if not os.path.exists(configdb_fname):
369-
print_err("Startup configuration not found, Kdump configuration is not saved")
370-
return
371-
else:
372-
try:
373-
with open(configdb_fname) as json_file:
374-
data = json.load(json_file)
375-
except Exception as e:
376-
print_err("Error [%s] while reading startup configuration" % e)
377-
return
378-
379-
# Rewrite configuration
380-
try:
381-
kdump_data = {'config': {'enabled': '', 'num_dumps': '', 'memory': ''}}
382-
(kdump_data['config'])['enabled'] = str(kdump_enabled).lower()
383-
(kdump_data['config'])['num_dumps'] = str(num_dumps)
384-
(kdump_data['config'])['memory'] = memory
385-
data['KDUMP'] = kdump_data
386-
with open(configdb_fname, 'w') as fp:
387-
json.dump(data, fp, indent=4, sort_keys=False)
388-
print("Kdump configuration has been updated in the startup configuration")
389-
except Exception as e:
390-
print_err("Error [%s] while saving Kdump configuration to startup configuration" % e)
391-
392359
## Enable kdump
393360
#
394361
# @param verbose If True, the function will display a few additinal information
@@ -432,9 +399,6 @@ def kdump_enable(verbose, kdump_enabled, memory, num_dumps, image, cmdline_file)
432399

433400
if changed:
434401
rewrite_cfg(lines, cmdline_file)
435-
save_config(kdump_enabled, memory, num_dumps)
436-
else:
437-
save_config(kdump_enabled, memory, num_dumps)
438402

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

546510
if changed:
547511
rewrite_grub_cfg(lines, grub_cfg)
548-
save_config(kdump_enabled, memory, num_dumps)
549512

550513
return changed
551514

@@ -588,9 +551,6 @@ def cmd_kdump_memory(verbose, memory):
588551
if memory != crash_kernel_in_cmdline or memory != memory_in_db or memory != memory_in_json:
589552
cmd_kdump_enable(verbose)
590553
print("Kdump updated memory will be only operational after the system reboots")
591-
else:
592-
num_dumps = get_kdump_num_dumps()
593-
save_config(False, memory, num_dumps)
594554

595555
## Command: Set / Get num_dumps
596556
#
@@ -603,9 +563,6 @@ def cmd_kdump_num_dumps(verbose, num_dumps):
603563
print('\n'.join(lines))
604564
else:
605565
write_num_dumps(num_dumps)
606-
kdump_enabled = get_kdump_administrative_mode()
607-
kdump_memory = get_kdump_memory()
608-
save_config(kdump_enabled, kdump_memory, num_dumps)
609566

610567
## Command: Display kdump status
611568
def cmd_kdump_status():

0 commit comments

Comments
 (0)