From 2202fedbbf2c2f89cd57bd3957f940367448bb06 Mon Sep 17 00:00:00 2001 From: Matt Phillips Date: Mon, 4 Feb 2019 20:08:51 -0500 Subject: [PATCH] address circular reference in LazyLoader with ThreadLocalProxy when lazyLoader was getting instantiated from inside already lazyloaded modules (ie state), pillar/grain (and probably other) globals were already populated. In this case they weren't getting dereferenced properly when wrapped via the NamespacedDict wrapper, causing an infinite loop. This should fix that scenario. Fixes https://github.com/saltstack/salt/pull/50655#issuecomment-460050683 --- tests/integration/files/file/base/issue-51499.sls | 6 ++++++ tests/integration/modules/test_state.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/integration/files/file/base/issue-51499.sls diff --git a/tests/integration/files/file/base/issue-51499.sls b/tests/integration/files/file/base/issue-51499.sls new file mode 100644 index 000000000000..0e15e7396eae --- /dev/null +++ b/tests/integration/files/file/base/issue-51499.sls @@ -0,0 +1,6 @@ +{% if 'nonexistent_module.function' in salt %} +{% do salt.log.warning("Module is available") %} +{% endif %} +always-passes: + test.succeed_without_changes: + - name: foo diff --git a/tests/integration/modules/test_state.py b/tests/integration/modules/test_state.py index d5f20652fb44..59ecc578e0f1 100644 --- a/tests/integration/modules/test_state.py +++ b/tests/integration/modules/test_state.py @@ -2118,3 +2118,16 @@ def test_state_sls_integer_name(self): self.assertEqual(state_run[state_id]['comment'], 'Success!') self.assertTrue(state_run[state_id]['result']) + + def test_state_sls_lazyloader_allows_recursion(self): + ''' + This tests that referencing dunders like __salt__ work + context: https://github.com/saltstack/salt/pull/51499 + ''' + state_run = self.run_function('state.sls', mods='issue-51499') + + state_id = 'test_|-always-passes_|-foo_|-succeed_without_changes' + self.assertIn(state_id, state_run) + self.assertEqual(state_run[state_id]['comment'], + 'Success!') + self.assertTrue(state_run[state_id]['result'])