mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Explicity pass context for salt-ssh highstate
This commit is contained in:
parent
92ce21d300
commit
dec1b83482
3 changed files with 25 additions and 11 deletions
|
@ -682,7 +682,7 @@ def highstate(test=None, **kwargs):
|
|||
context=__context__.value(),
|
||||
) as st_:
|
||||
st_.push_active()
|
||||
chunks = st_.compile_low_chunks()
|
||||
chunks = st_.compile_low_chunks(context=__context__.value())
|
||||
file_refs = salt.client.ssh.state.lowstate_file_refs(
|
||||
chunks,
|
||||
_merge_extra_filerefs(
|
||||
|
@ -1070,7 +1070,7 @@ def show_top(**kwargs):
|
|||
__context__["fileclient"],
|
||||
context=__context__.value(),
|
||||
) as st_:
|
||||
top_data = st_.get_top()
|
||||
top_data = st_.get_top(context=__context__)
|
||||
errors = []
|
||||
errors += st_.verify_tops(top_data)
|
||||
if errors:
|
||||
|
|
|
@ -3775,7 +3775,7 @@ class BaseHighState:
|
|||
envs.extend([env for env in client_envs if env not in envs])
|
||||
return envs
|
||||
|
||||
def get_tops(self):
|
||||
def get_tops(self, context=None):
|
||||
"""
|
||||
Gather the top files
|
||||
"""
|
||||
|
@ -3806,6 +3806,7 @@ class BaseHighState:
|
|||
self.state.opts["renderer_blacklist"],
|
||||
self.state.opts["renderer_whitelist"],
|
||||
saltenv=self.opts["saltenv"],
|
||||
context=context,
|
||||
)
|
||||
]
|
||||
else:
|
||||
|
@ -3831,6 +3832,7 @@ class BaseHighState:
|
|||
self.state.opts["renderer_blacklist"],
|
||||
self.state.opts["renderer_whitelist"],
|
||||
saltenv=saltenv,
|
||||
context=context,
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
@ -3887,6 +3889,7 @@ class BaseHighState:
|
|||
self.state.opts["renderer_blacklist"],
|
||||
self.state.opts["renderer_whitelist"],
|
||||
saltenv,
|
||||
context=context,
|
||||
)
|
||||
)
|
||||
done[saltenv].append(sls)
|
||||
|
@ -4137,12 +4140,12 @@ class BaseHighState:
|
|||
|
||||
return errors
|
||||
|
||||
def get_top(self):
|
||||
def get_top(self, context=None):
|
||||
"""
|
||||
Returns the high data derived from the top file
|
||||
"""
|
||||
try:
|
||||
tops = self.get_tops()
|
||||
tops = self.get_tops(context=context)
|
||||
except SaltRenderError as err:
|
||||
log.error("Unable to render top file: %s", err.error)
|
||||
return {}
|
||||
|
@ -4379,7 +4382,11 @@ class BaseHighState:
|
|||
mod_tgt = "{}:{}".format(r_env, sls_target)
|
||||
if mod_tgt not in mods:
|
||||
nstate, err = self.render_state(
|
||||
sls_target, r_env, mods, matches
|
||||
sls_target,
|
||||
r_env,
|
||||
mods,
|
||||
matches,
|
||||
context=context,
|
||||
)
|
||||
if nstate:
|
||||
self.merge_included_states(state, nstate, errors)
|
||||
|
@ -4777,14 +4784,14 @@ class BaseHighState:
|
|||
|
||||
return high
|
||||
|
||||
def compile_low_chunks(self):
|
||||
def compile_low_chunks(self, context=None):
|
||||
"""
|
||||
Compile the highstate but don't run it, return the low chunks to
|
||||
see exactly what the highstate will execute
|
||||
"""
|
||||
top = self.get_top()
|
||||
top = self.get_top(context=context)
|
||||
matches = self.top_matches(top)
|
||||
high, errors = self.render_highstate(matches)
|
||||
high, errors = self.render_highstate(matches, context=context)
|
||||
|
||||
# If there is extension data reconcile it
|
||||
high, ext_errors = self.state.reconcile_extend(high)
|
||||
|
|
|
@ -10,6 +10,7 @@ pytestmark = [
|
|||
@pytest.fixture(scope="module")
|
||||
def state_tree(base_env_state_tree_root_dir):
|
||||
top_file = """
|
||||
{%- from "map.jinja" import abc with context %}
|
||||
base:
|
||||
'localhost':
|
||||
- basic
|
||||
|
@ -39,12 +40,18 @@ def state_tree(base_env_state_tree_root_dir):
|
|||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ssh_cmd", ["state.sls", "state.highstate", "state.apply", "state.show_top"]
|
||||
)
|
||||
@pytest.mark.slow_test
|
||||
def test_state_with_import(salt_ssh_cli, state_tree):
|
||||
def test_state_with_import(salt_ssh_cli, state_tree, ssh_cmd):
|
||||
"""
|
||||
verify salt-ssh can use imported map files in states
|
||||
"""
|
||||
ret = salt_ssh_cli.run("state.sls", "test")
|
||||
if ssh_cmd == "state.sls":
|
||||
ret = salt_ssh_cli.run(ssh_cmd, "test")
|
||||
else:
|
||||
ret = salt_ssh_cli.run(ssh_cmd)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue