Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kdump-Remote-SSH-Configurations #3400

Open
wants to merge 210 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
210 commits
Select commit Hold shift + click to select a range
8e1a4b4
kdump-remote-configurations
Ghulam-Bahoo Jul 4, 2024
3893fc9
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
03c2b63
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
6f34f88
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
18caaba
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
7d7226c
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
49b511a
Corrected Functions
Ghulam-Bahoo Jul 10, 2024
a67a777
Corrected Functions
Ghulam-Bahoo Jul 11, 2024
2094bc7
Corrected Functions
Ghulam-Bahoo Jul 11, 2024
7ae0635
Corrected Functions
Ghulam-Bahoo Jul 11, 2024
518837e
Corrected Function Names
Ghulam-Bahoo Jul 11, 2024
d74f909
Corrected Function Names
Ghulam-Bahoo Jul 11, 2024
17e0790
Corrected Function Names
Ghulam-Bahoo Jul 11, 2024
999d298
Corrected Function Names
Ghulam-Bahoo Jul 11, 2024
361bb75
Corrected Function Names
Ghulam-Bahoo Jul 12, 2024
48eb48d
Corrected Function Names
Ghulam-Bahoo Jul 12, 2024
194f333
Corrected Indentation
Ghulam-Bahoo Jul 12, 2024
45fe33e
Corrected Indentation
Ghulam-Bahoo Jul 12, 2024
8c97669
Corrected Functions
Ghulam-Bahoo Jul 12, 2024
2453d25
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
cfbdd13
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
1b7091b
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
82f8000
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
7efce5d
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
12f0279
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
3c22c75
Corrected Functions
Ghulam-Bahoo Jul 19, 2024
6d2f7ce
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
f4856c7
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
2d0cacb
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
c1f2076
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
d3e975a
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
18895d3
Corrected Functions
Ghulam-Bahoo Jul 22, 2024
4fe15b1
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
8588324
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
65a07b0
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
247cb24
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
edd60cf
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
c9d4b83
Corrected Functions
Ghulam-Bahoo Jul 23, 2024
146c2c8
Merge branch 'sonic-net:master' into kdump_ssh_Enhancement
muhammadalihussnain Jul 24, 2024
668a357
Before Disabling Remove Key and Path
muhammadalihussnain Jul 24, 2024
16927d0
b4 disable remove key and path
muhammadalihussnain Jul 24, 2024
301b953
resolved db.mode_entry issue
muhammadalihussnain Jul 24, 2024
d32c898
removed hash from Remove function
muhammadalihussnain Jul 24, 2024
26530b9
erased space line 142 kdump.py
muhammadalihussnain Jul 25, 2024
fb3c04c
Corrected Functions
Ghulam-Bahoo Jul 25, 2024
557d2da
Corrected Functions
Ghulam-Bahoo Jul 25, 2024
88f72c5
Corrected Functions
Ghulam-Bahoo Jul 25, 2024
d52d4fd
assign to only Hash and deHash SSH AND SSH_KEY
muhammadalihussnain Jul 25, 2024
871bc9b
ADDED HASHING AND UNHASHING
muhammadalihussnain Jul 25, 2024
1a94b1e
resolove syntax of python
muhammadalihussnain Jul 25, 2024
e6af5ca
resolove syntax of python
muhammadalihussnain Jul 25, 2024
c5b1917
resolove syntax of python
muhammadalihussnain Jul 25, 2024
eb35995
just writing values to DB
muhammadalihussnain Jul 25, 2024
8d20e9c
Unit Tests
Ghulam-Bahoo Jul 25, 2024
af76fe1
Merge remote-tracking branch 'origin/kdump_ssh_Enhancement' into kdum…
Ghulam-Bahoo Jul 25, 2024
efbfa46
utility only comments and uncomments and add value to db
muhammadalihussnain Jul 25, 2024
8eaf182
Merge remote-tracking branch 'origin/kdump_ssh_Enhancement' into kdum…
muhammadalihussnain Jul 25, 2024
bd1d2f1
Testing
muhammadalihussnain Jul 25, 2024
657d913
Removed test cases
muhammadalihussnain Jul 26, 2024
9a95762
typo
muhammadalihussnain Jul 26, 2024
91c24c2
typo
muhammadalihussnain Jul 26, 2024
adda82e
typo
muhammadalihussnain Jul 26, 2024
6810b25
typo
muhammadalihussnain Jul 26, 2024
ac0b0e6
typo
muhammadalihussnain Jul 26, 2024
82f94b9
typo
muhammadalihussnain Jul 26, 2024
486a486
typo
muhammadalihussnain Jul 26, 2024
f709f03
typo
muhammadalihussnain Jul 29, 2024
ebaefc0
typo
muhammadalihussnain Jul 29, 2024
bc04bb7
added test cases for code coverage
muhammadalihussnain Jul 30, 2024
6f9c74f
added test cases for code coverage
muhammadalihussnain Jul 30, 2024
1bbf78a
erased white space and blanks
muhammadalihussnain Jul 30, 2024
98f3e14
erased white space and blanks
muhammadalihussnain Jul 30, 2024
bc87384
erased white space and blanks
muhammadalihussnain Jul 30, 2024
617523b
erased white space and blanks
muhammadalihussnain Jul 30, 2024
d8fe5b8
erased white space and blanks
muhammadalihussnain Jul 30, 2024
a5c5f34
erased functions from scripts/kdump file
muhammadalihussnain Jul 31, 2024
318f658
erased functions from scripts/kdump file
muhammadalihussnain Jul 31, 2024
53a3530
just added test case for the remote enable
muhammadalihussnain Jul 31, 2024
dd13c18
just added test case for the remote enable
muhammadalihussnain Jul 31, 2024
9f21cf6
just added test case for the remote enable
muhammadalihussnain Jul 31, 2024
4e66ca1
...
muhammadalihussnain Jul 31, 2024
2400b33
remote enable/disable test
muhammadalihussnain Aug 1, 2024
91763ef
...
muhammadalihussnain Aug 1, 2024
2ea0e24
test
muhammadalihussnain Aug 1, 2024
76eb141
remote enable/disable test
muhammadalihussnain Aug 1, 2024
1eec069
...
muhammadalihussnain Aug 1, 2024
ba6af36
...
muhammadalihussnain Aug 1, 2024
5eedadd
...
muhammadalihussnain Aug 1, 2024
3e9b1a3
...
muhammadalihussnain Aug 2, 2024
71a42f7
...
muhammadalihussnain Aug 2, 2024
b73360e
...
muhammadalihussnain Aug 2, 2024
51648ac
added kdump add and remove test case
muhammadalihussnain Aug 2, 2024
0c87f96
added lines to which are not covered in test case for coverage
muhammadalihussnain Aug 2, 2024
f05ce6b
added lines to which are not covered in test case for coverage
muhammadalihussnain Aug 2, 2024
f252fb8
added lines to which are not covered in test case for coverage
muhammadalihussnain Aug 2, 2024
7f96d23
handling error for code coverage
muhammadalihussnain Aug 2, 2024
1194a45
handling error for code coverage
muhammadalihussnain Aug 2, 2024
f3e8098
changed the logic to write on kdump-tools file
muhammadalihussnain Aug 2, 2024
9e657d8
changed the logic to write on kdump-tools file
muhammadalihussnain Aug 2, 2024
8d760b1
changed the logic to write on kdump-tools file
muhammadalihussnain Aug 2, 2024
35ced45
changed the logic to write on kdump-tools file
muhammadalihussnain Aug 4, 2024
5aaab85
modified test case failing writing on kdump-tools file
muhammadalihussnain Aug 5, 2024
b8eb084
modified test case failing writing on kdump-tools file
muhammadalihussnain Aug 5, 2024
9144810
modified test case failing writing on kdump-tools file
muhammadalihussnain Aug 5, 2024
41a3a41
modified test case failing writing on kdump-tools file
muhammadalihussnain Aug 5, 2024
50847d1
modified test case failing writing on kdump-tools file
muhammadalihussnain Aug 5, 2024
b928199
changed entrire policy
muhammadalihussnain Aug 6, 2024
2510c85
changed entrire policy
muhammadalihussnain Aug 6, 2024
886d21c
changed entrire policy
muhammadalihussnain Aug 6, 2024
ec1cc1a
changed entrire policy
muhammadalihussnain Aug 6, 2024
036257f
changed entrire policy
muhammadalihussnain Aug 6, 2024
48d1cae
changed entrire policy
muhammadalihussnain Aug 6, 2024
d1c5543
removed commas
muhammadalihussnain Aug 6, 2024
c620c18
after enable expected SSH=<user at server>
muhammadalihussnain Aug 6, 2024
b30391d
after enable expected SSH=<user at server>
muhammadalihussnain Aug 7, 2024
05c420f
after enable expected SSH=<user at server>
muhammadalihussnain Aug 7, 2024
fcc77a7
after enable expected SSH=<user at server>
muhammadalihussnain Aug 7, 2024
ef95754
after enable expected SSH=<user at server>
muhammadalihussnain Aug 7, 2024
06ccd35
new test case
muhammadalihussnain Aug 7, 2024
d8ac24c
new test case
muhammadalihussnain Aug 7, 2024
8401e77
new test case
muhammadalihussnain Aug 7, 2024
adc256a
Updated the test case
muhammadalihussnain Aug 7, 2024
b1f9379
Updated the test case
muhammadalihussnain Aug 7, 2024
5527452
Updated the test case
muhammadalihussnain Aug 7, 2024
bf91f71
Updated the test case
muhammadalihussnain Aug 7, 2024
368328b
Updated the test case
muhammadalihussnain Aug 7, 2024
b3b5d18
added remove kdump item test case
muhammadalihussnain Aug 7, 2024
46fb9d5
static analysis correction
muhammadalihussnain Aug 8, 2024
94d2609
static analysis correction
muhammadalihussnain Aug 8, 2024
5f91081
static analysis correction
muhammadalihussnain Aug 8, 2024
3604182
static analysis
muhammadalihussnain Aug 8, 2024
e5ccfcb
updated INFO
muhammadalihussnain Sep 6, 2024
18809cb
added remote function
muhammadalihussnain Sep 23, 2024
762a163
typo
muhammadalihussnain Sep 23, 2024
b231c11
resolved errors
muhammadalihussnain Sep 23, 2024
ba8172a
typoes
muhammadalihussnain Sep 23, 2024
60c067b
typoes
muhammadalihussnain Sep 23, 2024
e05c85d
typoes
muhammadalihussnain Sep 23, 2024
a2c829d
bypass tests-cases for now
muhammadalihussnain Sep 23, 2024
6549fe1
bypass tests-cases for now
muhammadalihussnain Sep 23, 2024
ab53019
bypass tests-cases for now
muhammadalihussnain Sep 23, 2024
5a6cf43
test cases
muhammadalihussnain Sep 23, 2024
9912125
error check
muhammadalihussnain Sep 24, 2024
f68fa48
white spaces in blank lines
muhammadalihussnain Sep 24, 2024
e5a93ac
@pass_db at commands
muhammadalihussnain Sep 24, 2024
0343e5b
added code from start for remote enable/disable without test-cases
muhammadalihussnain Sep 24, 2024
2dede5b
pretest failures removed
muhammadalihussnain Sep 24, 2024
3fdee51
added test case for the code remote enable/disable
muhammadalihussnain Sep 24, 2024
3bda604
added test case for the code remote enable/disable
muhammadalihussnain Sep 24, 2024
d7efd0d
type changed argument
muhammadalihussnain Sep 24, 2024
a966efa
type changed argument
muhammadalihussnain Sep 24, 2024
cc6c765
testcases
muhammadalihussnain Sep 24, 2024
3970ec8
testcases typos
muhammadalihussnain Sep 24, 2024
a6ec1ce
testcases typos
muhammadalihussnain Sep 24, 2024
3951942
testcases typos
muhammadalihussnain Sep 24, 2024
1d64ffc
testcases typos
muhammadalihussnain Sep 24, 2024
5741922
testcases typos
muhammadalihussnain Sep 24, 2024
6abe2f9
added removed functionality and test cases
muhammadalihussnain Sep 25, 2024
eebdd79
added removed functionality and test cases
muhammadalihussnain Sep 25, 2024
e93041a
typo
muhammadalihussnain Sep 25, 2024
5bdc5c9
removed error from test case
muhammadalihussnain Sep 25, 2024
077d336
removed errors related to pre-test analysis
muhammadalihussnain Sep 25, 2024
ea02048
removed errors related to pre-test analysis
muhammadalihussnain Sep 25, 2024
e6968ae
changes in sonic-kdump-config
muhammadalihussnain Sep 25, 2024
a1d4077
syntax error in show-kdump
muhammadalihussnain Sep 25, 2024
d8fb143
syntax error in show-kdump
muhammadalihussnain Sep 25, 2024
2db858c
syntax error in show-kdump
muhammadalihussnain Sep 25, 2024
d9c8f39
line 681 kdump-remote with rmote
muhammadalihussnain Sep 26, 2024
41c0be3
b4 adding string and path check remote status
muhammadalihussnain Sep 26, 2024
00e7c5f
updated test case
muhammadalihussnain Sep 26, 2024
623f822
updated test case
muhammadalihussnain Sep 26, 2024
e5357c8
updated test case
muhammadalihussnain Sep 26, 2024
6f1d7fc
updated test case
muhammadalihussnain Sep 26, 2024
89cc594
updated test case
muhammadalihussnain Sep 26, 2024
bf6102d
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
2a7595b
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
88dd4f0
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
9fae7d0
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
96ecc6d
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
826bb11
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
9f18a6a
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
3bc371f
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
4109593
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
d897d79
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
6670418
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
d1b6c32
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
dbafbac
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
ef1252d
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
e4d24c5
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
eaf3efa
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
b2911e2
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 27, 2024
b57b1ed
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
2898e78
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
49b674e
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
72cbd6a
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
db43785
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
7f1f2f4
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
0ea1d54
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
e1f2c7a
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
8f70056
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
57982a0
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
3200dea
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
956c0dc
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
1f83d6a
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
eb1a597
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
bc212a5
added some test cases for read,write strin/path sonic-kdump-config-test
muhammadalihussnain Sep 28, 2024
5a55046
added remote enable/disable code and tests
muhammadalihussnain Oct 1, 2024
43d9caf
pre-test error removed
muhammadalihussnain Oct 1, 2024
5cf9b60
changed code to remove error
muhammadalihussnain Oct 1, 2024
90cf8f1
changed code to remove error
muhammadalihussnain Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 126 additions & 14 deletions config/kdump.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import sys

