From f13e9435b1b14522e8e1a5fcd6d1f290b33d5616 Mon Sep 17 00:00:00 2001 From: Christophe Drevet-Droguet Date: Sat, 31 Oct 2015 20:43:17 +0100 Subject: [PATCH] loader test for custom grains --- tests/integration/__init__.py | 6 ++- .../file/base/_grains/test_custom_grain1.py | 5 +++ .../file/base/_grains/test_custom_grain2.py | 5 +++ tests/integration/loader/ext_grains.py | 42 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/integration/files/file/base/_grains/test_custom_grain1.py create mode 100644 tests/integration/files/file/base/_grains/test_custom_grain2.py create mode 100644 tests/integration/loader/ext_grains.py diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 79ba2dd8bf..39d2213c51 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -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): diff --git a/tests/integration/files/file/base/_grains/test_custom_grain1.py b/tests/integration/files/file/base/_grains/test_custom_grain1.py new file mode 100644 index 0000000000..983ca95ee3 --- /dev/null +++ b/tests/integration/files/file/base/_grains/test_custom_grain1.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +def myfunction(): + grains = {} + grains['a_custom'] = {'k1': 'v1'} + return grains diff --git a/tests/integration/files/file/base/_grains/test_custom_grain2.py b/tests/integration/files/file/base/_grains/test_custom_grain2.py new file mode 100644 index 0000000000..239b8f3cb7 --- /dev/null +++ b/tests/integration/files/file/base/_grains/test_custom_grain2.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +def myfunction(): + grains = {} + grains['a_custom'] = {'k2': 'v2'} + return grains diff --git a/tests/integration/loader/ext_grains.py b/tests/integration/loader/ext_grains.py new file mode 100644 index 0000000000..6a3c227421 --- /dev/null +++ b/tests/integration/loader/ext_grains.py @@ -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)