From 31870fdaee8c3bcdcc5b467ef92ddbe275a1c785 Mon Sep 17 00:00:00 2001 From: Max Arnold Date: Fri, 21 Feb 2020 18:27:43 +0700 Subject: [PATCH 1/2] Make slots work with parallel=true --- salt/state.py | 1 + tests/unit/test_state.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/salt/state.py b/salt/state.py index 588bc85fb4dc..2f1fb4e57dbc 100644 --- a/salt/state.py +++ b/salt/state.py @@ -1906,6 +1906,7 @@ def _call_parallel_target(self, name, cdata, low): # correctly calculate further down the chain utc_start_time = datetime.datetime.utcnow() + self.format_slots(cdata) tag = _gen_tag(low) try: ret = self.states[cdata["full"]](*cdata["args"], **cdata["kwargs"]) diff --git a/tests/unit/test_state.py b/tests/unit/test_state.py index f5748af5948e..2d0e750f7241 100644 --- a/tests/unit/test_state.py +++ b/tests/unit/test_state.py @@ -618,3 +618,26 @@ def test_slot_append(self): self.state_obj.format_slots(cdata) mock.assert_called_once_with("fun_arg", fun_key="fun_val") self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "value1thing~"}}) + + def test_format_slots_parallel(self): + """ + Test if slots work with "parallel: true". + """ + high_data = { + "always-changes-and-succeeds": { + "test": [ + {"changes": True}, + {"comment": "__slot__:salt:test.echo(fun_return)"}, + {"parallel": True}, + "configurable_test_state", + {"order": 10000}, + ], + "__env__": "base", + "__sls__": "parallel_slots", + } + } + self.state_obj.jid = "123" + res = self.state_obj.call_high(high_data) + self.state_obj.jid = None + [(_, data)] = res.items() + self.assertEqual(data["comment"], "fun_return") From 55658bdf28d5108abaaa1e5ca2493b7823b19d0f Mon Sep 17 00:00:00 2001 From: Max Arnold Date: Sat, 11 Apr 2020 18:47:30 +0700 Subject: [PATCH 2/2] Skip the parallel slots test on Windows --- tests/unit/test_state.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/test_state.py b/tests/unit/test_state.py index 2d0e750f7241..02b8ebd342a1 100644 --- a/tests/unit/test_state.py +++ b/tests/unit/test_state.py @@ -619,6 +619,11 @@ def test_slot_append(self): mock.assert_called_once_with("fun_arg", fun_key="fun_val") self.assertEqual(cdata, {"args": ["arg"], "kwargs": {"key": "value1thing~"}}) + # Skip on windows like integration.modules.test_state.StateModuleTest.test_parallel_state_with_long_tag + @skipIf( + salt.utils.platform.is_windows(), + "Skipped until parallel states can be fixed on Windows", + ) def test_format_slots_parallel(self): """ Test if slots work with "parallel: true".