Skip to content

Commit 2f53525

Browse files
authored
run api as group, clean up file transfer (#88)
1 parent a0713a8 commit 2f53525

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

Charts/web-conexs/templates/api_deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ spec:
1515
spec:
1616
securityContext:
1717
runAsUser: 1000
18+
supplementalGroups:
19+
- {{.Values.security.securityContext.runAsGroup}}
1820
volumes:
1921
- name: data-pv-volume
2022
persistentVolumeClaim:

web-conexs-api/src/slurm_submission_service/filetransfer.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
import os
44
import shutil
5-
import tempfile
65
from pathlib import Path
76

87
logger = logging.getLogger(__name__)
@@ -13,11 +12,6 @@ def check_filesystem(path):
1312
Path(path).stat()
1413

1514

16-
def make_directory(path):
17-
logger.info(f"Attempting to make directory {path}")
18-
Path(path).mkdir(parents=True)
19-
20-
2115
def copy_directory(source, destination):
2216
logger.info(f"Attempting to make copy {source} to {destination}")
2317

@@ -35,14 +29,19 @@ def copy_multiple_files(abs_paths: list[str], destination):
3529
shutil.copy(p, destination)
3630

3731

38-
def transfer_inputs(file_map: dict[str, str], final_dir):
39-
with tempfile.TemporaryDirectory() as tmpdirname:
40-
for k, v in file_map.items():
41-
input_file = tmpdirname + "/" + k
42-
with open(input_file, "w+") as f:
43-
f.write(v)
32+
def transfer_inputs(file_map: dict[str, str], destination):
33+
dest = Path(destination)
34+
parent = dest.parent
4435

45-
return copy_directory(tmpdirname, final_dir)
36+
if not parent.exists:
37+
parent.mkdir()
38+
39+
dest.mkdir()
40+
41+
for k, v in file_map.items():
42+
input_file = dest / k
43+
with open(input_file, "w+") as f:
44+
f.write(v)
4645

4746

4847
def transfer_results(simulation_type_id, result_dir, storage_dir):
@@ -72,17 +71,16 @@ def transfer_results(simulation_type_id, result_dir, storage_dir):
7271
parent = store_path.parent
7372

7473
if not parent.exists:
75-
parent.mkdir(mode=0o755)
74+
parent.mkdir()
7675

7776
if not store_path.exists:
78-
store_path.mkdir(mode=0o755)
77+
store_path.mkdir()
7978

8079
shutil.copytree(
8180
result_dir,
8281
storage_dir,
8382
ignore=ignore_pattern,
8483
dirs_exist_ok=True,
85-
copy_function=shutil.copyfile,
8684
)
8785

8886

web-conexs-api/src/slurm_submission_service/submitter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def run_update():
4646

4747

4848
def main():
49+
os.umask(0o007)
50+
4951
rootlogger = logging.getLogger()
5052
formatter = logging.Formatter(
5153
"%(asctime)s - %(levelname)s - %(name)s - %(message)s",

web-conexs-api/tests/test_filetransfer.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import os
12
from pathlib import Path
23

34
from slurm_submission_service.filetransfer import (
45
check_filesystem,
56
clean_up,
67
copy_directory,
78
copy_multiple_files,
8-
make_directory,
99
transfer_inputs,
1010
transfer_results,
1111
)
@@ -18,13 +18,6 @@ def test_check_filesystem(tmp_path: Path):
1818
assert True
1919

2020

21-
def test_make_directory(tmp_path: Path):
22-
d = tmp_path / "test_dir"
23-
assert not d.exists()
24-
make_directory(str(d))
25-
assert d.exists()
26-
27-
2821
def test_copy_dir_file(tmp_path: Path):
2922
job_text = "job"
3023
filename = "job.inp"
@@ -48,6 +41,7 @@ def test_copy_dir_file(tmp_path: Path):
4841

4942

5043
def test_transfer_inputs(tmp_path: Path):
44+
os.umask(0o007)
5145
job_text = "job"
5246
filename = "job.inp"
5347
file_map = {}
@@ -58,28 +52,39 @@ def test_transfer_inputs(tmp_path: Path):
5852

5953
output = d / filename
6054

55+
mode = oct(os.stat(d).st_mode)
56+
57+
assert mode[-3:] == "770"
58+
6159
assert output.exists()
6260

6361
assert output.read_text() == job_text
6462

6563

6664
def test_transfer_results(tmp_path: Path):
65+
os.umask(0o007)
6766
job_text = "job"
6867
filename = "job.inp"
6968
bad_file = "test.gbw"
7069
s = tmp_path / "source"
7170
s.mkdir()
71+
os.chmod(s, 0o770)
72+
7273
p = s / filename
7374
p.write_text("job")
7475

7576
b = s / bad_file
7677
b.touch()
7778

7879
orca = tmp_path / "orca"
79-
orca.mkdir()
8080

8181
transfer_results(1, str(s), str(orca))
8282

83+
print(oct(os.stat(orca).st_mode))
84+
85+
mode = oct(os.stat(orca).st_mode)
86+
87+
assert mode[-3:] == "770"
8388
print([str(x) for x in s.iterdir()])
8489
print([str(x) for x in orca.iterdir()])
8590

0 commit comments

Comments
 (0)