Skip to content

Commit

Permalink
Merge pull request #1972 from VallariAg/fix-teuthology-kill
Browse files Browse the repository at this point in the history
teuthology/kill.py: Fix "TypeError: 'NoneType' object is not iterable"
  • Loading branch information
zmc authored Jul 9, 2024
2 parents a4a89a3 + a8f6f4b commit 0b65d05
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions teuthology/kill.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ def find_pids(run_name):
def find_targets(run_name: str, job_id: Union[str, int, None] = None) -> dict:
if job_id is not None:
job_info = report.ResultsReporter().get_jobs(run_name, str(job_id))
return job_info.get("targets", dict())
return job_info.get("targets") or dict()
result = dict()
run_info = report.ResultsReporter().get_jobs(run_name)
for job_info in run_info:
if job_info.get("status") not in ("running", "waiting"):
continue
result.update(job_info.get("targets", dict()))
result.update(job_info.get("targets") or dict())
return result
46 changes: 46 additions & 0 deletions teuthology/test/test_kill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from unittest.mock import patch

from teuthology.kill import find_targets


class TestFindTargets(object):
""" Tests for teuthology.kill.find_targets """

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_missing_run_find_targets(self, m_get_jobs):
m_get_jobs.return_value = []
run_targets = find_targets("run-name")
assert run_targets == {}

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_missing_job_find_targets(self, m_get_jobs):
m_get_jobs.return_value = {}
job_targets = find_targets("run-name", "3")
assert job_targets == {}

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_missing_run_targets_find_targets(self, m_get_jobs):
m_get_jobs.return_value = [{"targets": None, "status": "waiting"}]
run_targets = find_targets("run-name")
assert run_targets == {}

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_missing_job_targets_find_targets(self, m_get_jobs):
m_get_jobs.return_value = {"targets": None}
job_targets = find_targets("run-name", "3")
assert job_targets == {}

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_run_find_targets(self, m_get_jobs):
m_get_jobs.return_value = [{"targets": {"node1": ""}, "status": "running"}]
run_targets = find_targets("run-name")
assert run_targets == {"node1": ""}
m_get_jobs.return_value = [{"targets": {"node1": ""}}]
run_targets = find_targets("run-name")
assert run_targets == {}

@patch('teuthology.kill.report.ResultsReporter.get_jobs')
def test_job_find_targets(self, m_get_jobs):
m_get_jobs.return_value = {"targets": {"node1": ""}}
job_targets = find_targets("run-name", "3")
assert job_targets == {"node1": ""}

0 comments on commit 0b65d05

Please sign in to comment.