The file listing needs to be sorted to return expectable results.

This seems like the only reasonable way to override, for example, grains.
Grains from `custom_grains_2` should override grains from `custom_grains_1`.
This commit is contained in:
Pedro Algarvio 2017-06-01 18:47:22 +01:00
parent 3b95ef2345
commit 451d8f98e3
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
2 changed files with 5 additions and 1 deletions

View file

@ -715,6 +715,7 @@ def grains(opts, force_refresh=False, proxy=None):
# one parameter. Then the grains can have access to the
# proxymodule for retrieving information from the connected
# device.
log.trace('Loading {0} grain'.format(key))
if funcs[key].__code__.co_argcount == 1:
ret = funcs[key](proxy)
else:
@ -1179,7 +1180,8 @@ class LazyLoader(salt.utils.lazy.LazyDict):
for mod_dir in self.module_dirs:
files = []
try:
files = os.listdir(mod_dir)
# Make sure we have a sorted listdir in order to have expectable override results
files = sorted(os.listdir(mod_dir))
except OSError:
continue # Next mod_dir
for filename in files:

View file

@ -32,6 +32,8 @@ class LoaderGrainsTest(ModuleCase):
# self.opts['grains'] = grains(self.opts)
def test_grains_overwrite(self):
# Force a grains sync
self.run_function('saltutil.sync_grains')
# To avoid a race condition on Windows, we need to make sure the
# `test_custom_grain2.py` file is present in the _grains directory
# before trying to get the grains. This test may execute before the