Merge pull request #40522 from carlpett/vault-fix-master-minion

Salt-vault: Fix handling of None-grains
This commit is contained in:
Mike Place 2017-04-04 13:33:56 -06:00 committed by GitHub
commit 778c1c94bd
2 changed files with 22 additions and 6 deletions

View File

@ -114,7 +114,7 @@ def _get_policies(minion_id, config):
'policies',
['saltstack/minion/{minion}', 'saltstack/minions']
)
mappings = {'minion': minion_id, 'grains': grains}
mappings = {'minion': minion_id, 'grains': grains or {}}
policies = []
for pattern in policy_patterns:

View File

@ -47,11 +47,7 @@ class VaultTest(TestCase, LoaderModuleMockMixin):
}
}
},
'mixedcase': 'UP-low-UP',
'dictlist': [
{'foo': 'bar'},
{'baz': 'qux'}
]
'mixedcase': 'UP-low-UP'
}
def tearDown(self):
@ -94,6 +90,26 @@ class VaultTest(TestCase, LoaderModuleMockMixin):
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:{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 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)
@skipIf(NO_MOCK, NO_MOCK_REASON)
def test_get_policies(self):
'''