Skip to content

Commit 1f20e0c

Browse files
committed
[#85251] Check if required directories exist
Signed-off-by: Maciej Sobkowski <msobkowski@antmicro.com>
1 parent 3f4733f commit 1f20e0c

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

protoplaster/protoplaster.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def parse_args():
4444
type=str,
4545
default=f"{ARTIFACTS_DIR}",
4646
help="Path to the test artifacts directory")
47+
parser.add_argument(
48+
"-m",
49+
"--mkdir",
50+
action="store_true",
51+
help="Try to create test/reports/artifacts directories if missing")
4752
parser.add_argument(
4853
"-t",
4954
"--test-file",
@@ -133,6 +138,29 @@ def main():
133138
if args.sudo:
134139
os.execv(shutil.which("sudo"),
135140
[__file__] + list(filter(lambda a: a != "--sudo", sys.argv)))
141+
142+
if not os.path.exists(args.test_dir):
143+
if args.mkdir:
144+
os.makedirs(args.test_dir, exist_ok=True)
145+
else:
146+
print(error(f"Tests dir ({args.test_dir}) does not exist!"))
147+
exit(1)
148+
149+
if not os.path.exists(args.reports_dir):
150+
if args.mkdir:
151+
os.makedirs(args.reports_dir, exist_ok=True)
152+
else:
153+
print(error(f"Reports dir ({args.reports_dir}) does not exist!"))
154+
exit(1)
155+
156+
if not os.path.exists(args.artifacts_dir):
157+
if args.mkdir:
158+
os.makedirs(args.artifacts_dir, exist_ok=True)
159+
else:
160+
print(
161+
error(f"Artifacts dir ({args.artifacts_dir}) does not exist!"))
162+
exit(1)
163+
136164
if not os.path.exists(
137165
f"{args.test_dir}/{args.test_file}") and not args.server:
138166
print(

protoplaster/runner/runner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ def run_tests(args):
157157
test_modules = test_file.list_test_modules()
158158
metadata_cmds = test_file.list_metadata_commands()
159159

160-
os.makedirs(args.artifacts_dir, exist_ok=True)
161-
162160
if metadata_cmds:
163161
metadata = [
164162
result.output_file

protoplaster/runner/worker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def run_test(run, base_args):
2727
args.csv = run["id"] + ".csv"
2828
args.artifacts_dir = os.path.join(args.artifacts_dir, run["id"])
2929

30+
os.makedirs(args.artifacts_dir, exist_ok=True)
31+
32+
if not (os.path.exists(args.test_dir) or os.path.exists(args.reports_dir)
33+
or os.path.exists(args.reports_dir)):
34+
run["status"] = RunStatus.FAILED
35+
return
36+
3037
ret, metadata = run_tests(args)
3138

3239
run["metadata"] = {

0 commit comments

Comments
 (0)