Skip to content

[BUG] minion crashes when empty grains are supplied as minion config #61321

@margau

Description

@margau

Description
The minion crashes when an empty grains-dict is supplied with the minion config:

Dec 03 08:16:41 hostname systemd[1]: Starting The Salt Minion...
Dec 03 08:16:41 hostname systemd[1]: Started The Salt Minion.
Dec 03 08:16:41 hostname salt-minion[80365]: [ERROR   ] 'NoneType' object is not iterable
Dec 03 08:16:41 hostname salt-minion[80365]: Traceback (most recent call last):
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 210, in parse_args
Dec 03 08:16:41 hostname salt-minion[80365]:     mixin_after_parsed_func(self)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 887, in __setup_extended_logging
Dec 03 08:16:41 hostname salt-minion[80365]:     log.setup_extended_logging(self.config)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/log/setup.py", line 414, in setup_extended_logging
Dec 03 08:16:41 hostname salt-minion[80365]:     providers = salt.loader.log_handlers(opts)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/__init__.py", line 685, in log_handlers
Dec 03 08:16:41 hostname salt-minion[80365]:     ret = LazyLoader(
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 255, in __init__
Dec 03 08:16:41 hostname salt-minion[80365]:     self.opts = self.__prep_mod_opts(opts)
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 573, in __prep_mod_opts
Dec 03 08:16:41 hostname salt-minion[80365]:     self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
Dec 03 08:16:41 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/context.py", line 203, in __init__
Dec 03 08:16:41 hostname salt-minion[80365]:     super().__init__(self._dict())
Dec 03 08:16:41 hostname salt-minion[80365]: TypeError: 'NoneType' object is not iterable
Dec 03 08:16:46 hostname salt-minion[80365]: Usage: salt-minion [options]
Dec 03 08:16:46 hostname salt-minion[80365]: salt-minion: error: Error while processing <function LogLevelMixIn.__setup_extended_logging at 0x7f5ef3f808b0>: Traceback (most recent call last):
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 210, in parse_args
Dec 03 08:16:46 hostname salt-minion[80365]:     mixin_after_parsed_func(self)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 887, in __setup_extended_logging
Dec 03 08:16:46 hostname salt-minion[80365]:     log.setup_extended_logging(self.config)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/log/setup.py", line 414, in setup_extended_logging
Dec 03 08:16:46 hostname salt-minion[80365]:     providers = salt.loader.log_handlers(opts)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/__init__.py", line 685, in log_handlers
Dec 03 08:16:46 hostname salt-minion[80365]:     ret = LazyLoader(
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 255, in __init__
Dec 03 08:16:46 hostname salt-minion[80365]:     self.opts = self.__prep_mod_opts(opts)
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 573, in __prep_mod_opts
Dec 03 08:16:46 hostname salt-minion[80365]:     self.pack["__grains__"] = salt.utils.context.NamespacedDictWrapper(
Dec 03 08:16:46 hostname salt-minion[80365]:   File "/usr/lib/python3/dist-packages/salt/utils/context.py", line 203, in __init__
Dec 03 08:16:46 hostname salt-minion[80365]:     super().__init__(self._dict())
Dec 03 08:16:46 hostname salt-minion[80365]: TypeError: 'NoneType' object is not iterable
Dec 03 08:16:46 hostname systemd[1]: salt-minion.service: Main process exited, code=exited, status=64/USAGE
Dec 03 08:16:46 hostname systemd[1]: salt-minion.service: Failed with result 'exit-code'.

If the grain configuration is removed or provided with content, the issue is gone.
When the configuration is automatically created/templated, it is possible that grains: is empty on some minions, depending on the used setup.

Setup
Salt-Master and Minion on the same machine (EC2) under ubuntu 20.04.
Minion configuration contains:

cat /etc/salt/minion.d/grains.conf 
grains:

Steps to Reproduce the behavior
Add a minion config, e.g. in /etc/salt/minion.d/grains.conf, with an empty grains dict:

grains:

The minion crashes upon restart.

Expected behavior
The minion should not crash, just ignore the grains configuration.

Versions Report
Both master and minion have the same version out of the https://repo.saltproject.io/py3/ubuntu/20.04/amd64/latest focal main repository.

salt --versions-report
Salt Version:
          Salt: 3004
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: 2.0.6
     gitpython: 3.0.7
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.8.10 (default, Sep 28 2021, 16:10:42)
  python-gnupg: 0.4.5
        PyYAML: 5.4.1
         PyZMQ: 18.1.1
         smmap: 2.0.5
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2
 
System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.11.0-1022-aws
        system: Linux
       version: Ubuntu 20.04 focal

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbroken, incorrect, or confusing behaviorhelp-wantedCommunity help is needed to resolve thisseverity-low4th level, cosemtic problems, work around exists

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions