Fix validate_reload by returning the validated value (#1378)

* Fix validate_reload by returning the validated value

When '--reload=RELOADER_TYPE' was implemented, `validate_reload()` was
added but in one of the last refactorings, it lost the return statement
at the end of the function. As a result, the '--reload' config value was
totally broken.

This resolves the issue by adding the missing return.

* Fix tests by changing --reload to always require an argument

- '--reload' always requires an argument now
- Added 'auto' as the default value for '--reload'
This commit is contained in:
Mark Adams 2016-10-28 01:35:24 -05:00 committed by Benoit Chesneau
parent 07f62e26f3
commit 6eb01409da
3 changed files with 11 additions and 11 deletions

View File

@ -256,7 +256,7 @@ reload
~~~~~~ ~~~~~~
* ``--reload RELOADER_TYPE`` * ``--reload RELOADER_TYPE``
* ``None`` * ``off``
Restart workers when code changes. Restart workers when code changes.
@ -270,8 +270,8 @@ application code or the reload will not work as designed.
When using this option, you can optionally specify whether you would When using this option, you can optionally specify whether you would
like to use file system polling or the kernel's inotify API to watch like to use file system polling or the kernel's inotify API to watch
for changes. Generally, inotify should be preferred if available for changes. Generally, inotify should be preferred if available
because it consumes less system resources. If no preference is given, because it consumes less system resources. The default behavior (auto)
inotify will attempted with a fallback to FS polling. is to attempt inotify with a fallback to FS polling.
Note: In order to use the inotify reloader, you must have the 'inotify' Note: In order to use the inotify reloader, you must have the 'inotify'
package installed. package installed.

View File

@ -492,15 +492,17 @@ def validate_hostport(val):
def validate_reloader(val): def validate_reloader(val):
if val is None: if val is None:
val = 'default' val = 'auto'
choices = ['poll', 'inotify', 'default'] choices = ['auto', 'poll', 'inotify', 'off']
if val not in choices: if val not in choices:
raise ConfigError( raise ConfigError(
'Invalid reloader type. Must be one of: %s' % choices 'Invalid reloader type. Must be one of: %s' % choices
) )
return val
def get_default_config_file(): def get_default_config_file():
config_path = os.path.join(os.path.abspath(os.getcwd()), config_path = os.path.join(os.path.abspath(os.getcwd()),
@ -820,9 +822,7 @@ class Reload(Setting):
section = 'Debugging' section = 'Debugging'
cli = ['--reload'] cli = ['--reload']
validator = validate_reloader validator = validate_reloader
nargs = '?' default = 'off'
const = 'default'
default = None
meta = 'RELOADER_TYPE' meta = 'RELOADER_TYPE'
desc = '''\ desc = '''\
@ -838,8 +838,8 @@ class Reload(Setting):
When using this option, you can optionally specify whether you would When using this option, you can optionally specify whether you would
like to use file system polling or the kernel's inotify API to watch like to use file system polling or the kernel's inotify API to watch
for changes. Generally, inotify should be preferred if available for changes. Generally, inotify should be preferred if available
because it consumes less system resources. If no preference is given, because it consumes less system resources. The default behavior (auto)
inotify will attempted with a fallback to FS polling. is to attempt inotify with a fallback to FS polling.
Note: In order to use the inotify reloader, you must have the 'inotify' Note: In order to use the inotify reloader, you must have the 'inotify'
package installed. package installed.

View File

@ -115,7 +115,7 @@ class Worker(object):
self.load_wsgi() self.load_wsgi()
# start the reloader # start the reloader
if self.cfg.reload: if self.cfg.reload and self.cfg.reload != 'off':
def changed(fname): def changed(fname):
self.log.info("Worker reloading: %s modified", fname) self.log.info("Worker reloading: %s modified", fname)
self.alive = False self.alive = False