Handle exceptions raised by __virtual__

Closes #23452
This commit is contained in:
Mike Place 2015-05-13 01:27:17 -06:00
parent f20c0e42ce
commit 45b4015d7d
2 changed files with 13 additions and 5 deletions

View file

@ -1069,7 +1069,13 @@ class Loader(object):
end, module_name)
log.warning(msg)
else:
virtual = mod.__virtual__()
try:
virtual = mod.__virtual__()
except Exception as exc:
log.error('Exception raised when processing __virtual__ function
' for {0}. Module will not be loaded {1}'.format(
module_name, exc))
virtual = None
# Get the module's virtual name
virtualname = getattr(mod, '__virtualname__', virtual)
if not virtual:

View file

@ -17,10 +17,12 @@ def __virtual__():
'''
Load this state if this is the salt-master
'''
return ('winrepo'
if 'salt-master' in __grains__.get('roles', [])
else False)
try:
return ('winrepo'
if 'salt-master' in __grains__.get('roles', [])
else False)
except TypeError:
return False
def genrepo(name, force=False, allow_empty=False):