@@ -84,3 +84,57 @@ def test_service_stop_empty(self, MockInit, MockBusName, MockSystemBus):
8484 ret , msg = systemd_service_stub .stop_service (service )
8585 assert ret == 1
8686 assert "stop_service called with no service specified" in msg
87+
88+ @mock .patch ("dbus.SystemBus" )
89+ @mock .patch ("dbus.service.BusName" )
90+ @mock .patch ("dbus.service.Object.__init__" )
91+ def test_execute_reboot_cold (self , MockInit , MockBusName , MockSystemBus ):
92+ # Mock subprocess.run
93+ with mock .patch ("subprocess.run" ) as mock_run :
94+ # Mock the result of subprocess.run
95+ res_mock = mock .Mock ()
96+ test_ret = 0
97+ test_msg = b"Succeeded"
98+ res_mock .configure_mock (returncode = test_ret , stderr = test_msg )
99+ mock_run .return_value = res_mock
100+
101+ method = systemd_service .RebootMethod .COLD
102+ systemd_service_stub = systemd_service .SystemdService (systemd_service .MOD_NAME )
103+
104+ # Execute the reboot method
105+ ret , msg = systemd_service_stub .execute_reboot (method )
106+
107+ # Assert the correct command was called
108+ call_args = mock_run .call_args [0 ][0 ]
109+ assert "/usr/local/bin/reboot" in call_args , f"Expected 'reboot' command, but got: { call_args } "
110+
111+ # Assert the return values are correct
112+ assert ret == test_ret , f"Expected return code { test_ret } , got { ret } "
113+ assert msg == "" , f"Expected return message '', got { msg } "
114+
115+ @mock .patch ("dbus.SystemBus" )
116+ @mock .patch ("dbus.service.BusName" )
117+ @mock .patch ("dbus.service.Object.__init__" )
118+ def test_execute_reboot_halt (self , MockInit , MockBusName , MockSystemBus ):
119+ # Mock subprocess.run
120+ with mock .patch ("subprocess.run" ) as mock_run :
121+ # Mock the result of subprocess.run
122+ res_mock = mock .Mock ()
123+ test_ret = 0
124+ test_msg = b"Succeeded"
125+ res_mock .configure_mock (returncode = test_ret , stderr = test_msg )
126+ mock_run .return_value = res_mock
127+
128+ method = systemd_service .RebootMethod .HALT
129+ systemd_service_stub = systemd_service .SystemdService (systemd_service .MOD_NAME )
130+
131+ # Execute the reboot method
132+ ret , msg = systemd_service_stub .execute_reboot (method )
133+
134+ # Assert the correct command was called
135+ call_args = mock_run .call_args [0 ][0 ]
136+ assert "/usr/local/bin/reboot" in call_args , f"Expected 'reboot' command, but got: { call_args } "
137+
138+ # Assert the return values are correct
139+ assert ret == test_ret , f"Expected return code { test_ret } , got { ret } "
140+ assert msg == "" , f"Expected return message '', got { msg } "
0 commit comments