@@ -154,6 +154,23 @@ def test_reserve_409_returns_json(self, mock_post):
154154
155155
156156class TestDeployer (unittest .TestCase ):
157+ def test_grab_hw_worker_journal (self ):
158+ """Verify journal is fetched and saved to results dir."""
159+ from lib .deployer import grab_hw_worker_journal
160+
161+ with tempfile .TemporaryDirectory () as tmpdir :
162+ with mock .patch ('lib.deployer._ssh' ,
163+ return_value = 'Mar 14 hw-worker[1]: test log\n ' ) as mock_ssh :
164+ grab_hw_worker_journal ('10.0.0.1' , tmpdir )
165+
166+ mock_ssh .assert_called_once ()
167+ self .assertIn ('journalctl' , mock_ssh .call_args [0 ][1 ])
168+ self .assertIn ('-n 250' , mock_ssh .call_args [0 ][1 ])
169+ journal_file = os .path .join (tmpdir , 'hw-worker-journal' )
170+ self .assertTrue (os .path .exists (journal_file ))
171+ with open (journal_file ) as fp :
172+ self .assertIn ('test log' , fp .read ())
173+
157174 @mock .patch ('subprocess.run' )
158175 def test_deploy_artifacts (self , mock_run ):
159176 mock_run .return_value = mock .Mock (returncode = 0 , stdout = b'' , stderr = b'' )
@@ -378,36 +395,20 @@ def ssh_retcode_side_effect(ip, cmd, timeout=30):
378395 return 1 # no results.json
379396 return 0
380397
381- ssh_call_count = {'n' : 0 }
382-
383398 def ssh_side_effect (ip , cmd , check = True , timeout = 30 ):
384- ssh_call_count ['n' ] += 1
385399 if 'systemctl show' in cmd :
386400 return 'failed\n '
387- if 'journalctl' in cmd :
388- return 'Mar 14 hw-worker[123]: some log\n '
389401 return ''
390402
391- with tempfile .TemporaryDirectory () as tmpdir :
392- with mock .patch ('lib.deployer._ssh_retcode' ,
393- side_effect = ssh_retcode_side_effect ):
394- with mock .patch ('lib.deployer._ssh' ,
395- side_effect = ssh_side_effect ) as mock_ssh :
396- result = wait_for_results (config , mc , 42 , [1 ], ['10.0.0.1' ],
397- results_path = tmpdir )
398-
399- self .assertIsInstance (result , WaitResult )
400- self .assertFalse (result .ok )
401- self .assertIn ('hw-worker exited without results' , result .error )
402-
403- # Verify journalctl output was fetched and saved
404- journal_calls = [c for c in mock_ssh .call_args_list
405- if 'journalctl' in c [0 ][1 ]]
406- self .assertEqual (len (journal_calls ), 1 )
407- journal_file = os .path .join (tmpdir , 'hw-worker-journal' )
408- self .assertTrue (os .path .exists (journal_file ))
409- with open (journal_file ) as fp :
410- self .assertIn ('some log' , fp .read ())
403+ with mock .patch ('lib.deployer._ssh_retcode' ,
404+ side_effect = ssh_retcode_side_effect ):
405+ with mock .patch ('lib.deployer._ssh' ,
406+ side_effect = ssh_side_effect ):
407+ result = wait_for_results (config , mc , 42 , [1 ], ['10.0.0.1' ])
408+
409+ self .assertIsInstance (result , WaitResult )
410+ self .assertFalse (result .ok )
411+ self .assertIn ('hw-worker exited without results' , result .error )
411412
412413 @mock .patch ('subprocess.run' )
413414 @mock .patch ('time.monotonic' )
0 commit comments