Skip to content

Commit 34ff60a

Browse files
committed
Add tests for a594266
1 parent a594266 commit 34ff60a

File tree

6 files changed

+129
-11
lines changed

6 files changed

+129
-11
lines changed

CHANGES.rst

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
``syslog`` was supplied, as is supported by all other log filename
1515
options. Patch by Franck Cuny.
1616

17+
- Fixed a bug where environment variables defined in ``environment=``
18+
in the ``[supervisord]`` section or a ``[program:x]`` section could
19+
not be used in ``%(ENV_x)s`` expansions. Patch by MythRen.
20+
1721
- The ``supervisorctl signal`` command now allows a signal to be sent
1822
when a process is in the ``STOPPING`` state. Patch by Mike Gould.
1923

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[supervisord]
2+
nodaemon=true ; start in foreground if true; default false
3+
loglevel=debug ; log level; default info; others: debug,warn,trace
4+
logfile=/tmp/issue-1170a.log ; main log file; default $CWD/supervisord.log
5+
pidfile=/tmp/issue-1170a.pid ; supervisord pidfile; default supervisord.pid
6+
environment=FOO="set from [supervisord] section"
7+
8+
[program:echo]
9+
command=bash -c "echo '%(ENV_FOO)s'"
10+
startsecs=0
11+
startretries=0
12+
autorestart=false
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[supervisord]
2+
nodaemon=true ; start in foreground if true; default false
3+
loglevel=debug ; log level; default info; others: debug,warn,trace
4+
logfile=/tmp/issue-1170b.log ; main log file; default $CWD/supervisord.log
5+
pidfile=/tmp/issue-1170b.pid ; supervisord pidfile; default supervisord.pid
6+
environment=FOO="set from [supervisord] section"
7+
8+
[program:echo]
9+
command=bash -c "echo '%(ENV_FOO)s'"
10+
environment=FOO="set from [program] section"
11+
startsecs=0
12+
startretries=0
13+
autorestart=false
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[supervisord]
2+
nodaemon=true ; start in foreground if true; default false
3+
loglevel=debug ; log level; default info; others: debug,warn,trace
4+
logfile=/tmp/issue-1170c.log ; main log file; default $CWD/supervisord.log
5+
pidfile=/tmp/issue-1170c.pid ; supervisord pidfile; default supervisord.pid
6+
environment=FOO="set from [supervisord] section"
7+
8+
[eventlistener:echo]
9+
command=bash -c "echo '%(ENV_FOO)s' >&2"
10+
environment=FOO="set from [eventlistener] section"
11+
events=PROCESS_STATE_FATAL
12+
startsecs=0
13+
startretries=0
14+
autorestart=false

supervisor/tests/test_end_to_end.py

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_issue_550(self):
2626
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
2727
self.addCleanup(supervisord.kill, signal.SIGINT)
2828
supervisord.expect_exact('success: print_env entered RUNNING state')
29+
supervisord.expect_exact('exited: print_env (exit status 0; expected)')
2930

3031
args = ['-m', 'supervisor.supervisorctl', '-c', filename, 'tail -100000', 'print_env']
3132
supervisorctl = pexpect.spawn(sys.executable, args, encoding='utf-8')
@@ -142,6 +143,27 @@ def test_issue_1054(self):
142143
seen = False
143144
self.assertTrue(seen)
144145

146+
def test_issue_1170a(self):
147+
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170a.conf')
148+
args = ['-m', 'supervisor.supervisord', '-c', filename]
149+
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
150+
self.addCleanup(supervisord.kill, signal.SIGINT)
151+
supervisord.expect_exact("set from [supervisord] section")
152+
153+
def test_issue_1170b(self):
154+
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170b.conf')
155+
args = ['-m', 'supervisor.supervisord', '-c', filename]
156+
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
157+
self.addCleanup(supervisord.kill, signal.SIGINT)
158+
supervisord.expect_exact("set from [program] section")
159+
160+
def test_issue_1170c(self):
161+
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170c.conf')
162+
args = ['-m', 'supervisor.supervisord', '-c', filename]
163+
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
164+
self.addCleanup(supervisord.kill, signal.SIGINT)
165+
supervisord.expect_exact("set from [eventlistener] section")
166+
145167
def test_issue_1224(self):
146168
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1224.conf')
147169
args = ['-m', 'supervisor.supervisord', '-c', filename]

supervisor/tests/test_options.py

+64-11
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ def test_options_parses_as_nonstrict_for_py2_py3_compat(self):
341341
# should not raise configparser.DuplicateSectionError on py3
342342

