loader test for custom grains

This commit is contained in:
Christophe Drevet-Droguet 2015-10-31 20:43:17 +01:00
parent af6d37caaf
commit f13e9435b1
4 changed files with 57 additions and 1 deletions

View File

@ -765,7 +765,8 @@ class TestDaemon(object):
if sync_needed:
# Wait for minions to "sync_all"
for target in [self.sync_minion_modules,
self.sync_minion_states]:
self.sync_minion_states,
self.sync_minion_grains]:
sync_minions = MultiprocessingProcess(
target=target,
args=(self.minion_targets, self.MINIONS_SYNC_TIMEOUT)
@ -1021,6 +1022,9 @@ class TestDaemon(object):
salt.utils.appendproctitle('SyncMinionModules')
self.sync_minion_modules_('modules', targets, timeout=timeout)
def sync_minion_grains(self, targets, timeout=None):
self.sync_minion_modules_('grains', targets, timeout=timeout)
class AdaptedConfigurationTestCaseMixIn(object):

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python
def myfunction():
grains = {}
grains['a_custom'] = {'k1': 'v1'}
return grains

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python
def myfunction():
grains = {}
grains['a_custom'] = {'k2': 'v2'}
return grains

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
'''
integration.loader.ext_grains
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test Salt's loader regarding external grains
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../')
# Import salt libs
import integration
from salt.config import minion_config
from salt.loader import grains
class LoaderGrainsTest(integration.ModuleCase):
'''
Test the loader standard behavior with external grains
'''
def setUp(self):
self.opts = minion_config(None)
self.opts['disable_modules'] = ['pillar']
self.opts['grains'] = grains(self.opts)
def test_grains_overwrite(self):
grains = self.run_function('grains.items')
# Check that custom grains are overwritten
self.assertEqual({'k2': 'v2'}, grains['a_custom'])
if __name__ == '__main__':
from integration import run_tests
run_tests(LoaderGrainsTest)