def test_get_policies_for_nonexisting_minions(self): minion_id = 'salt_master' # For non-existing minions, or the master-minion, grains will be None cases = { 'no-tokens-to-replace': ['no-tokens-to-replace'], 'single-dict:{minion}': ['single-dict:{0}'.format(minion_id)], 'single-list:{grains[roles]}': [] } with patch('salt.utils.minions.get_minion_data', MagicMock(return_value=(None, None, None))): for case, correct_output in six.iteritems(cases): test_config = {'policies': [case]} output = vault._get_policies(minion_id, test_config) # pylint: disable=protected-access diff = set(output).symmetric_difference(set(correct_output)) if diff: log.debug('Test %s failed', case) log.debug('Expected:\n\t%s\nGot\n\t%s', output, correct_output) log.debug('Difference:\n\t%s', diff) self.assertEqual(output, correct_output)
def test_get_policies(self): """ Ensure _get_policies works as intended, including expansion of lists """ cases = { "no-tokens-to-replace": ["no-tokens-to-replace"], "single-dict:{minion}": ["single-dict:test-minion"], "single-list:{grains[roles]}": ["single-list:web", "single-list:database"], "multiple-lists:{grains[roles]}+{grains[aux]}": [ "multiple-lists:web+foo", "multiple-lists:web+bar", "multiple-lists:database+foo", "multiple-lists:database+bar", ], "single-list-with-dicts:{grains[id]}+{grains[roles]}+{grains[id]}": [ "single-list-with-dicts:test-minion+web+test-minion", "single-list-with-dicts:test-minion+database+test-minion", ], "deeply-nested-list:{grains[deep][foo][bar][baz]}": [ "deeply-nested-list:hello", "deeply-nested-list:world", ], "should-not-cause-an-exception,but-result-empty:{foo}": [], "Case-Should-Be-Lowered:{grains[mixedcase]}": ["case-should-be-lowered:up-low-up"], } with patch( "salt.utils.minions.get_minion_data", MagicMock(return_value=(None, self.grains, None)), ): for case, correct_output in cases.items(): test_config = {"policies": [case]} output = vault._get_policies("test-minion", test_config) # pylint: disable=protected-access diff = set(output).symmetric_difference(set(correct_output)) if diff: log.debug("Test %s failed", case) log.debug("Expected:\n\t%s\nGot\n\t%s", output, correct_output) log.debug("Difference:\n\t%s", diff) self.assertEqual(output, correct_output)
def test_get_policies(self): ''' Ensure _get_policies works as intended, including expansion of lists ''' cases = { 'no-tokens-to-replace': ['no-tokens-to-replace'], 'single-dict:{minion}': ['single-dict:test-minion'], 'single-list:{grains[roles]}': ['single-list:web', 'single-list:database'], 'multiple-lists:{grains[roles]}+{grains[aux]}': [ 'multiple-lists:web+foo', 'multiple-lists:web+bar', 'multiple-lists:database+foo', 'multiple-lists:database+bar', ], 'single-list-with-dicts:{grains[id]}+{grains[roles]}+{grains[id]}': [ 'single-list-with-dicts:test-minion+web+test-minion', 'single-list-with-dicts:test-minion+database+test-minion' ], 'deeply-nested-list:{grains[deep][foo][bar][baz]}': ['deeply-nested-list:hello', 'deeply-nested-list:world'], 'should-not-cause-an-exception,but-result-empty:{foo}': [], 'Case-Should-Be-Lowered:{grains[mixedcase]}': ['case-should-be-lowered:up-low-up'] } with patch('salt.utils.minions.get_minion_data', MagicMock(return_value=(None, self.grains, None))): for case, correct_output in six.iteritems(cases): test_config = {'policies': [case]} output = vault._get_policies('test-minion', test_config) # pylint: disable=protected-access diff = set(output).symmetric_difference(set(correct_output)) if len(diff) != 0: log.debug('Test {0} failed'.format(case)) log.debug('Expected:\n\t{0}\nGot\n\t{1}'.format( output, correct_output)) log.debug('Difference:\n\t{0}'.format(diff)) self.assertEqual(output, correct_output)
def test_get_policies_for_nonexisting_minions(self): minion_id = "salt_master" # For non-existing minions, or the master-minion, grains will be None cases = { "no-tokens-to-replace": ["no-tokens-to-replace"], "single-dict:{minion}": ["single-dict:{}".format(minion_id)], "single-list:{grains[roles]}": [], } with patch( "salt.utils.minions.get_minion_data", MagicMock(return_value=(None, None, None)), ): for case, correct_output in cases.items(): test_config = {"policies": [case]} output = vault._get_policies(minion_id, test_config) # pylint: disable=protected-access diff = set(output).symmetric_difference(set(correct_output)) if diff: log.debug("Test %s failed", case) log.debug("Expected:\n\t%s\nGot\n\t%s", output, correct_output) log.debug("Difference:\n\t%s", diff) self.assertEqual(output, correct_output)