2012-02-14 18:00:35 +00:00
|
|
|
'''
|
|
|
|
Test the grains module
|
|
|
|
'''
|
2013-05-29 06:12:30 +00:00
|
|
|
# Import python libs
|
|
|
|
import time
|
2013-06-20 04:45:26 +00:00
|
|
|
import os
|
2013-05-29 06:12:30 +00:00
|
|
|
|
|
|
|
# Import salt libs
|
2013-06-24 19:06:49 +00:00
|
|
|
try:
|
|
|
|
import integration
|
|
|
|
except ImportError:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
sys.path.insert(
|
|
|
|
0, os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__), '../../'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import integration
|
|
|
|
from salttesting import skipIf
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2012-02-14 18:00:35 +00:00
|
|
|
|
2012-02-20 12:18:13 +00:00
|
|
|
class TestModulesGrains(integration.ModuleCase):
|
2012-02-14 18:00:35 +00:00
|
|
|
'''
|
|
|
|
Test the grains module
|
|
|
|
'''
|
|
|
|
def test_items(self):
|
|
|
|
'''
|
|
|
|
grains.items
|
|
|
|
'''
|
2012-06-30 20:54:23 +00:00
|
|
|
opts = self.minion_opts
|
2012-06-30 20:10:34 +00:00
|
|
|
self.assertEqual(
|
|
|
|
self.run_function('grains.items')['test_grain'],
|
|
|
|
opts['grains']['test_grain']
|
|
|
|
)
|
2012-02-14 18:00:35 +00:00
|
|
|
|
|
|
|
def test_item(self):
|
|
|
|
'''
|
|
|
|
grains.item
|
|
|
|
'''
|
2012-06-30 20:54:23 +00:00
|
|
|
opts = self.minion_opts
|
2012-06-30 20:10:34 +00:00
|
|
|
self.assertEqual(
|
2013-01-23 23:00:19 +00:00
|
|
|
self.run_function('grains.item', ['test_grain'])['test_grain'],
|
2012-06-30 20:10:34 +00:00
|
|
|
opts['grains']['test_grain']
|
|
|
|
)
|
2012-02-14 18:00:35 +00:00
|
|
|
|
|
|
|
def test_ls(self):
|
|
|
|
'''
|
|
|
|
grains.ls
|
|
|
|
'''
|
2012-05-10 04:39:49 +00:00
|
|
|
check_for = (
|
|
|
|
'cpuarch',
|
|
|
|
'cpu_flags',
|
|
|
|
'cpu_model',
|
|
|
|
'domain',
|
|
|
|
'fqdn',
|
|
|
|
'host',
|
|
|
|
'kernel',
|
|
|
|
'kernelrelease',
|
|
|
|
'localhost',
|
|
|
|
'mem_total',
|
|
|
|
'num_cpus',
|
|
|
|
'os',
|
2012-08-15 00:59:03 +00:00
|
|
|
'os_family',
|
2012-05-10 04:39:49 +00:00
|
|
|
'path',
|
|
|
|
'ps',
|
|
|
|
'pythonpath',
|
|
|
|
'pythonversion',
|
|
|
|
'saltpath',
|
|
|
|
'saltversion',
|
|
|
|
'virtual',
|
|
|
|
)
|
2012-02-14 18:00:35 +00:00
|
|
|
lsgrains = self.run_function('grains.ls')
|
2012-05-10 04:39:49 +00:00
|
|
|
for grain_name in check_for:
|
|
|
|
self.assertTrue(grain_name in lsgrains)
|
2012-05-05 14:09:23 +00:00
|
|
|
|
2013-06-20 04:28:53 +00:00
|
|
|
@skipIf(os.environ.get('TRAVIS_PYTHON_VERSION', None) is not None,
|
|
|
|
'Travis environment can\'t keep up with salt refresh')
|
2013-05-26 10:11:42 +00:00
|
|
|
def test_set_val(self):
|
|
|
|
'''
|
|
|
|
test grains.set_val
|
|
|
|
'''
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function(
|
|
|
|
'grains.setval',
|
|
|
|
['setgrain', 'grainval']),
|
|
|
|
{'setgrain': 'grainval'})
|
2013-06-20 04:28:53 +00:00
|
|
|
time.sleep(1)
|
2013-05-26 10:11:42 +00:00
|
|
|
self.assertTrue(
|
|
|
|
self.run_function(
|
|
|
|
'grains.item', ['setgrain']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-05-26 12:11:59 +00:00
|
|
|
def test_get(self):
|
|
|
|
'''
|
|
|
|
test grains.get
|
|
|
|
'''
|
|
|
|
self.assertEqual(
|
|
|
|
self.run_function(
|
|
|
|
'grains.get',
|
|
|
|
['level1:level2']),
|
|
|
|
'foo')
|
|
|
|
|
2013-05-26 10:11:42 +00:00
|
|
|
|
2012-07-20 06:21:01 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestModulesGrains)
|