mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Need to move the creation of the proxy object for the ProxyMinion further down in the initialization for sub proxies to ensure that all modules, especially any custom proxy modules, are available before attempting to run the init function.
This commit is contained in:
parent
8a62217866
commit
85fab706c9
3 changed files with 142 additions and 4 deletions
1
changelog/61805.fixed
Normal file
1
changelog/61805.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Need to move the creation of the proxy object for the ProxyMinion further down in the initialization for sub proxies to ensure that all modules, especially any custom proxy modules, are available before attempting to run the init function.
|
|
@ -428,10 +428,6 @@ def subproxy_post_master_init(minion_id, uid, opts, main_proxy, main_utils):
|
|||
_proxy_minion = ProxyMinion(proxyopts)
|
||||
_proxy_minion.proc_dir = salt.minion.get_proc_dir(proxyopts["cachedir"], uid=uid)
|
||||
|
||||
_proxy_minion.proxy = salt.loader.proxy(
|
||||
proxyopts, utils=main_utils, context=proxy_context
|
||||
)
|
||||
|
||||
# And load the modules
|
||||
(
|
||||
_proxy_minion.functions,
|
||||
|
@ -461,6 +457,13 @@ def subproxy_post_master_init(minion_id, uid, opts, main_proxy, main_utils):
|
|||
context=proxy_context,
|
||||
)
|
||||
|
||||
# Create this after modules are synced to ensure
|
||||
# any custom modules, eg. custom proxy modules
|
||||
# are avaiable.
|
||||
_proxy_minion.proxy = salt.loader.proxy(
|
||||
proxyopts, utils=main_utils, context=proxy_context
|
||||
)
|
||||
|
||||
_proxy_minion.functions.pack["__proxy__"] = _proxy_minion.proxy
|
||||
_proxy_minion.proxy.pack["__salt__"] = _proxy_minion.functions
|
||||
_proxy_minion.proxy.pack["__ret__"] = _proxy_minion.returners
|
||||
|
|
|
@ -452,3 +452,137 @@ def test_invalid_connection(
|
|||
|
||||
assert not factory.is_running()
|
||||
assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
|
||||
@pytest.mark.parametrize(
|
||||
"parallel_startup",
|
||||
[True, False],
|
||||
ids=["parallel_startup=True", "parallel_startup=False"],
|
||||
)
|
||||
def test_custom_proxy_module(
|
||||
salt_master,
|
||||
salt_cli,
|
||||
proxy_minion_id,
|
||||
parallel_startup,
|
||||
integration_files_dir,
|
||||
):
|
||||
"""
|
||||
Ensure the salt-proxy control proxy starts and
|
||||
is able to respond to test.ping, additionally ensure that
|
||||
the proxies being controlled also respond to test.ping.
|
||||
|
||||
Finally ensure correct exit status when salt-proxy exits correctly.
|
||||
|
||||
Skip on Windows because daemonization not supported
|
||||
"""
|
||||
|
||||
config_defaults = {
|
||||
"metaproxy": "deltaproxy",
|
||||
}
|
||||
proxy_one = "custom_dummy_proxy_one"
|
||||
proxy_two = "custom_dummy_proxy_two"
|
||||
|
||||
top_file = """
|
||||
base:
|
||||
{control}:
|
||||
- controlproxy
|
||||
{one}:
|
||||
- {one}
|
||||
{two}:
|
||||
- {two}
|
||||
""".format(
|
||||
control=proxy_minion_id,
|
||||
one=proxy_one,
|
||||
two=proxy_two,
|
||||
)
|
||||
controlproxy_pillar_file = """
|
||||
proxy:
|
||||
proxytype: deltaproxy
|
||||
parallel_startup: {}
|
||||
ids:
|
||||
- {}
|
||||
- {}
|
||||
""".format(
|
||||
parallel_startup, proxy_one, proxy_two
|
||||
)
|
||||
|
||||
dummy_proxy_one_pillar_file = """
|
||||
proxy:
|
||||
proxytype: custom_dummy
|
||||
"""
|
||||
|
||||
dummy_proxy_two_pillar_file = """
|
||||
proxy:
|
||||
proxytype: custom_dummy
|
||||
"""
|
||||
|
||||
module_contents = """
|
||||
__proxyenabled__ = ["custom_dummy"]
|
||||
|
||||
def __virtual__():
|
||||
return True
|
||||
|
||||
def init(opts):
|
||||
return True
|
||||
|
||||
def ping():
|
||||
return True
|
||||
"""
|
||||
|
||||
top_tempfile = salt_master.pillar_tree.base.temp_file("top.sls", top_file)
|
||||
controlproxy_tempfile = salt_master.pillar_tree.base.temp_file(
|
||||
"controlproxy.sls", controlproxy_pillar_file
|
||||
)
|
||||
dummy_proxy_one_tempfile = salt_master.pillar_tree.base.temp_file(
|
||||
"{}.sls".format(proxy_one),
|
||||
dummy_proxy_one_pillar_file,
|
||||
)
|
||||
dummy_proxy_two_tempfile = salt_master.pillar_tree.base.temp_file(
|
||||
"{}.sls".format(proxy_two),
|
||||
dummy_proxy_two_pillar_file,
|
||||
)
|
||||
|
||||
custom_proxy_module = salt_master.state_tree.base.temp_file(
|
||||
"_proxy/custom_dummy.py", module_contents
|
||||
)
|
||||
with top_tempfile, controlproxy_tempfile, dummy_proxy_one_tempfile, dummy_proxy_two_tempfile, custom_proxy_module:
|
||||
factory = salt_master.salt_proxy_minion_daemon(
|
||||
proxy_minion_id,
|
||||
defaults=config_defaults,
|
||||
extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
|
||||
start_timeout=240,
|
||||
)
|
||||
|
||||
for minion_id in (proxy_minion_id, proxy_one, proxy_two):
|
||||
factory.before_start(
|
||||
pytest.helpers.remove_stale_proxy_minion_cache_file, factory, minion_id
|
||||
)
|
||||
factory.after_terminate(
|
||||
pytest.helpers.remove_stale_minion_key, salt_master, minion_id
|
||||
)
|
||||
factory.after_terminate(
|
||||
pytest.helpers.remove_stale_proxy_minion_cache_file, factory, minion_id
|
||||
)
|
||||
|
||||
with factory.started():
|
||||
assert factory.is_running()
|
||||
|
||||
# Let's issue a ping the control proxy
|
||||
ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
||||
# Let's issue a ping to one of the controlled proxies
|
||||
ret = salt_cli.run("test.ping", minion_tgt=proxy_one)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
||||
# Let's issue a ping to one of the controlled proxies
|
||||
ret = salt_cli.run("test.ping", minion_tgt=proxy_two)
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
||||
# Terminate the proxy minion
|
||||
ret = factory.terminate()
|
||||
assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
|
||||
|
|
Loading…
Add table
Reference in a new issue