Skip to content

Fix sonic-kdump-config --remote parameter handling#4193

Open
Kirankumar-Muchandi-ML wants to merge 9 commits intosonic-net:masterfrom
Kirankumar-Muchandi-ML:kdump-remote-parameter
Open

Fix sonic-kdump-config --remote parameter handling#4193
Kirankumar-Muchandi-ML wants to merge 9 commits intosonic-net:masterfrom
Kirankumar-Muchandi-ML:kdump-remote-parameter

Conversation

@Kirankumar-Muchandi-ML
Copy link

@Kirankumar-Muchandi-ML Kirankumar-Muchandi-ML commented Jan 14, 2026

Issue : sonic-net/SONiC#2121

Why I did it

The sonic-kdump-config command's --remote flag was not saving the configuration to CONFIG_DB, and it only worked as a boolean flag without accepting explicit enable/disable parameters.

Current behavior (broken):

admin@sonic:~$ sudo sonic-kdump-config --remote true
usage: sonic-kdump-config [-h] [--dump-db] [--enable] [--config-next]
                          [--disable] [--status-json] [--kdump-records-json]
                          [--config-json] [--num_dumps [NUM_DUMPS]] [--remote]
                          [--ssh_string [SSH_STRING]] [--ssh_path [SSH_PATH]]
                          [--memory [MEMORY]] [-v] [-l LINES]
sonic-kdump-config: error: unrecognized arguments: true

Additionally, even when using just --remote flag, the setting was not persisted to CONFIG_DB.


How I did it

1. Changed --remote to accept enable/disable actions

  • Before: parser.add_argument('--remote', action='store_true')
  • After: parser.add_argument('--remote', type=str, choices=['enable', 'disable'], metavar='ACTION')
  • Now accepts explicit enable or disable actions (not true/false)
  • Provides clear error message for invalid values

2. Added custom validation with helpful error messages

parser.add_argument('--remote', 
                    type=str, 
                    choices=['enable', 'disable'],
                    metavar='ACTION',
                    help="Enable or disable remote kdump. Use 'enable' or 'disable'")

When invalid value is provided:

sonic-kdump-config: error: argument --remote: Invalid action. Use 'enable' or 'disable'.

3. Fixed CONFIG_DB save functionality

  • Before: Remote setting was not saved to CONFIG_DB
  • After: Properly saves remote: true/false to CONFIG_DB based on enable/disable action
  • Changed conditional logic from elif options.remote: to elif options.remote is not None:
  • Added proper kdump_defaults['remote'] assignment based on action

4. Updated unit tests

  • Modified existing tests to use enable/disable instead of true/false
  • Added test cases for invalid values
  • All tests verify CONFIG_DB persistence

How to verify it

Test 1: Enable remote kdump

sudo sonic-kdump-config --remote enable
show kdump config

Expected:

  • Output: Remote kdump feature enabled.
  • CONFIG_DB shows: Kdump ssh connection string: <value>

Test 2: Disable remote kdump

sudo sonic-kdump-config --remote disable
show kdump config

Expected:

  • Output: Remote kdump feature disabled.
  • CONFIG_DB shows: Kdump ssh connection string and ssh_path not found

Test 3: Verify CONFIG_DB persistence

sudo sonic-kdump-config --remote enable
sudo sonic-kdump-config --dump-db | grep remote

Expected: 'remote': 'true'

sudo sonic-kdump-config --remote disable
sudo sonic-kdump-config --dump-db | grep remote

Expected: 'remote': 'false'

Test 4: Test invalid value (should fail with clear error)

sudo sonic-kdump-config --remote true

Expected error:

sonic-kdump-config: error: argument --remote: Invalid action. Use 'enable' or 'disable'.
sudo sonic-kdump-config --remote false

Expected error:

sonic-kdump-config: error: argument --remote: Invalid action. Use 'enable' or 'disable'.

Test 5: Run unit tests

cd src/sonic-utilities
python -m pytest tests/sonic_kdump_config_test.py -v

Expected: All tests pass ✓


Previous Discussion Context

This PR supersedes the previous approach that used true/false boolean values. After review feedback, the implementation was changed to use enable/disable actions for consistency with other SONiC CLI commands and better user experience.


Files Modified

Submodule: src/sonic-utilities

  • scripts/sonic-kdump-config - Updated --remote argument handling and CONFIG_DB save logic
  • tests/sonic_kdump_config_test.py - Updated test cases to use enable/disable

Submodule commits:

  • 0da311da - Fix: Save remote kdump setting to CONFIG_DB when using --remote flag
  • 1c727f27 - Update --remote to accept only 'enable' or 'disable' with clear error message
  • 48491c24 - Fix sonic-kdump-config --remote parameter handling

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

… message

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
- Changed test validator from str_to_bool to validate_remote_action
- Updated tests to use 'enable'/'disable' instead of 'true'/'false'
- Removed tests for unsupported values ('0', '1', 'yes', 'no')
- Added tests to verify 'true'/'false' are rejected
- Tests now match the actual script implementation

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
- Updated test to use ConfigDBConnector mock instead of run_command
- Test now verifies CONFIG_DB mod_entry calls with 'true'/'false' strings
- Test verifies correct print messages for enable/disable
- Removed old tests that expected sed commands (old implementation)

This fixes the test failures in CI where tests expected the old
implementation that used sed commands to modify /etc/default/kdump-tools

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
- Remove f-string without placeholders (line 38)
- Split long lines to comply with 79 character limit (lines 42-45)
- Improve code readability with proper line breaks

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Remove duplicate validate_remote_action function in test class
- Use sonic_kdump_config.validate_remote_action to test actual implementation
- This ensures the function in the main script gets proper test coverage

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Add -v/--verbose flag to display additional reboot information including
power cycle status and reboot type.

Changes:
- Add verbose parameter to fetch_data_from_db() function
- Add verbose parameter to fetch_reboot_cause_history_from_db() function
- Add -v/--verbose option to history() command
- Display 'Power Cycle' and 'Reboot Type' columns when verbose flag is used
- Show 'N/A' for fields not present in database (backward compatible)

This enables vendor-agnostic testing to verify cold reboots trigger power cycles.

Fixes: sonic-net/sonic-buildimage#25420

Signed-off-by: Kirankumar-Muchandi-ML <Kirankumar.Muchandi@Xoriant.Com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants