axelray-dev commented on code in PR #69834:
URL: https://github.com/apache/airflow/pull/69834#discussion_r3622545124
##########
providers/ssh/src/airflow/providers/ssh/operators/ssh_remote_job.py:
##########
@@ -451,10 +451,11 @@ def _cleanup_remote_job(self, job_dir: str, remote_os:
str) -> None:
leave the directory rather than failing the (already finished) task.
"""
self.log.info("Cleaning up remote job directory: %s", job_dir)
+ expected_base = self._paths.base_dir if self._paths else
self.remote_base_dir
Review Comment:
Addressed on the current head.
Added `test_execute_complete_with_cleanup_custom_remote_base_dir` so the
operator wiring for a custom `remote_base_dir` is covered through
`execute_complete`, not only the utils builders.
##########
providers/ssh/src/airflow/providers/ssh/operators/ssh_remote_job.py:
##########
@@ -451,10 +451,11 @@ def _cleanup_remote_job(self, job_dir: str, remote_os:
str) -> None:
leave the directory rather than failing the (already finished) task.
"""
self.log.info("Cleaning up remote job directory: %s", job_dir)
+ expected_base = self._paths.base_dir if self._paths else
self.remote_base_dir
if remote_os == "posix":
- cleanup_cmd = build_posix_cleanup_command(job_dir)
+ cleanup_cmd = build_posix_cleanup_command(job_dir,
expected_base=expected_base)
Review Comment:
Addressed on the current head.
`_cleanup_remote_job` now catches `ValueError` from cleanup validation, logs
a warning, and leaves the remote directory in place instead of failing an
already-finished task. Covered by
`test_cleanup_validation_failure_leaves_directory_without_raising`.
##########
providers/ssh/src/airflow/providers/ssh/utils/remote_job.py:
##########
@@ -452,27 +459,29 @@ def build_windows_kill_command(pid_file: str) -> str:
return f"powershell.exe -NoProfile -NonInteractive -EncodedCommand
{encoded_script}"
-def build_posix_cleanup_command(job_dir: str) -> str:
+def build_posix_cleanup_command(job_dir: str, expected_base: str | None =
None) -> str:
"""
Build a POSIX command to clean up the job directory.
:param job_dir: Path to the job directory
+ :param expected_base: Expected base directory for the job
:return: Shell command to remove the directory
:raises ValueError: If job_dir is not under the expected base directory
"""
- _validate_job_dir(job_dir, "posix")
+ _validate_job_dir(job_dir, "posix", expected_base)
Review Comment:
Agreed. Kept the cleanup-path validation.
`job_dir` still comes from the trigger event at cleanup time, so the prefix
check remains the guard before `rm -rf`.
##########
providers/ssh/src/airflow/providers/ssh/utils/remote_job.py:
##########
@@ -30,18 +30,25 @@
WINDOWS_DEFAULT_BASE_DIR = "$env:TEMP\\airflow-ssh-jobs"
-def _validate_job_dir(job_dir: str, remote_os: Literal["posix", "windows"]) ->
None:
+def _validate_job_dir(
+ job_dir: str,
+ remote_os: Literal["posix", "windows"],
+ expected_base: str | None = None,
+) -> None:
"""
Validate that job_dir is under the expected base directory.
:param job_dir: The job directory path to validate
:param remote_os: Operating system type
+ :param expected_base: Expected base directory for the job
:raises ValueError: If job_dir doesn't start with the expected base path
"""
if remote_os == "posix":
- expected_prefix = POSIX_DEFAULT_BASE_DIR + "/"
+ expected_base = expected_base or POSIX_DEFAULT_BASE_DIR
Review Comment:
Addressed on the current head.
Validation now uses `expected_base is None` so empty/falsy values stay
consistent with `RemoteJobPaths.__post_init__`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]