Allow PID file path to be relative when daemonize a process (scheduler, kerberos, etc) (#13232)

Closes #13200.

Currently, if the PID file path provided is relative,
the process silently fails to launch.

This fix ensures the PID path specified to be
a normalized absolutized path eventually (expand with cwd),
no matter the given value is relative or absolute.

(cherry picked from commit 93e4787b70)
This commit is contained in:
Xiaodong DENG 2020-12-22 23:18:38 +01:00 коммит произвёл Kaxil Naik
Родитель 05e1bd9c43
Коммит b73dd6b0b5
2 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -227,8 +227,11 @@ def setup_locations(process, pid=None, stdout=None, stderr=None, log=None):
stdout = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.out')
if not log:
log = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.log')
if not pid:
pid = os.path.join(settings.AIRFLOW_HOME, f'airflow-{process}.pid')
else:
pid = os.path.abspath(pid)
return pid, stdout, stderr, log

Просмотреть файл

@ -131,6 +131,23 @@ class TestCliUtil(unittest.TestCase):
command = json.loads(command.replace("'", '"'))
self.assertEqual(command, expected_command)
def test_setup_locations_relative_pid_path(self):
relative_pid_path = "fake.pid"
pid_full_path = os.path.join(os.getcwd(), relative_pid_path)
pid, _, _, _ = cli.setup_locations(process="fake_process", pid=relative_pid_path)
self.assertEqual(pid, pid_full_path)
def test_setup_locations_absolute_pid_path(self):
abs_pid_path = os.path.join(os.getcwd(), "fake.pid")
pid, _, _, _ = cli.setup_locations(process="fake_process", pid=abs_pid_path)
self.assertEqual(pid, abs_pid_path)
def test_setup_locations_none_pid_path(self):
process_name = "fake_process"
default_pid_path = os.path.join(settings.AIRFLOW_HOME, f"airflow-{process_name}.pid")
pid, _, _, _ = cli.setup_locations(process=process_name)
self.assertEqual(pid, default_pid_path)
@contextmanager
def fail_action_logger_callback():