Merge pull request #51278 from dwoz/issue51248

Warn about proper validation option
This commit is contained in:
Thomas S Hatch 2019-01-22 15:13:12 -07:00 committed by GitHub
commit 1abffb20b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 8 deletions

View file

@ -1938,15 +1938,10 @@ PROVIDER_CONFIG_DEFAULTS = {
# <---- Salt Cloud Configuration Defaults ------------------------------------
def _validate_file_roots(file_roots):
def _normalize_roots(file_roots):
'''
If the file_roots option has a key that is None then we will error out,
just replace it with an empty list
Normalize file or pillar roots.
'''
if not isinstance(file_roots, dict):
log.warning('The file_roots parameter is not properly formatted,'
' using defaults')
return {'base': _expand_glob_path([salt.syspaths.BASE_FILE_ROOTS_DIR])}
for saltenv, dirs in six.iteritems(file_roots):
normalized_saltenv = six.text_type(saltenv)
if normalized_saltenv != saltenv:
@ -1958,6 +1953,30 @@ def _validate_file_roots(file_roots):
return file_roots
def _validate_pillar_roots(pillar_roots):
'''
If the pillar_roots option has a key that is None then we will error out,
just replace it with an empty list
'''
if not isinstance(pillar_roots, dict):
log.warning('The pillar_roots parameter is not properly formatted,'
' using defaults')
return {'base': _expand_glob_path([salt.syspaths.BASE_PILLAR_ROOTS_DIR])}
return _normalize_roots(pillar_roots)
def _validate_file_roots(file_roots):
'''
If the file_roots option has a key that is None then we will error out,
just replace it with an empty list
'''
if not isinstance(file_roots, dict):
log.warning('The file_roots parameter is not properly formatted,'
' using defaults')
return {'base': _expand_glob_path([salt.syspaths.BASE_FILE_ROOTS_DIR])}
return _normalize_roots(file_roots)
def _expand_glob_path(file_roots):
'''
Applies shell globbing to a set of directories and returns
@ -3767,7 +3786,7 @@ def apply_minion_config(overrides=None,
# nothing else!
opts['open_mode'] = opts['open_mode'] is True
opts['file_roots'] = _validate_file_roots(opts['file_roots'])
opts['pillar_roots'] = _validate_file_roots(opts['pillar_roots'])
opts['pillar_roots'] = _validate_pillar_roots(opts['pillar_roots'])
# Make sure ext_mods gets set if it is an untrue value
# (here to catch older bad configs)
opts['extension_modules'] = (

View file

@ -1 +1,32 @@
# -*- coding: utf-8 -*-
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
import tests.support.mock as mock
import salt.config
import salt.syspaths
class ConfigTest(TestCase):
def test_validate_bad_pillar_roots(self):
expected = salt.config._expand_glob_path(
[salt.syspaths.BASE_PILLAR_ROOTS_DIR]
)
with mock.patch('salt.config._normalize_roots') as mk:
ret = salt.config._validate_pillar_roots(None)
assert not mk.called
assert ret == {'base': expected}
def test_validate_bad_file_roots(self):
expected = salt.config._expand_glob_path(
[salt.syspaths.BASE_FILE_ROOTS_DIR]
)
with mock.patch('salt.config._normalize_roots') as mk:
ret = salt.config._validate_file_roots(None)
assert not mk.called
assert ret == {'base': expected}