Skip to content

Commit a014e78

Browse files
committed
provide more descriptive message on multiple jobs found
1 parent 7cb3b5e commit a014e78

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

ceph_devstack/resources/ceph/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,11 @@ async def logs(
236236
log_file = self.get_log_file(run_name, job_id)
237237
except FileNotFoundError:
238238
logger.error("No log file found")
239-
except TooManyJobsFound:
240-
logger.error(
241-
"Found too many jobs for target run. Please pick a job id with -j flag."
239+
except TooManyJobsFound as e:
240+
msg = "Found too many jobs: {jobs} for target run. Please pick a job id with -j flag.".format(
241+
jobs=", ".join(e.jobs)
242242
)
243+
logger.error(msg)
243244
else:
244245
if locate:
245246
print(log_file)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class TooManyJobsFound(Exception):
2-
pass
2+
def __init__(self, jobs: list[str]):
3+
self.jobs = jobs

ceph_devstack/resources/ceph/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def get_job_id(jobs: list[str]):
4040
if len(dirs) == 0:
4141
raise FileNotFoundError
4242
elif len(dirs) > 1:
43-
raise TooManyJobsFound
43+
raise TooManyJobsFound(dirs)
4444
return dirs[0]

ceph_devstack/resources/test/test_devstack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def test_get_job_id_throws_filenotfound_on_missing_job(self):
4747

4848
def test_get_job_id_throws_toomanyjobsfound_on_more_than_one_job(self):
4949
jobs = ["1", "2"]
50-
with pytest.raises(TooManyJobsFound):
50+
with pytest.raises(TooManyJobsFound) as exc:
5151
get_job_id(jobs)
52+
assert exc.value.dirs == jobs
5253

5354
async def test_logs_command_display_log_file_of_latest_run(self):
5455
with tempfile.TemporaryDirectory() as data_dir:

0 commit comments

Comments
 (0)