import click
from utilities_common.cli import AbbreviationGroup, pass_db


from utilities_common.cli import AbbreviationGroup, pass_db
from pathlib import Path
#
# 'kdump' group ('sudo config kdump ...')
#

@click.group(cls=AbbreviationGroup, name="kdump")
def kdump():
"""Configure the KDUMP mechanism"""
pass


def check_kdump_table_existence(kdump_table):
"""Checks whether the 'KDUMP' table is configured in Config DB.

Expand All @@ -32,9 +31,15 @@ def check_kdump_table_existence(kdump_table):
sys.exit(2)


def echo_reboot_warning():
"""Prints the warning message about reboot requirements."""
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.")
#
# 'disable' command ('sudo config kdump disable')
#


@kdump.command(name="disable", short_help="Disable the KDUMP mechanism")
@pass_db
def kdump_disable(db):
Expand All @@ -43,13 +48,13 @@ 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.")

echo_reboot_warning()

#
# 'enable' command ('sudo config kdump enable')
#


@kdump.command(name="enable", short_help="Enable the KDUMP mechanism")
@pass_db
def kdump_enable(db):
Expand All @@ -58,13 +63,13 @@ 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.")

echo_reboot_warning()

#
# 'memory' command ('sudo config kdump memory ...')
#


@kdump.command(name="memory", short_help="Configure the memory for KDUMP mechanism")
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True)
@pass_db
Expand All @@ -74,13 +79,13 @@ 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.")

echo_reboot_warning()

#
# 'num_dumps' command ('sudo config keump num_dumps ...')
# 'num_dumps' command ('sudo config kdump num_dumps ...')
#


@kdump.command(name="num_dumps", short_help="Configure the maximum dump files of KDUMP mechanism")
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int)
@pass_db
Expand All @@ -90,3 +95,110 @@ def kdump_num_dumps(db, kdump_num_dumps):
check_kdump_table_existence(kdump_table)

db.cfgdb.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})
echo_reboot_warning()


# 'remote' command ('sudo config kdump remote ...')
@kdump.command(name="remote", short_help="Enable or Disable Kdump Remote")
@click.argument('action', required=True, type=click.Choice(['enable', 'disable'], case_sensitive=False))
@pass_db
def kdump_remote(db, action):

"""Enable or Disable Kdump Remote Mode"""
kdump_table = db.cfgdb.get_table("KDUMP")
check_kdump_table_existence(kdump_table)
current_remote_status = kdump_table.get("config", {}).get("remote", "false").lower()

if action.lower() == 'enable' and current_remote_status == 'true':
click.echo("Error: Kdump Remote Mode is already enabled.")
Copy link
Contributor

@venkatmahalingam venkatmahalingam Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need not be error; you can just report INFO level message.

return

elif action.lower() == 'disable' and current_remote_status == 'false':
click.echo("Error: Kdump Remote Mode is already disabled.")
return

if action.lower() == 'disable':
ssh_string = kdump_table.get("config", {}).get("ssh_string", None)
ssh_key = kdump_table.get("config", {}).get("ssh_key", None)
if ssh_string or ssh_key:
click.echo("Error: Remove SSH_string, SSH_key from Config DB before disabling Kdump Remote Mode.")
Copy link
Contributor

@venkatmahalingam venkatmahalingam Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should the SSH keys removed before KDUMP global disable? any dependency?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSH keys needs to be removed before disabling Kdump Remote Mode to avoid leftover values in the configuration files. If not removed, these keys will stay in the "kdump-tools" file and could cause confusion or security issues later. Clearing them ensures the configuration is accurate and clean

return

remote = 'true' if action.lower() == 'enable' else 'false'
db.cfgdb.mod_entry("KDUMP", "config", {"remote": remote})
file_path = Path('/etc/default/kdump-tools')

# Values to be set for SSH and SSH_KEY
DEFAULT_SSH = "<user at server>"
DEFAULT_SSH_KEY = "<path>"

with open(file_path, 'r') as file:
lines = file.readlines()
updated_lines = []

for line in lines:
if remote:
if line.startswith("#SSH="):
updated_lines.append(f'SSH={DEFAULT_SSH}\n')
elif line.startswith("#SSH_KEY="):
updated_lines.append(f'SSH_KEY={DEFAULT_SSH_KEY}\n')
else:
updated_lines.append(line)
else:
if line.startswith("SSH="):
updated_lines.append(f'#SSH={DEFAULT_SSH}\n')
elif line.startswith("SSH_KEY="):
updated_lines.append(f'#SSH_KEY={DEFAULT_SSH_KEY}\n')
else:
updated_lines.append(line)

with open(file_path, 'w') as file:
file.writelines(updated_lines)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be handled in hostcfgd?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct; this could be managed by hostcfgd for better consistency. We chose to handle it directly here for simplicity and immediate updates. we will modify the code hostcfgd to handle this and remove from utility

echo_reboot_warning()


# 'add' command ('sudo config kdump add ...')
@kdump.command(name="add", short_help="Add SSH connection string or SSH key path.")
@click.argument('item', type=click.Choice(['ssh_string', 'ssh_path']))
@click.argument('value', metavar='<value>', required=True)
@pass_db
def add_kdump_item(db, item, value):
"""Add SSH connection string or SSH key path for kdump"""
kdump_table = db.cfgdb.get_table("KDUMP")
check_kdump_table_existence(kdump_table)

# Check if remote mode is enabled
remote_mode_enabled = kdump_table.get("config", {}).get("remote", "false").lower()
if remote_mode_enabled != "true":
click.echo("Error: Enable remote mode first.")
return

# Check if the item is already added
existing_value = kdump_table.get("config", {}).get(item)
if existing_value:
click.echo(f"Error: {item} is already added.")
return

# Add item to config_db
db.cfgdb.mod_entry("KDUMP", "config", {item: value})
echo_reboot_warning()


@kdump.command(name="remove", short_help="Remove SSH connection string or SSH key path.")
@click.argument('item', type=click.Choice(['ssh_string', 'ssh_path']))
@pass_db
def remove_kdump_item(db, item):
"""Remove SSH connection string or SSH key path for kdump"""
kdump_table = db.cfgdb.get_table("KDUMP")
check_kdump_table_existence(kdump_table)

# Check if the item is already configured
existing_value = kdump_table.get("config", {}).get(item)
if not existing_value:
click.echo(f"Error: {item} is not configured.")
return

# Remove item from config_db
db.cfgdb.mod_entry("KDUMP", "config", {item: ""})
click.echo(f"{item} removed successfully.")
echo_reboot_warning()
12 changes: 6 additions & 6 deletions scripts/sonic-kdump-config
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ def cmd_dump_config_json():
kdump_enabled = get_kdump_administrative_mode()
kdump_memory = get_kdump_memory()
kdump_num_dumps = get_kdump_num_dumps()
# remote SSH variables
data = { "enable" : kdump_enabled, \
"memory" : kdump_memory, \
"max-dumps" : int(kdump_num_dumps) }
"max-dumps" : int(kdump_num_dumps)}
print(json.dumps(data, indent=4))

def cmd_dump_kdump_records_json():
Expand Down Expand Up @@ -223,6 +224,7 @@ def cmd_dump_status_json():
kdump_oper_state = get_kdump_oper_mode(kdump_enabled)
kdump_memory = get_kdump_memory()
kdump_num_dumps = get_kdump_num_dumps()
# remote SSH variables
data = { "enable" : kdump_enabled, \
"current-state" : kdump_oper_state, \
"memory" : kdump_memory, \
Expand Down Expand Up @@ -417,7 +419,7 @@ def kdump_enable(verbose, kdump_enabled, memory, num_dumps, image, cmdline_file)

## Read kdump configuration saved in the startup configuration file
#
# @param config_param If True, the function will display a few additional information
# @param config_param If True, the function will display a few additional information.
# @return Value of the configuration parameter saved in the startup configuration file
# @return None if the startup configuration file does not exist or the kdump
# configuration parameter is not present in the file.
Expand Down Expand Up @@ -449,8 +451,7 @@ def cmd_kdump_enable(verbose, image):
memory = get_kdump_memory()
num_dumps = get_kdump_num_dumps()
if verbose:
print("configDB: kdump_enabled=%d memory=[%s] num_nums=%d" % (kdump_enabled, memory, num_dumps))

print("kdump enabled: %s" % kdump_enabled)
if os.path.exists(grub_cfg):
return kdump_enable(verbose, kdump_enabled, memory, num_dumps, image, grub_cfg)
elif open(machine_cfg, 'r').read().find('aboot_platform') >= 0:
Expand Down Expand Up @@ -527,10 +528,9 @@ def cmd_kdump_disable(verbose):
kdump_enabled = get_kdump_administrative_mode()
memory = get_kdump_memory()
num_dumps = get_kdump_num_dumps()

if verbose:
print("configDB: kdump_enabled=%d memory=[%s] num_nums=%d" % (kdump_enabled, memory, num_dumps))

if os.path.exists(grub_cfg):
return kdump_disable(verbose, image, grub_cfg)
elif open(machine_cfg, 'r').read().find('aboot_platform') >= 0:
Expand Down
8 changes: 8 additions & 0 deletions show/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def config():
num_files_config = get_kdump_config("num_dumps")
click.echo("Maximum number of Kdump files: {}".format(num_files_config))

# remote SSH configs
if get_kdump_config("remote") == "true":
ssh_conn_str = get_kdump_config("ssh_string")
click.echo("Kdump ssh connection string: {}".format(ssh_conn_str))

ssh_prv_key = get_kdump_config("ssh_path")
click.echo("Kdump private key path: {}".format(ssh_prv_key))


def get_kdump_core_files():
"""Retrieves the kernel core dump files from directory '/var/crash/'.
Expand Down
Loading
Loading