Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:FrontRunner
salt.24747
state.orchestrate_single-does-not-pass-pillar-n...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File state.orchestrate_single-does-not-pass-pillar-none-4.patch of Package salt.24747
From d44207dc209894b36f2a2c8af4c81afcd86b4625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= <psuarezhernandez@suse.com> Date: Wed, 9 Feb 2022 09:01:08 +0000 Subject: [PATCH] state.orchestrate_single does not pass pillar=None (#488) Passing a pillar to state.single can results in state functions not working when they don't accept a pillar keyword argument. One example where this is the case is salt.wait_for_event. When no pillar is provided, it does not need to be passed. Co-authored-by: Alexander Graul <agraul@suse.com> --- changelog/61092.fixed | 3 ++ salt/runners/state.py | 10 ++++-- tests/pytests/unit/runners/test_state.py | 41 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 changelog/61092.fixed create mode 100644 tests/pytests/unit/runners/test_state.py diff --git a/changelog/61092.fixed b/changelog/61092.fixed new file mode 100644 index 0000000000..6ca66839c9 --- /dev/null +++ b/changelog/61092.fixed @@ -0,0 +1,3 @@ +state.orchestrate_single only passes a pillar if it is set to the state +function. This allows it to be used with state functions that don't accept a +pillar keyword argument. diff --git a/salt/runners/state.py b/salt/runners/state.py index f8fc1b0944..5642204ce9 100644 --- a/salt/runners/state.py +++ b/salt/runners/state.py @@ -150,12 +150,16 @@ def orchestrate_single(fun, name, test=None, queue=False, pillar=None, **kwargs) salt-run state.orchestrate_single fun=salt.wheel name=key.list_all """ - if pillar is not None and not isinstance(pillar, dict): - raise SaltInvocationError("Pillar data must be formatted as a dictionary") + if pillar is not None: + if isinstance(pillar, dict): + kwargs["pillar"] = pillar + else: + raise SaltInvocationError("Pillar data must be formatted as a dictionary") + __opts__["file_client"] = "local" minion = salt.minion.MasterMinion(__opts__) running = minion.functions["state.single"]( - fun, name, test=None, queue=False, pillar=pillar, **kwargs + fun, name, test=None, queue=False, **kwargs ) ret = {minion.opts["id"]: running} __jid_event__.fire_event({"data": ret, "outputter": "highstate"}, "progress") diff --git a/tests/pytests/unit/runners/test_state.py b/tests/pytests/unit/runners/test_state.py new file mode 100644 index 0000000000..df0a718a41 --- /dev/null +++ b/tests/pytests/unit/runners/test_state.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +import pytest +from salt.runners import state as state_runner +from tests.support.mock import Mock, patch + + +@pytest.fixture +def configure_loader_modules(): + return {state_runner: {"__opts__": {}, "__jid_event__": Mock()}} + + +def test_orchestrate_single_passes_pillar(): + """ + test state.orchestrate_single passes given pillar to state.single + """ + mock_master_minion = Mock() + mock_state_single = Mock() + mock_master_minion.functions = {"state.single": mock_state_single} + mock_master_minion.opts = {"id": "dummy"} + test_pillar = {"test_entry": "exists"} + with patch("salt.minion.MasterMinion", Mock(return_value=mock_master_minion)): + state_runner.orchestrate_single( + fun="pillar.get", name="test_entry", pillar=test_pillar + ) + assert mock_state_single.call_args.kwargs["pillar"] == test_pillar + + +def test_orchestrate_single_does_not_pass_none_pillar(): + """ + test state.orchestrate_single does not pass pillar=None to state.single + """ + mock_master_minion = Mock() + mock_state_single = Mock() + mock_master_minion.functions = {"state.single": mock_state_single} + mock_master_minion.opts = {"id": "dummy"} + with patch("salt.minion.MasterMinion", Mock(return_value=mock_master_minion)): + state_runner.orchestrate_single( + fun="pillar.get", name="test_entry", pillar=None + ) + assert "pillar" not in mock_state_single.call_args.kwargs -- 2.35.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor