Skip to content

Commit 364e2bf

Browse files
committed
Add changelog entry and more tests for 18438c5
1 parent 2076211 commit 364e2bf

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
- Fixed a bug where the XML-RPC method ``supervisor.getAllConfigInfo()``
55
did not return the value of the ``autorestart`` program option.
66

7+
- Fixed a bug where an escaped percent sign (``%%``) could not be used
8+
in ``environment=`` in the ``[supervisord]`` section of the config file.
9+
The bug did not affect ``[program:x]`` sections, where an escaped
10+
percent sign in ``environment=`` already worked. Patch by yuk1pedia.
11+
712
- Parsing ``environment=`` in the config file now uses ``shlex`` in POSIX
813
mode instead of legacy mode to allow for escaped quotes in the values.
914
However, on Python 2 before 2.7.13 and Python 3 before 3.5.3, POSIX mode

supervisor/tests/test_options.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,20 @@ def test_processes_from_section(self):
17381738
self.assertEqual(pconfig.environment,
17391739
{'KEY1':'val1', 'KEY2':'val2', 'KEY3':'0'})
17401740

1741+
def test_processes_from_section_environment_with_escaped_chars(self):
1742+
instance = self._makeOne()
1743+
text = lstrip("""\
1744+
[program:foo]
1745+
command = /bin/foo
1746+
environment=VAR_WITH_P="some_value_%%_end"
1747+
""")
1748+
from supervisor.options import UnhosedConfigParser
1749+
config = UnhosedConfigParser()
1750+
config.read_string(text)
1751+
pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
1752+
expected = {'VAR_WITH_P': 'some_value_%_end'}
1753+
self.assertEqual(pconfigs[0].environment, expected)
1754+
17411755
def test_processes_from_section_host_node_name_expansion(self):
17421756
instance = self._makeOne()
17431757
text = lstrip("""\
@@ -1933,7 +1947,7 @@ def test_options_with_environment_expansions(self):
19331947
nocleanup = %(ENV_SUPD_NOCLEANUP)s
19341948
childlogdir = %(ENV_HOME)s
19351949
strip_ansi = %(ENV_SUPD_STRIP_ANSI)s
1936-
environment = FAKE_ENV_VAR=/some/path
1950+
environment = GLOBAL_ENV_VAR=%(ENV_SUPR_ENVIRONMENT_VALUE)s
19371951
19381952
[inet_http_server]
19391953
port=*:%(ENV_HTSRV_PORT)s
@@ -1954,6 +1968,7 @@ def test_options_with_environment_expansions(self):
19541968
startretries=%(ENV_CAT1_STARTRETRIES)s
19551969
directory=%(ENV_CAT1_DIR)s
19561970
umask=%(ENV_CAT1_UMASK)s
1971+
environment = PROGRAM_ENV_VAR=%(ENV_CAT1_ENVIRONMENT_VALUE)s
19571972
""")
19581973
from supervisor import datatypes
19591974
from supervisor.options import UnhosedConfigParser
@@ -1964,6 +1979,7 @@ def test_options_with_environment_expansions(self):
19641979
'ENV_HTSRV_PORT': '9210',
19651980
'ENV_HTSRV_USER': 'someuser',
19661981
'ENV_HTSRV_PASS': 'passwordhere',
1982+
'ENV_SUPR_ENVIRONMENT_VALUE': 'from_supervisord_section',
19671983
'ENV_SUPD_LOGFILE_MAXBYTES': '51MB',
19681984
'ENV_SUPD_LOGFILE_BACKUPS': '10',
19691985
'ENV_SUPD_LOGLEVEL': 'info',
@@ -1978,6 +1994,7 @@ def test_options_with_environment_expansions(self):
19781994
'ENV_CAT1_COMMAND_LOGDIR': '/path/to/logs',
19791995
'ENV_CAT1_PRIORITY': '3',
19801996
'ENV_CAT1_AUTOSTART': 'true',
1997+
'ENV_CAT1_ENVIRONMENT_VALUE': 'from_program_section',
19811998
'ENV_CAT1_USER': 'root', # resolved to uid
19821999
'ENV_CAT1_STDOUT_LOGFILE': '/tmp/cat.log',
19832000
'ENV_CAT1_STDOUT_LOGFILE_MAXBYTES': '78KB',
@@ -2043,7 +2060,11 @@ def test_options_with_environment_expansions(self):
20432060
self.assertEqual(proc1.exitcodes, [0])
20442061
self.assertEqual(proc1.directory, '/tmp')
20452062
self.assertEqual(proc1.umask, 2)
2046-
self.assertEqual(proc1.environment, dict(FAKE_ENV_VAR='/some/path'))
2063+
expected_env = {
2064+
'GLOBAL_ENV_VAR': 'from_supervisord_section',
2065+
'PROGRAM_ENV_VAR': 'from_program_section'
2066+
}
2067+
self.assertEqual(proc1.environment, expected_env)
20472068

20482069
def test_options_supervisord_section_expands_here(self):
20492070
instance = self._makeOne()

0 commit comments

Comments
 (0)