Skip to content

Commit

Permalink
[cli/oarsub] better error when AR fail
Browse files Browse the repository at this point in the history
  • Loading branch information
adfaure committed Nov 28, 2023
1 parent 1e4674b commit edf1459
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 1 addition & 3 deletions etc/oar/admission_rules.d/02_prevent_root_oar_toSubmit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Prevent root and oar to submit jobs.
if (user == "root") or (user == "oar"):
raise Exception(
"# ADMISSION RULE> root and oar users are not allowed to submit jobs."
)
raise Exception("root and oar users are not allowed to submit jobs.")
2 changes: 1 addition & 1 deletion etc/oar/admission_rules.d/04_submit_in_admin_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

if user not in grp.getgrnam(admin_group).gr_mem:
raise Exception(
"# ADMISSION RULE> Only member of the group {} can submit jobs in the admin queue".format(
"Only member of the group {} can submit jobs in the admin queue".format(
admin_group
)
)
6 changes: 5 additions & 1 deletion oar/cli/oarsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,11 @@ def qdel(signalnum, frame): # pragma: no cover
# Launch the checked submission
(error, job_id_lst) = submission.submit(session, config)

if error[0] != 0:
# Admission rule failed
if error[0] == -2:
cmd_ret.print_(f"# ADMISSION RULE> {error[1]}")
cmd_ret.exit(1)
elif error[0] != 0:
cmd_ret.error("unamed error", 0, error) # TODO
cmd_ret.exit()

Expand Down
5 changes: 3 additions & 2 deletions oar/lib/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,9 @@ def add_micheline_jobs(
if ("ADMISSION_RULES_IN_FILES" in config) and (
config["ADMISSION_RULES_IN_FILES"] == "yes"
):

# Read admission_rules from files
rules_dir = "/etc/oar/admission_rules.d/"
rules_dir = config.get("ADMISSION_RULES_PATH", "/etc/oar/admission_rules.d/")
file_names = os.listdir(rules_dir)

file_names.sort()
Expand Down Expand Up @@ -1114,7 +1115,7 @@ def add_micheline_jobs(
err = sys.exc_info()
error = (
-2,
str(err[1]) + ", a failed admission rule prevented submitting the job.",
f"A failed admission rule prevented submitting the job: {err[1]}.",
)
return (error, [])

Expand Down
23 changes: 21 additions & 2 deletions tests/cli/test_oarsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,32 @@ def test_oarsub_reservation_granted(
["--reservation", "1970-01-01 01:20:00"],
obj=(minimal_db_initialization, config),
)
print(result.output)
print(result.output.split("\n")[3])
print(f"{result.output} \n fin")

assert re.match(r".*GRANTED.*", result.output.split("\n")[3])
assert result.exit_code == 0


def test_oarsub_fail_ar(monkeypatch, minimal_db_initialization, setup_config):
config, _, _ = setup_config
AdmissionRule.create(
minimal_db_initialization,
rule="""raise Exception(
"try again"
)""",
)
runner = CliRunner()
result = runner.invoke(
cli,
["-q default", '"sleep 1"'],
obj=(minimal_db_initialization, config),
catch_exceptions=False,
)

print(result.output)
assert result.exit_code == 1


def test_oarsub_array_index(monkeypatch, minimal_db_initialization, setup_config):
config, _, _ = setup_config
runner = CliRunner()
Expand Down

0 comments on commit edf1459

Please sign in to comment.