Skip to content

Commit

Permalink
Add tests for a594266
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaberez committed Feb 25, 2021
1 parent a594266 commit 34ff60a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
``syslog`` was supplied, as is supported by all other log filename
options. Patch by Franck Cuny.

- Fixed a bug where environment variables defined in ``environment=``
in the ``[supervisord]`` section or a ``[program:x]`` section could
not be used in ``%(ENV_x)s`` expansions. Patch by MythRen.

- The ``supervisorctl signal`` command now allows a signal to be sent
when a process is in the ``STOPPING`` state. Patch by Mike Gould.

Expand Down
12 changes: 12 additions & 0 deletions supervisor/tests/fixtures/issue-1170a.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[supervisord]
nodaemon=true ; start in foreground if true; default false
loglevel=debug ; log level; default info; others: debug,warn,trace
logfile=/tmp/issue-1170a.log ; main log file; default $CWD/supervisord.log
pidfile=/tmp/issue-1170a.pid ; supervisord pidfile; default supervisord.pid
environment=FOO="set from [supervisord] section"

[program:echo]
command=bash -c "echo '%(ENV_FOO)s'"
startsecs=0
startretries=0
autorestart=false
13 changes: 13 additions & 0 deletions supervisor/tests/fixtures/issue-1170b.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[supervisord]
nodaemon=true ; start in foreground if true; default false
loglevel=debug ; log level; default info; others: debug,warn,trace
logfile=/tmp/issue-1170b.log ; main log file; default $CWD/supervisord.log
pidfile=/tmp/issue-1170b.pid ; supervisord pidfile; default supervisord.pid
environment=FOO="set from [supervisord] section"

[program:echo]
command=bash -c "echo '%(ENV_FOO)s'"
environment=FOO="set from [program] section"
startsecs=0
startretries=0
autorestart=false
14 changes: 14 additions & 0 deletions supervisor/tests/fixtures/issue-1170c.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[supervisord]
nodaemon=true ; start in foreground if true; default false
loglevel=debug ; log level; default info; others: debug,warn,trace
logfile=/tmp/issue-1170c.log ; main log file; default $CWD/supervisord.log
pidfile=/tmp/issue-1170c.pid ; supervisord pidfile; default supervisord.pid
environment=FOO="set from [supervisord] section"

[eventlistener:echo]
command=bash -c "echo '%(ENV_FOO)s' >&2"
environment=FOO="set from [eventlistener] section"
events=PROCESS_STATE_FATAL
startsecs=0
startretries=0
autorestart=false
22 changes: 22 additions & 0 deletions supervisor/tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_issue_550(self):
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
self.addCleanup(supervisord.kill, signal.SIGINT)
supervisord.expect_exact('success: print_env entered RUNNING state')
supervisord.expect_exact('exited: print_env (exit status 0; expected)')

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

def test_issue_1170a(self):
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170a.conf')
args = ['-m', 'supervisor.supervisord', '-c', filename]
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
self.addCleanup(supervisord.kill, signal.SIGINT)
supervisord.expect_exact("set from [supervisord] section")

def test_issue_1170b(self):
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170b.conf')
args = ['-m', 'supervisor.supervisord', '-c', filename]
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
self.addCleanup(supervisord.kill, signal.SIGINT)
supervisord.expect_exact("set from [program] section")

def test_issue_1170c(self):
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1170c.conf')
args = ['-m', 'supervisor.supervisord', '-c', filename]
supervisord = pexpect.spawn(sys.executable, args, encoding='utf-8')
self.addCleanup(supervisord.kill, signal.SIGINT)
supervisord.expect_exact("set from [eventlistener] section")

def test_issue_1224(self):
filename = pkg_resources.resource_filename(__name__, 'fixtures/issue-1224.conf')
args = ['-m', 'supervisor.supervisord', '-c', filename]
Expand Down
75 changes: 64 additions & 11 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def test_options_parses_as_nonstrict_for_py2_py3_compat(self):
# should not raise configparser.DuplicateSectionError on py3

