Skip to content

Commit

Permalink
Fix tower for Salt release 3003
Browse files Browse the repository at this point in the history
With the Loader changes from saltstack/salt#59832 in
the Salt Aluminum release, this tower breaks.

The traceback is shown below:

```
[ERROR   ] can't pickle _thread.RLock objects
Traceback (most recent call last):
  File "/var/cache/salt/minion/extmods/pillar/tower.py", line 138, in _match_minion
    tgt, {"grains": grains, "pillar": self, "id": self.minion_id}
  File "/var/cache/salt/minion/extmods/pillar/tower.py", line 33, in _match_minion_impl
    dict(__opts__, **opts)
  File "/usr/lib/python3.6/site-packages/salt/loader.py", line 372, in matchers
    return LazyLoader(_module_dirs(opts, "matchers"), opts, tag="matchers")
  File "/usr/lib/python3.6/site-packages/salt/loader.py", line 1318, in __init__
    opts = copy.deepcopy(opts)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib64/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib64/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib64/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib64/python3.6/copy.py", line 169, in deepcopy
    rv = reductor(4)
TypeError: can't pickle _thread.RLock objects
```

The reason for this is that self as used for the pillar dictionary has a
LazyLoader object attached, which has an unpickable RLock object. Casting to dict()
fixes this.

Additionally the new loader code changes things in such, that grains.value() needs
to be used to get the grains instead of just a loader object. This is fixed as well.

Credits for the actual understanding of the problem on the salt side and the fix suggestion
goes to @dwoz.
  • Loading branch information
ixs authored and jgraichen committed Apr 3, 2021
1 parent 1ed2b86 commit 862e8a2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion salt_tower/pillar/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ def run(self, top):

def _match_minion(self, tgt):
try:
if hasattr(__grains__, "value"):
grains = __grains__.value()
else:
grains = __grains__
return _match_minion_impl(
tgt, {"grains": __grains__, "pillar": self, "id": self.minion_id}
tgt, {"grains": grains, "pillar": dict(self), "id": self.minion_id}
)
except Exception as err: # pylint: disable=broad-except
LOGGER.exception(err)
Expand Down

0 comments on commit 862e8a2

Please sign in to comment.