@@ -395,9 +395,8 @@ def test_write_kdump_remote_true(self, mock_read_remote, mock_run_command):
395395 sonic_kdump_config .write_kdump_remote () # Call the function
396396
397397 # Ensure the correct commands were run to uncomment SSH and SSH_KEY
398- mock_run_command .assert_any_call ("/bin/sed -i 's/#SSH/SSH/' /etc/default/kdump-tools" , use_shell = False )
399- mock_run_command .assert_any_call ("/bin/sed -i 's/#SSH_KEY/SSH_KEY/' /etc/default/kdump-tools" , use_shell = False )
400- self .assertEqual (mock_run_command .call_count , 2 ) # Ensure both commands were called
398+ mock_run_command .assert_any_call ("/bin/sed -i 's/^#SSH/SSH/' /etc/default/kdump-tools" , use_shell = False )
399+ self .assertEqual (mock_run_command .call_count , 1 ) # Ensure the sed command was called once
401400
402401 @patch ("sonic_kdump_config.run_command" )
403402 @patch ("sonic_kdump_config.get_kdump_remote" )
@@ -408,9 +407,8 @@ def test_write_kdump_remote_false(self, mock_read_remote, mock_run_command):
408407 sonic_kdump_config .write_kdump_remote () # Call the function
409408
410409 # Ensure the correct commands were run to comment SSH and SSH_KEY
411- mock_run_command .assert_any_call ("/bin/sed -i 's/SSH/#SSH/' /etc/default/kdump-tools" , use_shell = False )
412- mock_run_command .assert_any_call ("/bin/sed -i 's/SSH_KEY/#SSH_KEY/' /etc/default/kdump-tools" , use_shell = False )
413- self .assertEqual (mock_run_command .call_count , 2 )
410+ mock_run_command .assert_any_call ("/bin/sed -i 's/^SSH/#SSH/' /etc/default/kdump-tools" , use_shell = False )
411+ self .assertEqual (mock_run_command .call_count , 1 )
414412
415413 @patch ("sonic_kdump_config.get_kdump_remote" )
416414 @patch ("sonic_kdump_config.run_command" )
@@ -422,16 +420,14 @@ def test_cmd_kdump_remote(self, mock_run_command, mock_read_remote):
422420 sonic_kdump_config .cmd_kdump_remote (verbose = True )
423421
424422 # Ensure the correct commands are being run
425- mock_run_command .assert_any_call ("/bin/sed -i 's/#SSH/SSH/' /etc/default/kdump-tools" , use_shell = False )
426- mock_run_command .assert_any_call ("/bin/sed -i 's/#SSH_KEY/SSH_KEY/' /etc/default/kdump-tools" , use_shell = False )
423+ mock_run_command .assert_any_call ("/bin/sed -i 's/^#SSH/SSH/' /etc/default/kdump-tools" , use_shell = False )
427424
428425 # Test case: Remote is False
429426 mock_read_remote .return_value = False
430427 sonic_kdump_config .cmd_kdump_remote (verbose = True )
431428
432429 # Ensure the correct commands are being run
433- mock_run_command .assert_any_call ("/bin/sed -i 's/SSH/#SSH/' /etc/default/kdump-tools" , use_shell = False )
434- mock_run_command .assert_any_call ("/bin/sed -i 's/SSH_KEY/#SSH_KEY/' /etc/default/kdump-tools" , use_shell = False )
430+ mock_run_command .assert_any_call ("/bin/sed -i 's/^SSH/#SSH/' /etc/default/kdump-tools" , use_shell = False )
435431
436432 # Test case: Checking output messages
437433 with patch ("builtins.print" ) as mock_print :
@@ -538,7 +534,7 @@ def test_write_ssh_path(self, mock_read_ssh_path, mock_run_cmd):
538534 sonic_kdump_config .write_ssh_path ('/path/to/keys' ) # Call function with valid path
539535 # Ensure the correct command is being run
540536 expected_cmd = (
541- "/bin/sed -i -e 's/ #*SSH_KEY=.*/ SSH_KEY=\" /path/to/keys\" / ' %s"
537+ "/bin/sed -i -e 's| #*SSH_KEY=.*| SSH_KEY=\" /path/to/keys\" | ' %s"
542538 % sonic_kdump_config .kdump_cfg
543539 )
544540 mock_run_cmd .assert_called_once_with (expected_cmd , use_shell = False )
@@ -670,23 +666,6 @@ def test_cmd_kdump_ssh_path_update(self, mock_print, mock_write, mock_read, mock
670666 # Verify that the correct message is printed
671667 mock_print .assert_called_once_with ("SSH path updated. Changes will take effect after reboot." )
672668
673- @patch ('sonic_kdump_config.run_command' )
674- @patch ('sonic_kdump_config.read_ssh_path' )
675- @patch ('sonic_kdump_config.write_ssh_path' )
676- @patch ('builtins.print' ) # Mock print to capture printed output
677- def test_cmd_kdump_ssh_path_no_update (self , mock_print , mock_write , mock_read , mock_run ):
678- # Mock read_ssh_path to return the same SSH path provided
679- mock_read .return_value = '/same/path/to/keys'
680-
681- # Call the function with the same SSH path
682- sonic_kdump_config .cmd_kdump_ssh_path (verbose = True , ssh_path = '/same/path/to/keys' )
683-
684- # Check that write_ssh_path was not called
685- mock_write .assert_not_called ()
686-
687- # Check that no message is printed for update
688- mock_print .assert_not_called ()
689-
690669 @patch ("sonic_kdump_config.write_use_kdump" )
691670 @patch ("os.path.exists" )
692671 def test_kdump_disable (self , mock_path_exist , mock_write_kdump ):
0 commit comments