@@ -400,7 +400,7 @@ def test_is_tcp_open_success(self):
400400 mock_socket .return_value .__exit__ = MagicMock ()
401401 result = gnoi_shutdown_daemon .is_tcp_open ("10.0.0.1" , 8080 , timeout = 1.0 )
402402 self .assertTrue (result )
403- mock_socket .assert_called_once_with (("10.0.0.1" , 8080 ), 1.0 )
403+ mock_socket .assert_called_once_with (("10.0.0.1" , 8080 ), timeout = 1.0 )
404404
405405 def test_is_tcp_open_failure (self ):
406406 """Test is_tcp_open when connection fails."""
@@ -469,5 +469,47 @@ def test_set_gnoi_shutdown_complete_flag_success(self):
469469 call_args = mock_table .set .call_args
470470 self .assertEqual (call_args [0 ][0 ], "DPU0" )
471471
472+ def test_is_tcp_open_default_timeout (self ):
473+ """Test is_tcp_open uses environment variable for default timeout."""
474+ with patch .dict (os .environ , {"GNOI_DIAL_TIMEOUT" : "2.5" }):
475+ with patch ('gnoi_shutdown_daemon.socket.create_connection' ) as mock_socket :
476+ mock_socket .return_value .__enter__ = MagicMock ()
477+ mock_socket .return_value .__exit__ = MagicMock ()
478+ result = gnoi_shutdown_daemon .is_tcp_open ("10.0.0.1" , 8080 )
479+ self .assertTrue (result )
480+ mock_socket .assert_called_once_with (("10.0.0.1" , 8080 ), timeout = 2.5 )
481+
482+ def test_get_dpu_ip_list_ips (self ):
483+ """Test get_dpu_ip when ips is a list (normal case)."""
484+ mock_config = MagicMock ()
485+ mock_config .get_entry .return_value = {"ips" : ["10.0.0.10" , "10.0.0.11" ]}
486+
487+ ip = gnoi_shutdown_daemon .get_dpu_ip (mock_config , "DPU2" )
488+ self .assertEqual (ip , "10.0.0.10" ) # Should return first IP
489+
490+ def test_get_dpu_gnmi_port_found_first_try (self ):
491+ """Test get_dpu_gnmi_port when port is found on first lookup."""
492+ mock_config = MagicMock ()
493+ # Return port on first call (lowercase)
494+ mock_config .get_entry .return_value = {"gnmi_port" : "9090" }
495+
496+ port = gnoi_shutdown_daemon .get_dpu_gnmi_port (mock_config , "DPU3" )
497+ self .assertEqual (port , "9090" )
498+ # Should only call once if found on first try
499+ self .assertEqual (mock_config .get_entry .call_count , 1 )
500+
501+ def test_poll_reboot_status_success (self ):
502+ """Test _poll_reboot_status when reboot completes successfully."""
503+ with patch ('gnoi_shutdown_daemon.execute_gnoi_command' ) as mock_execute :
504+ with patch ('gnoi_shutdown_daemon.time.monotonic' , side_effect = [0 , 1 ]):
505+ with patch ('gnoi_shutdown_daemon.time.sleep' ):
506+ # Return "Reboot Complete" message
507+ mock_execute .return_value = (0 , "System Reboot Complete" , "" )
508+
509+ handler = gnoi_shutdown_daemon .GnoiRebootHandler (MagicMock (), MagicMock (), MagicMock ())
510+ result = handler ._poll_reboot_status ("DPU0" , "10.0.0.1" , "8080" )
511+
512+ self .assertTrue (result )
513+
472514if __name__ == '__main__' :
473515 unittest .main ()
0 commit comments