mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add some grains targeting tests
This commit is contained in:
parent
1b76de1557
commit
37cfe70724
2 changed files with 83 additions and 7 deletions
|
@ -193,7 +193,9 @@ def setvals(grains, destructive=False):
|
|||
'''
|
||||
Set new grains values in the grains config file
|
||||
|
||||
:param Destructive: If an operation results in a key being removed, delete the key, too. Defaults to False.
|
||||
destructive
|
||||
If an operation results in a key being removed, delete the key, too.
|
||||
Defaults to False.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -279,7 +281,15 @@ def setval(key, val, destructive=False):
|
|||
'''
|
||||
Set a grains value in the grains config file
|
||||
|
||||
:param Destructive: If an operation results in a key being removed, delete the key, too. Defaults to False.
|
||||
key
|
||||
The grain key to be set.
|
||||
|
||||
val
|
||||
The value to set the grain key to.
|
||||
|
||||
destructive
|
||||
If an operation results in a key being removed, delete the key, too.
|
||||
Defaults to False.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -305,11 +315,13 @@ def append(key, val, convert=False, delimiter=DEFAULT_TARGET_DELIM):
|
|||
val
|
||||
The value to append to the grain key
|
||||
|
||||
:param convert: If convert is True, convert non-list contents into a list.
|
||||
convert
|
||||
If convert is True, convert non-list contents into a list.
|
||||
If convert is False and the grain contains non-list contents, an error
|
||||
is given. Defaults to False.
|
||||
|
||||
:param delimiter: The key can be a nested dict key. Use this parameter to
|
||||
delimiter
|
||||
The key can be a nested dict key. Use this parameter to
|
||||
specify the delimiter you use, instead of the default ``:``.
|
||||
You can now append values to a list in nested dictionary grains. If the
|
||||
list doesn't exist at this level, it will be created.
|
||||
|
@ -351,12 +363,19 @@ def remove(key, val, delimiter=DEFAULT_TARGET_DELIM):
|
|||
|
||||
Remove a value from a list in the grains config file
|
||||
|
||||
:param delimiter: The key can be a nested dict key. Use this parameter to
|
||||
key
|
||||
The grain key to remove.
|
||||
|
||||
val
|
||||
The value to remove.
|
||||
|
||||
delimiter
|
||||
The key can be a nested dict key. Use this parameter to
|
||||
specify the delimiter you use, instead of the default ``:``.
|
||||
You can now append values to a list in nested dictionary grains. If the
|
||||
list doesn't exist at this level, it will be created.
|
||||
|
||||
.. versionadded:: Boron
|
||||
.. versionadded:: 2015.8.2
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -387,7 +406,11 @@ def delval(key, destructive=False):
|
|||
|
||||
Delete a grain from the grains config file
|
||||
|
||||
:param destructive: Delete the key, too. Defaults to False.
|
||||
key
|
||||
The grain key from which to delete the value.
|
||||
|
||||
destructive
|
||||
Delete the key, too. Defaults to False.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@
|
|||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
|
||||
# Import Salt Libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
@ -24,6 +26,57 @@ from salttesting.helpers import ensure_in_syspath
|
|||
ensure_in_syspath('../../')
|
||||
|
||||
|
||||
class GrainsTargetingTest(integration.ShellCase):
|
||||
'''
|
||||
Integration tests for targeting with grains.
|
||||
'''
|
||||
|
||||
def test_grains_targeting_os_running(self):
|
||||
'''
|
||||
Tests running "salt -G 'os:<system-os>' test.ping and minions both return True
|
||||
'''
|
||||
test_ret = ['sub_minion:', ' True', 'minion:', ' True']
|
||||
|
||||
os_grain = ''
|
||||
for item in self.run_salt('minion grains.get os'):
|
||||
if item != 'minion:':
|
||||
os_grain = item.strip()
|
||||
|
||||
ret = self.run_salt('-G \'os:{0}\' test.ping'.format(os_grain))
|
||||
self.assertEqual(sorted(ret), sorted(test_ret))
|
||||
|
||||
def test_grains_targeting_minion_id_running(self):
|
||||
'''
|
||||
Tests return of each running test minion targeting with minion id grain
|
||||
'''
|
||||
minion = self.run_salt('-G \'id:minion\' test.ping')
|
||||
self.assertEqual(sorted(minion), sorted(['minion:', ' True']))
|
||||
|
||||
sub_minion = self.run_salt('-G \'id:sub_minion\' test.ping')
|
||||
self.assertEqual(sorted(sub_minion), sorted(['sub_minion:', ' True']))
|
||||
|
||||
def test_grains_targeting_disconnected(self):
|
||||
'''
|
||||
Tests return of minion using grains targeting on a disconnected minion.
|
||||
'''
|
||||
test_ret = 'Minion did not return. [Not connected]'
|
||||
|
||||
# Create a minion key, but do not start the "fake" minion. This mimics a
|
||||
# disconnected minion.
|
||||
key_file = os.path.join(self.master_opts['pki_dir'], 'minions', 'disconnected')
|
||||
salt.utils.fopen(key_file, 'a').close()
|
||||
|
||||
# ping disconnected minion and ensure it times out and returns with correct message
|
||||
try:
|
||||
ret = ''
|
||||
for item in self.run_salt('-G \'id:disconnected\' test.ping'):
|
||||
if item != 'disconnected:':
|
||||
ret = item.strip()
|
||||
self.assertEqual(ret, test_ret)
|
||||
finally:
|
||||
os.unlink(key_file)
|
||||
|
||||
|
||||
class SSHGrainsTest(integration.SSHCase):
|
||||
'''
|
||||
Test salt-ssh grains functionality
|
||||
|
|
Loading…
Add table
Reference in a new issue