Repository navigation
Description
Description
A clear and concise description of what the bug is.
I have a custom execution module were I need to compile Pillars given a custom git branch. This is done by invoking salt.pillar.get_pillar. I had no troubles running this across many Salt versions (including 3002.9 currently), but upgrading to anything above 3003 (including 3005rc2), it errors out.
The reasoning why we're needing this call is that we have a gitfs backend, and need on-demand Pillar data compiled for whatever branch the user requires.
Trace:
The minion function caused an exception: Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/salt/metaproxy/proxy.py", line 479, in thread_return
return_data = minion_instance.executors[fname](
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 1228, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 1243, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/executors/direct_call.py", line 10, in execute
return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 1228, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/salt/loader/lazy.py", line 1243, in _run_as
return _func_or_method(*args, **kwargs)
File "/var/cache/salt/proxy/extmods/some-proxy/modules/do.py", line 862, in config
master_pillar = get_pillar(ext=_ext_pillar_args(branch) if branch else None)
File "/var/cache/salt/proxy/extmods/some-proxy/modules/do.py", line 104, in get_pillar
ret = salt.pillar.get_pillar(
File "/usr/local/lib/python3.9/site-packages/salt/pillar/__init__.py", line 353, in compile_pillar
ret_pillar = self.channel.crypted_transfer_decode_dictentry(
File "/usr/local/lib/python3.9/site-packages/salt/utils/asynchronous.py", line 125, in wrap
raise exc_info[1].with_traceback(exc_info[2])
File "/usr/local/lib/python3.9/site-packages/salt/utils/asynchronous.py", line 131, in _target
result = io_loop.run_sync(lambda: getattr(self.obj, key)(*args, **kwargs))
File "/usr/local/lib/python3.9/site-packages/salt/ext/tornado/ioloop.py", line 459, in run_sync
return future_cell[0].result()
File "/usr/local/lib/python3.9/site-packages/salt/ext/tornado/concurrent.py", line 249, in result
raise_exc_info(self._exc_info)
File "<string>", line 4, in raise_exc_info
File "/usr/local/lib/python3.9/site-packages/salt/ext/tornado/gen.py", line 309, in wrapper
yielded = next(result)
File "/usr/local/lib/python3.9/site-packages/salt/channel/client.py", line 172, in crypted_transfer_decode_dictentry
self._package_load(self.auth.crypticle.dumps(load)),
File "/usr/local/lib/python3.9/site-packages/salt/crypt.py", line 1518, in dumps
toencrypt = self.PICKLE_PAD + salt.payload.dumps(obj)
File "/usr/local/lib/python3.9/site-packages/salt/payload.py", line 163, in dumps
return salt.utils.msgpack.packb(
File "/usr/local/lib/python3.9/site-packages/salt/utils/msgpack.py", line 133, in packb
return msgpack.packb(o, **_sanitize_msgpack_kwargs(kwargs))
File "/usr/local/lib/python3.9/site-packages/msgpack/__init__.py", line 38, in packb
return Packer(**kwargs).pack(o)
File "msgpack/_packer.pyx", line 294, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 300, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 297, in msgpack._cmsgpack.Packer.pack
File "msgpack/_packer.pyx", line 231, in msgpack._cmsgpack.Packer._pack
File "msgpack/_packer.pyx", line 285, in msgpack._cmsgpack.Packer._pack
File "/usr/local/lib/python3.9/site-packages/salt/payload.py", line 158, in ext_type_encoder
return dict(obj)
File "/usr/local/lib/python3.9/_collections_abc.py", line 826, in __iter__
yield from self._mapping
File "/usr/local/lib/python3.9/site-packages/salt/loader/context.py", line 97, in __iter__
return self.value().__iter__()
AttributeError: 'NoneType' object has no attribute '__iter__'Setup
A Salt Master and a Proxy Minion (any flavour) running Salt 3003+, and a custom execution module with these functions:
def _ext_pillar_args(branch):
repo = "[email protected]:org/salt.git"
return dict(
git=[
{
"{} {}".format(branch, repo): [
{"env": "base"},
{"root": "salt/pillar"},
{"pubkey": "/path/to/key.pub"},
{"privkey": "/path/to/key.priv"},
]
}
]
)
def get_pillar(branch=None):
ext = _ext_pillar_args(branch) if branch else None
ret = salt.pillar.get_pillar(
__opts__, __grains__, __opts__["id"], __opts__.get("saltenv"), ext=ext
).compile_pillar()
return retMaster configuration:
ext_pillar_first: true
ext_pillar:
- git:
- [email protected]:org/salt.git:
- root: salt/pillar
- pubkey: /path/to/key.pub
- privkey: /path/to/key.privThis code has been running in production, and currently under 3002.9 perfectly fine.
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify)
- VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
Steps to Reproduce the behavior
- Put the code above into a custom execution module.
- Set up a Master with a gitfs backend and a Proxy Minion of any flavour.
- Execute
salt <tgt> custom_module.get_pillar
Expected behavior
I'd expect to get the pillar not the trace.
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)root@salt:~# salt --versions-report
Salt Version:
Salt: 3004.2
Dependency Versions:
cffi: 1.15.1
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.0.3
libgit2: 1.4.3
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.4
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.15.0
pygit2: 1.9.2
Python: 3.9.13 (main, Jul 12 2022, 12:26:02)
python-gnupg: 0.4.9
PyYAML: 6.0
PyZMQ: 21.0.2
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.3
System Versions:
dist: debian 10 buster
locale: utf-8
machine: x86_64
release: 5.0.0-36-generic
system: Linux
version: Debian GNU/Linux 10 busterAdditional context
Add any other context about the problem here.
Activity
mirceaulinic commentedon Aug 17, 2022
More info on this: it seems like the object being sent to msgpack (see the end of the trace)
is this:
{'id': 'some-proxy', 'grains': <salt.loader.context.NamedLoaderContext object at 0x7f4fa2700f10>, 'saltenv': 'base', 'pillarenv': None, 'pillar_override': {}, 'extra_minion_data': {}, 'ver': '2', 'cmd': '_pillar', 'nonce': 'supersafe'}This gets sent to
salt.payload.ext_type_encoderand the value of thegrainsobject appears to beNonefor some reason.mirceaulinic commentedon Aug 18, 2022
It turns out that the error is caused by the fact that the Grains are passed in as the
NamedLoaderContextobject. Changing the snippet above to the following, fixes the issue:I am happy to close this one out, but I'd like to see if the core team would find value in checking the data type of the
grainsargument (into thesalt.pillar.get_pillarfunction) and always call.value()when the object passed in issalt.loader.context.NamedLoaderContexttype (I can probably see other places where this confusion would be avoided out of the box).jbemmel commentedon Aug 22, 2022
Also happens when passing a simple pillar on the command line (using 3004.2):
Looks like a pretty serious bug to me - no workaround available to command line users
dmurphy18 commentedon Feb 16, 2023
@mirceaulinic Curious, the versions-report states Salt 3004.2, but the python version used is Python 3.9.13 but the default OS version for Debian 10 is Python 3.7.3, and given this is a (classic) package which depends on the OS to supply dependencies (not Onedir - only available with Salt 3005.1), typically they need the default OS python3 version to operate correctly ?
dwoz commentedon Apr 8, 2023
I wonder if this will fix the issue #64043
dmurphy18 commentedon Apr 10, 2023
Can confirm with
The 3002.9 minion on Debian 10 works fine, but 3005.1 minion on Debian 11, has issues, from RHEL 7 salt-master 3002.9
dmurphy18 commentedon Apr 10, 2023
Upgrade to salt-master with 3005.1 and issue still exists
dmurphy18 commentedon Apr 10, 2023
The problem is here
trying to do a dict of the obj throws an exception, in salt/payload.py
dmurphy18 commentedon Apr 12, 2023
Simplifying the test which produces the error
dmurphy18 commentedon Apr 13, 2023
Moving this to 3006.1, to allow for more time to research NamedLoaderContext issue not containing a loader which results in None.
dmurphy18 commentedon Apr 18, 2023
It appears to be a deep copy issue in salt/utils/asynchronous.py the _wrap starts a thread with function _target,
in _wrap the NamedLoadContext works fine, but in _target it has loader LookupError.
_wrap is just passing it's args parameter through to the thread, and when the tread activates the NamedLoaderContext is missing it's loader.
This may be an issue with other args passed to the thread which also require a deepcopy too.
https://github.com/saltstack/salt/blob/master/salt/utils/asynchronous.py#L112-L136
The following is the debug output with testing of grains.
dmurphy18 commentedon Apr 18, 2023
After chatting with @dwoz , want to limit the NamedLoaderContext use with dunder grains, pillars, etc. within the execution modules where it was created, and hence use value() for anywhere it goes beyond the execution modules, for example: accessing / updating / gathering pillar information.
dmurphy18 commentedon Apr 26, 2023
Closing since PR #64055 merged