Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deltaproxy Custom Proxy Modules #63084

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/61805.fixed
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 7 additions & 4 deletions salt/metaproxy/deltaproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
134 changes: 134 additions & 0 deletions tests/pytests/integration/cli/test_salt_deltaproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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