Skip to content

Commit

Permalink
Fix some issues from the merge
Browse files Browse the repository at this point in the history
  • Loading branch information
plars committed Jul 12, 2024
1 parent b074c27 commit 371a33b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions agent/testflinger_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ def process_jobs(self):
self.set_agent_state(phase)

event_emitter.emit_event(TestEvent(phase + "_start"))
exitcode, exit_event, exit_reason = job.run_test_phase(
exit_code, exit_event, exit_reason = job.run_test_phase(
phase, rundir
)
self.client.post_influx(phase, exitcode)
self.client.post_influx(phase, exit_code)
event_emitter.emit_event(exit_event, exit_reason)

if exitcode:
if exit_code:
# exit code 46 is our indication that recovery failed!
# In this case, we need to mark the device offline
if exitcode == 46:
if exit_code == 46:
self.mark_device_offline()
exit_event = TestEvent.RECOVERY_FAIL
else:
Expand Down
4 changes: 3 additions & 1 deletion agent/testflinger_agent/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def run_test_phase(self, phase, rundir):
):
runner.run(f"echo '{line}'")
try:
# Set exit_event to fail for this phase in case of an exception
exit_event = f"{phase}_fail"
exitcode, exit_event, exit_reason = runner.run(cmd)
except Exception as e:
except Exception as exc:
logger.exception(exc)
exitcode = 100
exit_reason = str(exc) # noqa: F841 - ignore this until it's used
Expand Down
16 changes: 11 additions & 5 deletions agent/testflinger_agent/tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile

import requests_mock as rmock
from unittest.mock import patch, Mock
from unittest.mock import patch

import testflinger_agent
from testflinger_agent.client import TestflingerClient as _TestflingerClient
Expand Down Expand Up @@ -161,11 +161,17 @@ def test_run_test_phase_with_run_exception(
requests_mock.post(rmock.ANY, status_code=200)
job = _TestflingerJob({}, client)
job.phase = "setup"
mock_runner = Mock()
mock_runner.run.side_effect = Exception("failed")
with patch("testflinger_agent.job.CommandRunner", mock_runner):
exit_code = job.run_test_phase("setup", tmp_path)
# Don't raise the exception on the 3 banner lines
with patch(
"testflinger_agent.job.CommandRunner.run",
side_effect=[None, None, None, Exception("failed")],
):
exit_code, exit_event, exit_reason = job.run_test_phase(
"setup", tmp_path
)
assert exit_code == 100
assert exit_event == "setup_fail"
assert exit_reason == "failed"

def test_set_truncate(self, client):
"""Test the _set_truncate method of TestflingerJob"""
Expand Down

0 comments on commit 371a33b

Please sign in to comment.