Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
* upstream/develop: (54 commits)
  remove duplicate work (saltstack#37225)
  Fix Zypper module and tests for Carbon
  Fix merge conflict in SPM
  Remove repr flag from format
  Address transport test hang
  Allow pass renderer to work with complex yaml structures
  Pylint fix for 2016.3 (saltstack#37186)
  load tags should reference the actual load tags
  Do not prematurily raise an exception, let the main loop take care of it instead
  Do not restart the whole thing if roster is not around
  Fix PEP8
  Do not prematurily raise an exception, let the main loop take care of it instead
  Do not restart the whole thing if roster is not around
  Fix PEP8
  Fixed mutable arguments in sensehat module
  Fixed style of sensehat beacon
  Fixed style of sensehat module
  Remove sleep. Thanks @s0undt3ch
  Fix test suite hang on salt testing
  Fixed __salt__ call in sensehat beacon
  ...
  • Loading branch information
jojohans committed Oct 25, 2016
2 parents 164bb2a + 534f510 commit d20fa88
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 66 deletions.
91 changes: 91 additions & 0 deletions salt/beacons/sensehat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*-
'''
Beacon to monitor temperature, humidity and pressure using the SenseHat
of a Raspberry Pi.
:maintainer: Benedikt Werner <1benediktwerner@gmail.com>
:maturity: new
:depends: sense_hat Python module
'''

from __future__ import absolute_import
import logging
import re

log = logging.getLogger(__name__)


def __virtual__():
return 'sensehat.get_pressure' in __salt__


def __validate__(config):
'''
Validate the beacon configuration
'''
# Configuration for sensehat beacon should be a dict
if not isinstance(config, dict):
return False, ('Configuration for sensehat beacon '
'must be a dictionary.')
return True, 'Valid beacon configuration'


def beacon(config):
'''
Monitor the temperature, humidity and pressure using the SenseHat sensors.
You can either specify a threshold for each value and only emit a beacon
if it is exceeded or define a range and emit a beacon when the value is
out of range.
Units:
* humidity: percent
* temperature: degrees Celsius
* temperature_from_pressure: degrees Celsius
* pressure: Millibars
.. code-block:: yaml
beacons:
sensehat:
humidity: 70%
temperature: [20, 40]
temperature_from_pressure: 40
pressure: 1500
'''
ret = []
min_default = {
'humidity': '0',
'pressure': '0',
'temperature': '-273.15'
}

for sensor in config:
sensor_function = 'sensehat.get_{0}'.format(sensor)
if sensor_function not in __salt__:
log.error('No sensor for meassuring {0}. Skipping.'.format(sensor))
continue

sensor_config = config[sensor]
if isinstance(sensor_config, list):
sensor_min = str(sensor_config[0])
sensor_max = str(sensor_config[1])
else:
sensor_min = min_default.get(sensor, '0')
sensor_max = str(sensor_config)

if '%' in sensor_min:
sensor_min = re.sub('%', '', sensor_min)
if '%' in sensor_max:
sensor_max = re.sub('%', '', sensor_max)
sensor_min = float(sensor_min)
sensor_max = float(sensor_max)

current_value = __salt__[sensor_function]()
if not sensor_min <= current_value <= sensor_max:
ret.append({
'tag': 'sensehat/{0}'.format(sensor),
sensor: current_value
})

return ret
4 changes: 0 additions & 4 deletions salt/client/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ def _low(self, fun, low, print_event=True, full_return=False):
else:
kwargs = low['kwarg']

# Update the event data with loaded args and kwargs
data['fun_args'] = args + ([kwargs] if kwargs else [])
func_globals['__jid_event__'].fire_event(data, 'new')

# Update the event data with loaded args and kwargs
data['fun_args'] = list(args) + ([kwargs] if kwargs else [])
func_globals['__jid_event__'].fire_event(data, 'new')
Expand Down
7 changes: 4 additions & 3 deletions salt/client/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def __init__(self, opts):
raise salt.exceptions.SaltSystemExit('No ssh binary found in path -- ssh must be installed for salt-ssh to run. Exiting.')
self.opts['_ssh_version'] = ssh_version()
self.tgt_type = self.opts['selected_target_option'] \
if self.opts['selected_target_option'] else 'glob'
if self.opts['selected_target_option'] else 'glob'
self.roster = salt.roster.Roster(opts, opts.get('roster', 'flat'))
self.targets = self.roster.targets(
self.opts['tgt'],
Expand Down Expand Up @@ -446,9 +446,10 @@ def handle_ssh(self, mine=False):
returned = set()
rets = set()
init = False
if not self.targets:
raise salt.exceptions.SaltClientError('No matching targets found in roster.')
while True:
if not self.targets:
log.error('No matching targets found in roster.')
break
if len(running) < self.opts.get('ssh_max_procs', 25) and not init:
try:
host = next(target_iter)
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/dockerng.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ def create(image,
cpu_shares
CPU shares (relative weight)
Example: ``cpu_shares=0.5``, ``cpu_shares=1``
Example: ``cpu_shares=0``, ``cpu_shares=256``
cpuset
CPUs on which which to allow execution, specified as a string
Expand Down
50 changes: 28 additions & 22 deletions salt/modules/gpg.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
'''
Manage a GPG keychains, add keys, create keys, retrieve keys
from keyservers. Sign, encrypt and sign & encrypt text and files.
Manage a GPG keychains, add keys, create keys, retrieve keys from keyservers.
Sign, encrypt and sign plus encrypt text and files.
.. versionadded:: 2015.5.0
.. note::
The ``python-gnupg`` library and gpg binary are
required to be installed.
The ``python-gnupg`` library and ``gpg`` binary are required to be
installed.
'''

Expand Down Expand Up @@ -565,7 +566,7 @@ def get_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
Get a key from the GPG keychain
keyid
The keyid of the key to be retrieved.
The key ID (short or long) of the key to be retrieved.
fingerprint
The fingerprint of the key to be retrieved.
Expand All @@ -591,7 +592,9 @@ def get_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
'''
tmp = {}
for _key in _list_keys(user, gnupghome):
if _key['fingerprint'] == fingerprint or _key['keyid'] == keyid:
if (_key['fingerprint'] == fingerprint or
_key['keyid'] == keyid or
_key['keyid'][8:] == keyid):
tmp['keyid'] = _key['keyid']
tmp['fingerprint'] = _key['fingerprint']
tmp['uids'] = _key['uids']
Expand Down Expand Up @@ -625,7 +628,7 @@ def get_secret_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
Get a key from the GPG keychain
keyid
The keyid of the key to be retrieved.
The key ID (short or long) of the key to be retrieved.
fingerprint
The fingerprint of the key to be retrieved.
Expand All @@ -651,7 +654,9 @@ def get_secret_key(keyid=None, fingerprint=None, user=None, gnupghome=None):
'''
tmp = {}
for _key in _list_keys(user, gnupghome, secret=True):
if _key['fingerprint'] == fingerprint or _key['keyid'] == keyid:
if (_key['fingerprint'] == fingerprint or
_key['keyid'] == keyid or
_key['keyid'][8:] == keyid):
tmp['keyid'] = _key['keyid']
tmp['fingerprint'] = _key['fingerprint']
tmp['uids'] = _key['uids']
Expand Down Expand Up @@ -681,24 +686,24 @@ def get_secret_key(keyid=None, fingerprint=None, user=None, gnupghome=None):


@_restore_ownership
def import_key(user=None,
text=None,
def import_key(text=None,
filename=None,
user=None,
gnupghome=None):
r'''
Import a key from text or file
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
text
The text containing to import.
filename
The filename containing the key to import.
user
Which user's keychain to access, defaults to user Salt is running as.
Passing the user as ``salt`` will set the GnuPG home directory to the
``/etc/salt/gpgkeys``.
gnupghome
Specify the location where GPG keyring and related files are stored.
Expand All @@ -711,9 +716,9 @@ def import_key(user=None,
'''
ret = {
'res': True,
'message': ''
}
'res': True,
'message': ''
}

gpg = _create_gpg(user, gnupghome)

Expand Down Expand Up @@ -761,12 +766,13 @@ def export_key(keyids=None, secret=False, user=None, gnupghome=None):
Export a key from the GPG keychain
keyids
The keyid(s) of the key(s) to be exported. Can be specified as a comma
separated string or a list. Anything which GnuPG itself accepts to
identify a key - for example, the keyid or the fingerprint could be used.
The key ID(s) of the key(s) to be exported. Can be specified as a comma
separated string or a list. Anything which GnuPG itself accepts to
identify a key - for example, the key ID or the fingerprint could be
used.
secret
Export the secret key identified by the keyid information passed.
Export the secret key identified by the ``keyids`` information passed.
user
Which user's keychain to access, defaults to user Salt is running as.
Expand Down
Loading

0 comments on commit d20fa88

Please sign in to comment.