Merge pull request #38107 from cachedout/supercede_38088

Status beacon should raise proper exception
This commit is contained in:
Thomas S Hatch 2016-12-07 10:21:49 -07:00 committed by GitHub
commit 4b9a7f2295
2 changed files with 22 additions and 2 deletions

View File

@ -87,6 +87,7 @@ markers for specific list items:
from __future__ import absolute_import
import logging
import datetime
import salt.exceptions
log = logging.getLogger(__name__)
@ -100,6 +101,14 @@ def __validate__(config):
return True, 'Valid beacon configuration'
def __virtual__():
# TODO Find a way to check the existence of the module itself, not just a single func
if 'status.w' not in __salt__:
return (False, 'The \'status\' execution module is not available on this system')
else:
return True
def beacon(config):
'''
Return status for requested information
@ -118,7 +127,12 @@ def beacon(config):
ret = {}
for func in config:
data = __salt__['status.{0}'.format(func)]()
try:
data = __salt__['status.{0}'.format(func)]()
except salt.exceptions.CommandExecutionError as exc:
log.debug('Status beacon attempted to process function {0} \
but encountered error: {1}'.format(func, exc))
continue
ret[func] = {}
for item in config[func]:
if item == 'all':

View File

@ -210,8 +210,14 @@ def loadavg():
.. code-block:: bash
salt '*' status.loadavg
:raises CommandExecutionError: If the system cannot report loadaverages to Python
'''
load_avg = os.getloadavg()
try:
load_avg = os.getloadavg()
except AttributeError:
# Some UNIX-based operating systems do not have os.getloadavg()
raise salt.exceptions.CommandExecutionError('status.loadavag is not available on your platform')
return {'1-min': load_avg[0],
'5-min': load_avg[1],
'15-min': load_avg[2]}