mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Backported issue #42713 to 2017.7
Cherry-picked and squashed the two commits from the develop branch (details at the end of this message) The unit test module didn't exist at all on 2017.7, hence a conflict during cherry picking, resolved by introducing only the new tests (the other ones don't pass as is on 2017.7) Also, the mock in unit tests for mine.get had to be adapted, because the return of salt.utils.minions.CkMinions._check_compound_minions() takes a different form on 2017.7 (just the list of minions). Original cherry-picked commits: commit 115ebef6a089dedf8dbadd3b4cca768adbb4a710 Author: Georges Racinet <gracinet@anybox.fr> Date: Wed Nov 8 18:02:29 2017 +0100 Unit test for backwards compatibility of mine.get Could not find calls to RemoteFuncs in unit tests, therefore started a new one, hope it's in the appropriate place. The test replaces the caceh by its own (very limited) one. It's quite possible it could be improved by reusing another one meant for unit tests. commit dc884478399355f3fbea8626a8366b933580dee0 Author: Georges Racinet <gracinet@anybox.fr> Date: Mon Oct 30 13:49:13 2017 +0100 Backwards compat for mine.get on pre-Nitrogen minions With this change, the master will accept `expr_form` from its minions doing a `mine.get`, which is what minions versions before Nitrogen would do. This solves issue #42713. In case both `tgt_type` and `expr_form` are present, the former gets precedence. Performance-wise, this adds a single dict lookup for minions running Nitrogen onwards, and two for pre-Nitrogen minions. This is, in my opinion, acceptable.
This commit is contained in:
parent
642eed11e1
commit
fb586c6dce
2 changed files with 81 additions and 1 deletions
|
@ -586,7 +586,18 @@ class RemoteFuncs(object):
|
|||
ret = {}
|
||||
if not salt.utils.verify.valid_id(self.opts, load['id']):
|
||||
return ret
|
||||
match_type = load.get('tgt_type', 'glob')
|
||||
expr_form = load.get('expr_form')
|
||||
if expr_form is not None and 'tgt_type' not in load:
|
||||
salt.utils.warn_until(
|
||||
u'Neon',
|
||||
u'_mine_get: minion {0} uses pre-Nitrogen API key '
|
||||
u'"expr_form". Accepting for backwards compatibility '
|
||||
u'but this is not guaranteed '
|
||||
u'after the Neon release'.format(load['id'])
|
||||
)
|
||||
match_type = expr_form
|
||||
else:
|
||||
match_type = load.get('tgt_type', 'glob')
|
||||
if match_type.lower() == 'pillar':
|
||||
match_type = 'pillar_exact'
|
||||
if match_type.lower() == 'compound':
|
||||
|
|
69
tests/unit/daemons/test_masterapi.py
Normal file
69
tests/unit/daemons/test_masterapi.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt libs
|
||||
import salt.config
|
||||
import salt.daemons.masterapi as masterapi
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.mock import (
|
||||
patch,
|
||||
MagicMock,
|
||||
)
|
||||
|
||||
|
||||
class FakeCache(object):
|
||||
|
||||
def __init__(self):
|
||||
self.data = {}
|
||||
|
||||
def store(self, bank, key, value):
|
||||
self.data[bank, key] = value
|
||||
|
||||
def fetch(self, bank, key):
|
||||
return self.data[bank, key]
|
||||
|
||||
|
||||
class RemoteFuncsTestCase(TestCase):
|
||||
'''
|
||||
TestCase for salt.daemons.masterapi.RemoteFuncs class
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
opts = salt.config.master_config(None)
|
||||
self.funcs = masterapi.RemoteFuncs(opts)
|
||||
self.funcs.cache = FakeCache()
|
||||
|
||||
def test_mine_get(self, tgt_type_key='tgt_type'):
|
||||
'''
|
||||
Asserts that ``mine_get`` gives the expected results.
|
||||
|
||||
Actually this only tests that:
|
||||
|
||||
- the correct check minions method is called
|
||||
- the correct cache key is subsequently used
|
||||
'''
|
||||
self.funcs.cache.store('minions/webserver', 'mine',
|
||||
dict(ip_addr='2001:db8::1:3'))
|
||||
with patch('salt.utils.minions.CkMinions._check_compound_minions',
|
||||
MagicMock(return_value=['webserver'])):
|
||||
ret = self.funcs._mine_get(
|
||||
{
|
||||
'id': 'requester_minion',
|
||||
'tgt': 'G@roles:web',
|
||||
'fun': 'ip_addr',
|
||||
tgt_type_key: 'compound',
|
||||
}
|
||||
)
|
||||
self.assertDictEqual(ret, dict(webserver='2001:db8::1:3'))
|
||||
|
||||
def test_mine_get_pre_nitrogen_compat(self):
|
||||
'''
|
||||
Asserts that pre-Nitrogen API key ``expr_form`` is still accepted.
|
||||
|
||||
This is what minions before Nitrogen would issue.
|
||||
'''
|
||||
self.test_mine_get(tgt_type_key='expr_form')
|
Loading…
Add table
Reference in a new issue