343343
def test_options_with_environment_expansions(self):
344-
s = lstrip("""[supervisorctl]
344+
s = lstrip("""
345+
[supervisorctl]
345346
serverurl=http://localhost:%(ENV_SERVER_PORT)s
346347
username=%(ENV_CLIENT_USER)s
347348
password=%(ENV_CLIENT_PASS)s
@@ -454,11 +455,7 @@ def test_version(self):
454455
self.assertEqual(options.stdout.getvalue(), VERSION + '\n')
455456

456457
def test_options(self):
457-
s = lstrip("""[inet_http_server]
458-
port=127.0.0.1:8999
459-
username=chrism
460-
password=foo
461-
458+
s = lstrip("""
462459
[supervisord]
463460
directory=%(tempdir)s
464461
backofflimit=10
@@ -478,6 +475,11 @@ def test_options(self):
478475
minprocs=300
479476
environment=FAKE_ENV_VAR=/some/path
480477
478+
[inet_http_server]
479+
port=127.0.0.1:8999
480+
username=chrism
481+
password=foo
482+
481483
[program:cat1]
482484
command=/bin/cat
483485
priority=1
@@ -1844,11 +1846,6 @@ def test_processes_from_section_redirect_stderr_with_auto(self):
18441846

18451847
def test_options_with_environment_expansions(self):
18461848
text = lstrip("""\
1847-
[inet_http_server]
1848-
port=*:%(ENV_HTSRV_PORT)s
1849-
username=%(ENV_HTSRV_USER)s
1850-
password=%(ENV_HTSRV_PASS)s
1851-
18521849
[supervisord]
18531850
logfile = %(ENV_HOME)s/supervisord.log
18541851
logfile_maxbytes = %(ENV_SUPD_LOGFILE_MAXBYTES)s
@@ -1864,6 +1861,11 @@ def test_options_with_environment_expansions(self):
18641861
strip_ansi = %(ENV_SUPD_STRIP_ANSI)s
18651862
environment = FAKE_ENV_VAR=/some/path
18661863
1864+
[inet_http_server]
1865+
port=*:%(ENV_HTSRV_PORT)s
1866+
username=%(ENV_HTSRV_USER)s
1867+
password=%(ENV_HTSRV_PASS)s
1868+
18671869
[program:cat1]
18681870
command=%(ENV_CAT1_COMMAND)s --logdir=%(ENV_CAT1_COMMAND_LOGDIR)s
18691871
priority=%(ENV_CAT1_PRIORITY)s
@@ -1996,6 +1998,57 @@ def test_options_supervisord_section_expands_here(self):
19961998
self.assertEqual(instance.pidfile,
19971999
os.path.join(here, 'supervisord.pid'))
19982000

2001+
def test_options_program_section_expands_env_from_supervisord_sect(self):
2002+
instance = self._makeOne()
2003+
text = lstrip('''
2004+
[supervisord]
2005+
environment=CMD=/bin/from/supervisord/section
2006+
2007+
[program:cmd]
2008+
command=%(ENV_CMD)s
2009+
''')
2010+
here = tempfile.mkdtemp()
2011+
supervisord_conf = os.path.join(here, 'supervisord.conf')
2012+
with open(supervisord_conf, 'w') as f:
2013+
f.write(text)
2014+
try:
2015+
instance.configfile = supervisord_conf
2016+
instance.realize(args=[])
2017+
finally:
2018+
shutil.rmtree(here, ignore_errors=True)
2019+
options = instance.configroot.supervisord
2020+
group = options.process_group_configs[0]
2021+
self.assertEqual(group.name, 'cmd')
2022+
proc = group.process_configs[0]
2023+
self.assertEqual(proc.command,
2024+
os.path.join(here, '/bin/from/supervisord/section'))
2025+
2026+
def test_options_program_section_expands_env_from_program_sect(self):
2027+
instance = self._makeOne()
2028+
text = lstrip('''
2029+
[supervisord]
2030+
environment=CMD=/bin/from/supervisord/section
2031+
2032+
[program:cmd]
2033+
command=%(ENV_CMD)s
2034+
environment=CMD=/bin/from/program/section
2035+
''')
2036+
here = tempfile.mkdtemp()
2037+
supervisord_conf = os.path.join(here, 'supervisord.conf')
2038+
with open(supervisord_conf, 'w') as f:
2039+
f.write(text)
2040+
try:
2041+
instance.configfile = supervisord_conf
2042+
instance.realize(args=[])
2043+
finally:
2044+
shutil.rmtree(here, ignore_errors=True)
2045+
options = instance.configroot.supervisord
2046+
group = options.process_group_configs[0]
2047+
self.assertEqual(group.name, 'cmd')
2048+
proc = group.process_configs[0]
2049+
self.assertEqual(proc.command,
2050+
os.path.join(here, '/bin/from/program/section'))
2051+
19992052
def test_options_program_section_expands_here(self):
20002053
instance = self._makeOne()
20012054
text = lstrip('''

0 commit comments

Comments
 (0)