2012-02-14 18:00:35 +00:00
|
|
|
'''
|
|
|
|
Test the grains module
|
|
|
|
'''
|
2012-05-05 14:09:23 +00:00
|
|
|
# Import python libs
|
|
|
|
import sys
|
2012-02-14 18:00:35 +00:00
|
|
|
|
2012-05-05 14:09:23 +00:00
|
|
|
# Import salt libs
|
|
|
|
from saltunittest import TestLoader, TextTestRunner
|
2012-02-20 12:18:13 +00:00
|
|
|
import integration
|
2012-05-05 14:09:23 +00:00
|
|
|
from integration import TestDaemon
|
|
|
|
|
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
|
|
|
|
'''
|
|
|
|
opts = self.minion_opts()
|
|
|
|
self.assertEqual(self.run_function('grains.items')['test_grain'], opts['grains']['test_grain'])
|
|
|
|
|
|
|
|
def test_item(self):
|
|
|
|
'''
|
|
|
|
grains.item
|
|
|
|
'''
|
|
|
|
opts = self.minion_opts()
|
|
|
|
self.assertEqual(self.run_function('grains.item', ['test_grain']), opts['grains']['test_grain'])
|
|
|
|
|
|
|
|
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',
|
|
|
|
'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
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
loader = TestLoader()
|
|
|
|
tests = loader.loadTestsFromTestCase(TestModulesGrains)
|
|
|
|
print('Setting up Salt daemons to execute tests')
|
|
|
|
with TestDaemon():
|
|
|
|
runner = TextTestRunner(verbosity=1).run(tests)
|
|
|
|
sys.exit(runner.wasSuccessful())
|