Merge remote-tracking branch 'upstream/2015.5' into merge-forward-develop

This commit is contained in:
Colton Myers 2015-06-12 11:42:42 -06:00
commit 5b49e89b43
6 changed files with 115 additions and 10 deletions

View File

@ -1230,6 +1230,8 @@ def _convert_args(args):
for arg in args:
if isinstance(arg, dict):
for key in list(arg.keys()):
if key == '__kwarg__':
continue
converted.append('{0}={1}'.format(key, arg[key]))
else:
converted.append(arg)

View File

@ -10,7 +10,6 @@ import re
import sys
import uuid
import shlex
import string
# Import salt libs
import salt.utils
@ -319,10 +318,7 @@ def build_rule(table='filter', chain=None, command=None, position='', full=None,
for after_jump_argument in after_jump_arguments:
if after_jump_argument in kwargs:
value = kwargs[after_jump_argument]
if any(ws_char in str(value) for ws_char in string.whitespace):
after_jump.append('--{0} "{1}"'.format(after_jump_argument, value))
else:
after_jump.append('--{0} {1}'.format(after_jump_argument, value))
after_jump.append('--{0} {1}'.format(after_jump_argument, value))
del kwargs[after_jump_argument]
if 'log' in kwargs:

View File

@ -474,6 +474,7 @@ def highstate(test=None,
salt '*' state.highstate pillar="{foo: 'Foo!', bar: 'Bar!'}"
'''
if _disabled(['highstate']):
log.debug('Salt highstate run is disabled. To re-enable, run state.enable highstate')
ret = {
'name': 'Salt highstate run is disabled. To re-enable, run state.enable highstate',
'result': 'False',
@ -635,6 +636,8 @@ def sls(mods,
disabled = _disabled([mods])
if disabled:
for state in disabled:
log.debug('Salt state {0} run is disabled. To re-enable, run state.enable {0}'.format(state))
__context__['retcode'] = 1
return disabled

View File

@ -27,7 +27,10 @@ def targets(tgt, tgt_type='glob', **kwargs):
rend = salt.loader.render(__opts__, {})
raw = compile_template(template, rend, __opts__['renderer'], **kwargs)
rmatcher = RosterMatcher(raw, tgt, tgt_type, 'ipv4')
conditioned_raw = {}
for minion in raw:
conditioned_raw[str(minion)] = raw[minion]
rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
return rmatcher.targets()

View File

@ -60,7 +60,6 @@ class PkgModuleTest(integration.ModuleCase,
self.assertNotEqual(ret, {})
if os_release.startswith('12.'):
self.assertIn(repo, ret)
self.assertTrue(ret[repo]['result'])
else:
self.assertIn(uri, ret.keys()[0])
@ -90,6 +89,13 @@ class PkgModuleTest(integration.ModuleCase,
'''
pkg = 'htop'
version = self.run_function('pkg.version', [pkg])
os_grain = self.run_function('grains.item', ['os'])['os']
os_release = self.run_function('grains.item', ['osrelease'])['osrelease']
if os_grain == 'Ubuntu':
if os_release.startswith('12.'):
self.skipTest('pkg.install and pkg.remove do not work on ubuntu '
'12 when run from the test suite')
def test_install():
install_ret = self.run_function('pkg.install', [pkg])
@ -114,13 +120,15 @@ class PkgModuleTest(integration.ModuleCase,
'''
pkg = 'htop'
os_family = self.run_function('grains.item', ['os_family'])['os_family']
os_major_release = self.run_function('grains.item', ['osmajorrelease'])['osmajorrelease']
available = self.run_function('sys.doc', ['pkg.hold'])
if available:
if os_family == 'RedHat':
versionlock = self.run_function('pkg.version', ['yum-plugin-versionlock'])
lock_pkg = 'yum-versionlock' if os_major_release == '5' else 'yum-plugin-versionlock'
versionlock = self.run_function('pkg.version', [lock_pkg])
if not versionlock:
self.run_function('pkg.install', ['yum-plugin-versionlock'])
self.run_function('pkg.install', [lock_pkg])
hold_ret = self.run_function('pkg.hold', [pkg])
self.assertIn(pkg, hold_ret)
@ -132,7 +140,7 @@ class PkgModuleTest(integration.ModuleCase,
if os_family == 'RedHat':
if not versionlock:
self.run_function('pkg.remove', ['yum-plugin-versionlock'])
self.run_function('pkg.remove', [lock_pkg])
else:
os_grain = self.run_function('grains.item', ['os'])['os']

View File

@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
from salttesting import skipIf, TestCase
from salttesting.mock import (
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch
)
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import Salt Libs
from salt.states import reg
reg.__opts__ = {}
reg.__salt__ = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class RegTestCase(TestCase):
'''
Test cases for salt.states.reg
'''
# 'present' function tests: 1
def test_present(self):
'''
Test to set a registry entry.
'''
name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt\\version'
value = '0.15.3'
ret = {'name': name,
'changes': {},
'result': True,
'comment': '{0} is already configured'.format(name)}
mock = MagicMock(side_effect=[value, 'a', 'a'])
mock_t = MagicMock(return_value=True)
with patch.dict(reg.__salt__, {'reg.read_key': mock,
'reg.set_key': mock_t}):
self.assertDictEqual(reg.present(name, value), ret)
with patch.dict(reg.__opts__, {'test': True}):
ret.update({'comment': '', 'result': None,
'changes': {'reg': 'configured to 0.15.3'}})
self.assertDictEqual(reg.present(name, value), ret)
with patch.dict(reg.__opts__, {'test': False}):
ret.update({'result': True})
self.assertDictEqual(reg.present(name, value), ret)
# 'absent' function tests: 1
def test_absent(self):
'''
Test to remove a registry entry.
'''
name = 'HKEY_CURRENT_USER\\SOFTWARE\\Salt\\version'
ret = {'name': name,
'changes': {},
'result': True,
'comment': '{0} is already absent'.format(name)}
mock = MagicMock(side_effect=[False, True, True])
mock_t = MagicMock(return_value=True)
with patch.dict(reg.__salt__, {'reg.read_key': mock,
'reg.delete_key': mock_t}):
self.assertDictEqual(reg.absent(name), ret)
with patch.dict(reg.__opts__, {'test': True}):
ret.update({'comment': '', 'result': None,
'changes': {'reg': 'Removed {0}'.format(name)}})
self.assertDictEqual(reg.absent(name), ret)
with patch.dict(reg.__opts__, {'test': False}):
ret.update({'result': True})
self.assertDictEqual(reg.absent(name), ret)
if __name__ == '__main__':
from integration import run_tests
run_tests(RegTestCase, needs_daemon=False)