mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #40522 from carlpett/vault-fix-master-minion
Salt-vault: Fix handling of None-grains
This commit is contained in:
commit
778c1c94bd
@ -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:
|
||||
|
@ -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):
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user