Skip to content

Commit

Permalink
Cleanup config file as well
Browse files Browse the repository at this point in the history
  • Loading branch information
TorecLuik committed Apr 4, 2024
1 parent 756ea35 commit 8780a0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 8 additions & 1 deletion biomero/slurm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,21 @@ def cleanup_tmp_files(self,
clog = clog.format(slurm_job_id=slurm_job_id)
rmclog = f"rm {clog}"
cmds.append(rmclog)

# data
if data_location is None:
data_location = self.extract_data_location_from_log(logfile)
rmdata = f"rm -rf {data_location} {data_location}.*"
cmds.append(rmdata)

# convert config file
config_file = f"config_{os.path.basename(data_location)}.txt"
rmconfig = f"rm {config_file}"
cmds.append(rmconfig)

try:
result = self.run_commands(cmds)
# do as much as possible, not conditional removal
result = self.run_commands(cmds, sep=' ; ')
except UnexpectedExit as e:
logger.warning(e)
result = e.result
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/test_slurm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ def test_cleanup_tmp_files_loc(mock_extract_data_location, mock_run_commands,
data_location = "/path"
logfile = "/path/to/logfile"

mock_extract_data_location.return_value = data_location
mock_run_commands.return_value = mock.MagicMock(ok=True)

# WHEN
Expand All @@ -857,8 +856,9 @@ def test_cleanup_tmp_files_loc(mock_extract_data_location, mock_run_commands,
f"rm {filename}.*",
f"rm {logfile}",
f"rm slurm-{slurm_job_id}_*.out",
f"rm -rf {data_location} {data_location}.*"
])
f"rm -rf {data_location} {data_location}.*",
f"rm config_path.txt"
], sep=' ; ')

assert result.ok is True

Expand All @@ -875,8 +875,9 @@ def test_cleanup_tmp_files(mock_extract_data_location, mock_run_commands,
filename = "output.zip"
data_location = None
logfile = "/path/to/logfile"
found_location = '/path'

mock_extract_data_location.return_value = data_location
mock_extract_data_location.return_value = found_location
mock_run_commands.return_value = mock.MagicMock(ok=True)

# WHEN
Expand All @@ -889,8 +890,9 @@ def test_cleanup_tmp_files(mock_extract_data_location, mock_run_commands,
f"rm {filename}.*",
f"rm {logfile}",
f"rm slurm-{slurm_job_id}_*.out",
f"rm -rf {data_location} {data_location}.*"
])
f"rm -rf {found_location} {found_location}.*",
f"rm config_path.txt"
], sep=' ; ')

assert result.ok is True

Expand Down

0 comments on commit 8780a0b

Please sign in to comment.