def test_options_with_environment_expansions(self):
s = lstrip("""[supervisorctl]
s = lstrip("""
[supervisorctl]
serverurl=http://localhost:%(ENV_SERVER_PORT)s
username=%(ENV_CLIENT_USER)s
password=%(ENV_CLIENT_PASS)s
Expand Down Expand Up @@ -454,11 +455,7 @@ def test_version(self):
self.assertEqual(options.stdout.getvalue(), VERSION + '\n')

def test_options(self):
s = lstrip("""[inet_http_server]
port=127.0.0.1:8999
username=chrism
password=foo
s = lstrip("""
[supervisord]
directory=%(tempdir)s
backofflimit=10
Expand All @@ -478,6 +475,11 @@ def test_options(self):
minprocs=300
environment=FAKE_ENV_VAR=/some/path
[inet_http_server]
port=127.0.0.1:8999
username=chrism
password=foo
[program:cat1]
command=/bin/cat
priority=1
Expand Down Expand Up @@ -1844,11 +1846,6 @@ def test_processes_from_section_redirect_stderr_with_auto(self):

def test_options_with_environment_expansions(self):
text = lstrip("""\
[inet_http_server]
port=*:%(ENV_HTSRV_PORT)s
username=%(ENV_HTSRV_USER)s
password=%(ENV_HTSRV_PASS)s
[supervisord]
logfile = %(ENV_HOME)s/supervisord.log
logfile_maxbytes = %(ENV_SUPD_LOGFILE_MAXBYTES)s
Expand All @@ -1864,6 +1861,11 @@ def test_options_with_environment_expansions(self):
strip_ansi = %(ENV_SUPD_STRIP_ANSI)s
environment = FAKE_ENV_VAR=/some/path
[inet_http_server]
port=*:%(ENV_HTSRV_PORT)s
username=%(ENV_HTSRV_USER)s
password=%(ENV_HTSRV_PASS)s
[program:cat1]
command=%(ENV_CAT1_COMMAND)s --logdir=%(ENV_CAT1_COMMAND_LOGDIR)s
priority=%(ENV_CAT1_PRIORITY)s
Expand Down Expand Up @@ -1996,6 +1998,57 @@ def test_options_supervisord_section_expands_here(self):
self.assertEqual(instance.pidfile,
os.path.join(here, 'supervisord.pid'))

def test_options_program_section_expands_env_from_supervisord_sect(self):
instance = self._makeOne()
text = lstrip('''
[supervisord]
environment=CMD=/bin/from/supervisord/section
[program:cmd]
command=%(ENV_CMD)s
''')
here = tempfile.mkdtemp()
supervisord_conf = os.path.join(here, 'supervisord.conf')
with open(supervisord_conf, 'w') as f:
f.write(text)
try:
instance.configfile = supervisord_conf
instance.realize(args=[])
finally:
shutil.rmtree(here, ignore_errors=True)
options = instance.configroot.supervisord
group = options.process_group_configs[0]
self.assertEqual(group.name, 'cmd')
proc = group.process_configs[0]
self.assertEqual(proc.command,
os.path.join(here, '/bin/from/supervisord/section'))

def test_options_program_section_expands_env_from_program_sect(self):
instance = self._makeOne()
text = lstrip('''
[supervisord]
environment=CMD=/bin/from/supervisord/section
[program:cmd]
command=%(ENV_CMD)s
environment=CMD=/bin/from/program/section
''')
here = tempfile.mkdtemp()
supervisord_conf = os.path.join(here, 'supervisord.conf')
with open(supervisord_conf, 'w') as f:
f.write(text)
try:
instance.configfile = supervisord_conf
instance.realize(args=[])
finally:
shutil.rmtree(here, ignore_errors=True)
options = instance.configroot.supervisord
group = options.process_group_configs[0]
self.assertEqual(group.name, 'cmd')
proc = group.process_configs[0]
self.assertEqual(proc.command,
os.path.join(here, '/bin/from/program/section'))

def test_options_program_section_expands_here(self):
instance = self._makeOne()
text = lstrip('''
Expand Down

0 comments on commit 34ff60a

Please sign in to comment.