mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Status beacon should raise proper exception
Also have it check for the status exec module in __virtual__()
This commit is contained in:
parent
1b52289508
commit
a8ce153252
@ -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__)
|
||||
|
||||
@ -99,6 +100,12 @@ def __validate__(config):
|
||||
return False, ('Configuration for status beacon must be a dictionary.')
|
||||
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):
|
||||
'''
|
||||
@ -118,7 +125,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.NotImplemented as exc:
|
||||
log.error('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':
|
||||
|
@ -27,7 +27,7 @@ import salt.utils.event
|
||||
from salt.utils.network import host_to_ips as _host_to_ips
|
||||
from salt.utils.network import remote_port_tcp as _remote_port_tcp
|
||||
from salt.ext.six.moves import zip
|
||||
from salt.exceptions import CommandExecutionError
|
||||
from salt.exceptions import CommandExecutionError, NotImplemented
|
||||
|
||||
__virtualname__ = 'status'
|
||||
__opts__ = {}
|
||||
@ -210,8 +210,14 @@ def loadavg():
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' status.loadavg
|
||||
|
||||
:raises NotImpelemnted: 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