Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(agent): make sure phase exit codes are in the 0-255 range #385

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions agent/testflinger_agent/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def run_test_phase(self, phase, rundir):
# 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)
# make sure the exit code is within the expected 0-255 range
# (this also handles negative numbers)
exitcode = exitcode % 256
except Exception as exc:
logger.exception(exc)
exitcode = 100
Expand Down
26 changes: 26 additions & 0 deletions agent/testflinger_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,32 @@ def test_phase_failed(self, agent, requests_mock):
assert outcome_data.get("provision_status") == 1
assert outcome_data.get("test_status") is None

def test_phase_timeout(self, agent, requests_mock):
# Make sure the status code of a timed-out phase is correct
self.config["test_command"] = "sleep 12"
mock_job_data = {
"job_id": str(uuid.uuid1()),
"job_queue": "test",
"output_timeout": 1,
"test_data": {"test_cmds": "foo"},
}
requests_mock.get(
rmock.ANY, [{"text": json.dumps(mock_job_data)}, {"text": "{}"}]
)
requests_mock.post(rmock.ANY, status_code=200)
with patch("shutil.rmtree"), patch("os.unlink"):
agent.process_jobs()
outcome_file = os.path.join(
os.path.join(
self.tmpdir,
mock_job_data.get("job_id"),
"testflinger-outcome.json",
)
)
with open(outcome_file) as f:
outcome_data = json.load(f)
assert outcome_data.get("test_status") == 247

def test_retry_transmit(self, agent, requests_mock):
# Make sure we retry sending test results
self.config["provision_command"] = "/bin/false"
Expand Down