mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #38107 from cachedout/supercede_38088
Status beacon should raise proper exception
This commit is contained in:
commit
4b9a7f2295
@ -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':
|
||||
|
@ -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]}
|
||||
|
Loading…
Reference in New Issue
Block a user