mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #30189 from rallytime/bp-30185
Back-port #30185 to 2015.8
This commit is contained in:
commit
ad7522c98d
3 changed files with 58 additions and 13 deletions
|
@ -484,6 +484,11 @@ def highstate(test=None,
|
|||
"roots" of salt directories (with their own minion config, pillars,
|
||||
file_roots) to run highstate out of.
|
||||
|
||||
mock:
|
||||
The mock option allows for the state run to execute without actually
|
||||
calling any states. This then returns a mocked return which will show
|
||||
the requisite ordering as well as fully validate the state run.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -540,9 +545,16 @@ def highstate(test=None,
|
|||
opts['pillarenv'] = kwargs['pillarenv']
|
||||
|
||||
try:
|
||||
st_ = salt.state.HighState(opts, pillar, kwargs.get('__pub_jid'), proxy=__proxy__)
|
||||
st_ = salt.state.HighState(opts,
|
||||
pillar,
|
||||
kwargs.get('__pub_jid'),
|
||||
proxy=__proxy__,
|
||||
mocked=kwargs.get('mock', False))
|
||||
except NameError:
|
||||
st_ = salt.state.HighState(opts, pillar, kwargs.get('__pub_jid'))
|
||||
st_ = salt.state.HighState(opts,
|
||||
pillar,
|
||||
kwargs.get('__pub_jid'),
|
||||
mocked=kwargs.get('mock', False))
|
||||
|
||||
st_.push_active()
|
||||
try:
|
||||
|
@ -617,6 +629,11 @@ def sls(mods,
|
|||
"roots" of salt directories (with their own minion config, pillars,
|
||||
file_roots) to run highstate out of.
|
||||
|
||||
mock:
|
||||
The mock option allows for the state run to execute without actually
|
||||
calling any states. This then returns a mocked return which will show
|
||||
the requisite ordering as well as fully validate the state run.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -696,9 +713,16 @@ def sls(mods,
|
|||
)
|
||||
|
||||
try:
|
||||
st_ = salt.state.HighState(opts, pillar, kwargs.get('__pub_jid'), proxy=__proxy__)
|
||||
st_ = salt.state.HighState(opts,
|
||||
pillar,
|
||||
kwargs.get('__pub_jid'),
|
||||
proxy=__proxy__,
|
||||
mocked=kwargs.get('mock', False))
|
||||
except NameError:
|
||||
st_ = salt.state.HighState(opts, pillar, kwargs.get('__pub_jid'))
|
||||
st_ = salt.state.HighState(opts,
|
||||
pillar,
|
||||
kwargs.get('__pub_jid'),
|
||||
mocked=kwargs.get('mock', False))
|
||||
|
||||
umask = os.umask(0o77)
|
||||
if kwargs.get('cache'):
|
||||
|
|
|
@ -253,6 +253,23 @@ def ishashable(obj):
|
|||
return True
|
||||
|
||||
|
||||
def mock_ret(cdata):
|
||||
'''
|
||||
Returns a mocked return dict with information about the run, without
|
||||
executing the state function
|
||||
'''
|
||||
# As this is expanded it should be sent into the execution module
|
||||
# layer or it should be turned into a standalone loader system
|
||||
if cdata['args']:
|
||||
name = cdata['args'][0]
|
||||
else:
|
||||
name = cdata['kwargs']['name']
|
||||
return {'name': name,
|
||||
'comment': 'Not called, mocked',
|
||||
'changes': {},
|
||||
'result': True}
|
||||
|
||||
|
||||
class StateError(Exception):
|
||||
'''
|
||||
Custom exception class.
|
||||
|
@ -601,7 +618,7 @@ class State(object):
|
|||
'''
|
||||
Class used to execute salt states
|
||||
'''
|
||||
def __init__(self, opts, pillar=None, jid=None, proxy=None):
|
||||
def __init__(self, opts, pillar=None, jid=None, proxy=None, mocked=False):
|
||||
if 'grains' not in opts:
|
||||
opts['grains'] = salt.loader.grains(opts)
|
||||
self.opts = opts
|
||||
|
@ -616,6 +633,8 @@ class State(object):
|
|||
self.__run_num = 0
|
||||
self.jid = jid
|
||||
self.instance_id = str(id(self))
|
||||
self.inject_globals = {}
|
||||
self.mocked = mocked
|
||||
|
||||
def _gather_pillar(self):
|
||||
'''
|
||||
|
@ -1598,8 +1617,11 @@ class State(object):
|
|||
|
||||
if 'result' not in ret or ret['result'] is False:
|
||||
self.states.inject_globals = inject_globals
|
||||
ret = self.states[cdata['full']](*cdata['args'],
|
||||
**cdata['kwargs'])
|
||||
if self.mocked:
|
||||
ret = mock_ret(cdata)
|
||||
else:
|
||||
ret = self.states[cdata['full']](*cdata['args'],
|
||||
**cdata['kwargs'])
|
||||
self.states.inject_globals = {}
|
||||
if 'check_cmd' in low and '{0[state]}.mod_run_check_cmd'.format(low) not in self.states:
|
||||
ret.update(self._run_check_cmd(low))
|
||||
|
@ -3171,11 +3193,11 @@ class HighState(BaseHighState):
|
|||
# a stack of active HighState objects during a state.highstate run
|
||||
stack = []
|
||||
|
||||
def __init__(self, opts, pillar=None, jid=None, proxy=None):
|
||||
def __init__(self, opts, pillar=None, jid=None, proxy=None, mocked=False):
|
||||
self.opts = opts
|
||||
self.client = salt.fileclient.get_file_client(self.opts)
|
||||
BaseHighState.__init__(self, opts)
|
||||
self.state = State(self.opts, pillar, jid, proxy=proxy)
|
||||
self.state = State(self.opts, pillar, jid, proxy=proxy, mocked=mocked)
|
||||
self.matcher = salt.minion.Matcher(self.opts)
|
||||
|
||||
# tracks all pydsl state declarations globally across sls files
|
||||
|
|
|
@ -133,10 +133,9 @@ class MockState(object):
|
|||
flag = False
|
||||
opts = {'state_top': ""}
|
||||
|
||||
def __init__(self, opts, pillar=None, kwargs=None):
|
||||
pillar = pillar
|
||||
kwargs = kwargs
|
||||
self.state = MockState.State(opts)
|
||||
def __init__(self, opts, pillar=None, mocked=None):
|
||||
self.state = MockState.State(opts,
|
||||
pillar=pillar)
|
||||
|
||||
def render_state(self, sls, saltenv, mods, matches, local=False):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue