diff --git a/salt/beacons/status.py b/salt/beacons/status.py index 9941e4df60..44920f7605 100644 --- a/salt/beacons/status.py +++ b/salt/beacons/status.py @@ -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': diff --git a/salt/modules/status.py b/salt/modules/status.py index cb76125b26..1ed9494ff9 100644 --- a/salt/modules/status.py +++ b/salt/modules/status.py @@ -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]}