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:
  Fix pylint error
  Remove test that doesn't actually test anything
  Don't escape source before calling managed
  Fix for saltstack#14915 (saltstack#34254)
  Fixed symlinks on windows where the slashes don't match
  ipset: fix the comment containing blank
  Use 'config_dir' setting instead of CONFIG_DIR in gpg renderer
  ipset: fix commont containing blank
  Fix win_system.set_system_date_time
  win_pkg: refresh pkg database if refresh=True passed to version() or list_pkgs()
  Catch CommandExecutionError in pkg states
  some cleanup and renaming
  better way to check for openSUSE Leap
  Fix for SUSE OS grains in 2015.8
  • Loading branch information
jojohans committed Jun 27, 2016
2 parents efbdd9c + ec28d11 commit 7c695c4
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 80 deletions.
43 changes: 36 additions & 7 deletions salt/modules/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def active(extended=False):
ret = {}
if __grains__['os'] == 'FreeBSD':
_active_mounts_freebsd(ret)
elif __grains__['os'] == 'Solaris':
elif __grains__['kernel'] == 'SunOS':
_active_mounts_solaris(ret)
elif __grains__['os'] == 'OpenBSD':
_active_mounts_openbsd(ret)
Expand Down Expand Up @@ -859,14 +859,25 @@ def swaps():
'''
Return a dict containing information on active swap
.. versionchanged:: 2016.3.2
CLI Example:
.. code-block:: bash
salt '*' mount.swaps
'''
ret = {}
if __grains__['os'] != 'OpenBSD':
if __grains__['kernel'] == 'SunOS':
for line in __salt__['cmd.run_stdout']('swap -l').splitlines():
if line.startswith('swapfile'):
continue
comps = line.split()
ret[comps[0]] = {'type': 'device' if comps[0].startswith(('/dev', 'swap')) else 'file',
'size': int(comps[3]),
'used': (int(comps[3]) - int(comps[4])),
'priority': '-'}
elif __grains__['os'] != 'OpenBSD':
with salt.utils.fopen('/proc/swaps') as fp_:
for line in fp_:
if line.startswith('Filename'):
Expand Down Expand Up @@ -895,6 +906,8 @@ def swapon(name, priority=None):
'''
Activate a swap disk
.. versionchanged:: 2016.3.2
CLI Example:
.. code-block:: bash
Expand All @@ -907,22 +920,33 @@ def swapon(name, priority=None):
ret['stats'] = on_[name]
ret['new'] = False
return ret
cmd = 'swapon {0}'.format(name)
if priority:
cmd += ' -p {0}'.format(priority)
__salt__['cmd.run'](cmd, python_shell=False)

if __grains__['kernel'] == 'SunOS':
if __grains__['virtual'] != 'zone':
__salt__['cmd.run']('swap -a {0}'.format(name), python_shell=False)
else:
return False
else:
cmd = 'swapon {0}'.format(name)
if priority:
cmd += ' -p {0}'.format(priority)
__salt__['cmd.run'](cmd, python_shell=False)

on_ = swaps()
if name in on_:
ret['stats'] = on_[name]
ret['new'] = True
return ret

return ret


def swapoff(name):
'''
Deactivate a named swap mount
.. versionchanged:: 2016.3.2
CLI Example:
.. code-block:: bash
Expand All @@ -931,7 +955,12 @@ def swapoff(name):
'''
on_ = swaps()
if name in on_:
if __grains__['os'] != 'OpenBSD':
if __grains__['kernel'] == 'SunOS':
if __grains__['virtual'] != 'zone':
__salt__['cmd.run']('swap -a {0}'.format(name), python_shell=False)
else:
return False
elif __grains__['os'] != 'OpenBSD':
__salt__['cmd.run']('swapoff {0}'.format(name), python_shell=False)
else:
__salt__['cmd.run']('swapctl -d {0}'.format(name),
Expand Down
4 changes: 4 additions & 0 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def list_pkgs(versions_as_list=False, saltenv='base', **kwargs):
for x in ('removed', 'purge_desired')]):
return {}

if kwargs.get('refresh', False):
# _get_name_map() needs a refresh_db if cache is not present
refresh_db()

ret = {}
name_map = _get_name_map(saltenv)
for pkg_name, val in six.iteritems(_get_reg_software()):
Expand Down
12 changes: 6 additions & 6 deletions salt/modules/win_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,17 +865,17 @@ def set_system_date_time(years=None,
return False

# Check for passed values. If not passed, use current values
if not years:
if years is None:
years = date_time[0]
if not months:
if months is None:
months = date_time[1]
if not days:
if days is None:
days = date_time[3]
if not hours:
if hours is None:
hours = date_time[4]
if not minutes:
if minutes is None:
minutes = date_time[5]
if not seconds:
if seconds is None:
seconds = date_time[6]

# Create the time tuple to be passed to SetLocalTime, including day_of_week
Expand Down
2 changes: 1 addition & 1 deletion salt/renderers/gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _get_key_dir():
gpg_keydir = __salt__['config.get']('gpg_keydir')
else:
gpg_keydir = __opts__.get('gpg_keydir')
return gpg_keydir or os.path.join(salt.syspaths.CONFIG_DIR, 'gpgkeys')
return gpg_keydir or os.path.join(__opts__['config_dir'], 'gpgkeys')


def _decrypt_ciphertext(cipher, translate_newlines=False):
Expand Down
3 changes: 1 addition & 2 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def symlink(
)
if __salt__['file.is_link'](name):
# The link exists, verify that it matches the target
if __salt__['file.readlink'](name) != target:
if os.path.normpath(__salt__['file.readlink'](name)) != os.path.normpath(target):
# The target is wrong, delete the link
os.remove(name)
else:
Expand Down Expand Up @@ -2480,7 +2480,6 @@ def merge_ret(path, _ret):
ret['changes'][path] = _ret['changes']

def manage_file(path, source):
source = salt.utils.url.escape(source)
if clean and os.path.exists(path) and os.path.isdir(path):
_ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
if __opts__['test']:
Expand Down
37 changes: 19 additions & 18 deletions salt/states/ipset.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ def present(name, entry=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}
test_flag = False

if not entry:
ret['result'] = False
Expand All @@ -198,25 +197,24 @@ def present(name, entry=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)
if 'timeout' in kwargs:
if 'comment' in _entry:
_entry = '{0} timeout {1} {2} {3}'.format(entry.split()[0], kwargs['timeout'], entry.split()[1], entry.split()[2])
else:
_entry = '{0} timeout {1}'.format(entry.split()[0], kwargs['timeout'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

if __salt__['ipset.check'](kwargs['set_name'],
_entry,
family) is True:
if test_flag is False:
ret['result'] = True
ret['comment'] += 'entry for {0} already in set {1} for {2}\n'.format(
entry,
kwargs['set_name'],
family)
else:
if __opts__['test']:
test_flag = True
ret['result'] = None
ret['comment'] += 'entry {0} would be added to set {1} for family {2}\n'.format(
entry,
Expand All @@ -226,7 +224,6 @@ def present(name, entry=None, family='ipv4', **kwargs):
command = __salt__['ipset.add'](kwargs['set_name'], entry, family, **kwargs)
if 'Error' not in command:
ret['changes'] = {'locale': name}
ret['result'] = True
ret['comment'] += 'entry {0} added to set {1} for family {2}\n'.format(
_entry,
kwargs['set_name'],
Expand Down Expand Up @@ -255,7 +252,7 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}

if not entry:
Expand All @@ -270,10 +267,14 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)

if 'comment' in kwargs:
_entry = '{0} comment "{1}"'.format(entry, kwargs['comment'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

log.debug('_entry {0}'.format(_entry))
if not __salt__['ipset.check'](kwargs['set_name'],
Expand All @@ -285,8 +286,8 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
kwargs['set_name'],
family)
else:

if __opts__['test']:
ret['result'] = None
ret['comment'] += 'ipset entry {0} would be removed from set {1} for {2}\n'.format(
entry,
kwargs['set_name'],
Expand Down
26 changes: 23 additions & 3 deletions salt/states/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,14 @@ def _find_install_targets(name=None,
if __grains__['os'] == 'FreeBSD':
kwargs['with_origin'] = True

cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
try:
cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
except CommandExecutionError as exc:
return {'name': name,
'changes': {},
'result': False,
'comment': exc.strerror}

if any((pkgs, sources)):
if pkgs:
desired = _repack_pkgs(pkgs)
Expand Down Expand Up @@ -1158,7 +1165,13 @@ def installed(
# If version is empty, it means the latest version is installed
# so we grab that version to avoid passing an empty string
if not version:
version = __salt__['pkg.version'](name)
try:
version = __salt__['pkg.version'](name)
except CommandExecutionError as exc:
return {'name': name,
'changes': {},
'result': False,
'comment': exc.strerror}

kwargs['allow_updates'] = allow_updates
result = _find_install_targets(name, version, pkgs, sources,
Expand Down Expand Up @@ -1708,7 +1721,6 @@ def latest(
else:
desired_pkgs = [name]

cur = __salt__['pkg.version'](*desired_pkgs, **kwargs)
try:
avail = __salt__['pkg.latest_version'](*desired_pkgs,
fromrepo=fromrepo,
Expand All @@ -1722,6 +1734,14 @@ def latest(
'newest available version of package(s): {0}'
.format(exc)}

try:
cur = __salt__['pkg.version'](*desired_pkgs, **kwargs)
except CommandExecutionError as exc:
return {'name': name,
'changes': {},
'result': False,
'comment': exc.strerror}

# Remove the rtag if it exists, ensuring only one refresh per salt run
# (unless overridden with refresh=True)
if os.path.isfile(rtag) and refresh:
Expand Down
Loading

0 comments on commit 7c695c4

Please sign in to comment.