diff --git a/celery/apps/multi.py b/celery/apps/multi.py index 90c9cf0356d..baa2fa8b9e1 100644 --- a/celery/apps/multi.py +++ b/celery/apps/multi.py @@ -151,8 +151,8 @@ def _setdefaultopt(self, d, alt, value): return d[opt] except KeyError: pass - path_split = value.split("/") - dir_path = "/".join(path_split[0:-1]) + value = os.path.normpath(value) + dir_path = os.path.dirname(value) if not os.path.exists(dir_path): os.makedirs(dir_path) return d.setdefault(alt[0], value) diff --git a/t/unit/apps/test_multi.py b/t/unit/apps/test_multi.py index 1d60c7259aa..16add3c48b1 100644 --- a/t/unit/apps/test_multi.py +++ b/t/unit/apps/test_multi.py @@ -3,6 +3,7 @@ import errno import signal import sys +import os import pytest from case import Mock, call, patch, skip @@ -113,8 +114,8 @@ def assert_line_in(name, args): def _args(name, *args): return args + ( - '--pidfile=/var/run/celery/{}.pid'.format(name), - '--logfile=/var/log/celery/{}%I.log'.format(name), + '--pidfile={}.pid'.format(os.path.join(os.path.normpath('/var/run/celery/'), name)), + '--logfile={}%I.log'.format(os.path.join(os.path.normpath('/var/log/celery/'), name)), '--executable={0}'.format(sys.executable), '', ) @@ -194,10 +195,10 @@ def test_from_kwargs(self): '--executable={0}'.format(n.executable), '-O fair', '-n foo@bar.com', - '--logfile=/var/log/celery/foo%I.log', + '--logfile={}'.format(os.path.normpath('/var/log/celery/foo%I.log')), '-Q q1,q2', '--max-tasks-per-child=30', - '--pidfile=/var/run/celery/foo.pid', + '--pidfile={}'.format(os.path.normpath('/var/run/celery/foo.pid')), '', ]) @@ -275,7 +276,7 @@ def test_handle_process_exit__signalled(self): def test_logfile(self): assert self.node.logfile == self.expander.return_value - self.expander.assert_called_with('/var/log/celery/%n%I.log') + self.expander.assert_called_with(os.path.normpath('/var/log/celery/%n%I.log')) class test_Cluster: @@ -375,8 +376,8 @@ def test_getpids(self): assert sorted(node_0.argv) == sorted([ '', '--executable={0}'.format(node_0.executable), - '--logfile=/var/log/celery/foo%I.log', - '--pidfile=/var/run/celery/foo.pid', + '--logfile={}'.format(os.path.normpath('/var/log/celery/foo%I.log')), + '--pidfile={}'.format(os.path.normpath('/var/run/celery/foo.pid')), '-m celery worker --detach', '-n foo@e.com', ]) @@ -386,8 +387,8 @@ def test_getpids(self): assert sorted(node_1.argv) == sorted([ '', '--executable={0}'.format(node_1.executable), - '--logfile=/var/log/celery/bar%I.log', - '--pidfile=/var/run/celery/bar.pid', + '--logfile={}'.format(os.path.normpath('/var/log/celery/bar%I.log')), + '--pidfile={}'.format(os.path.normpath('/var/run/celery/bar.pid')), '-m celery worker --detach', '-n bar@e.com', ]) @@ -404,8 +405,8 @@ def __init__(self, path): def read_pid(self): try: - return {'/var/run/celery/foo.pid': 10, - '/var/run/celery/bar.pid': 11}[self.path] + return {os.path.normpath('/var/run/celery/foo.pid'): 10, + os.path.normpath('/var/run/celery/bar.pid'): 11}[self.path] except KeyError: raise ValueError() self.Pidfile.side_effect = pids