Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state locale.system throws exception #63559

Open
iils-jschmidt opened this issue Jan 26, 2023 · 9 comments
Open

state locale.system throws exception #63559

iils-jschmidt opened this issue Jan 26, 2023 · 9 comments
Labels
Bug broken, incorrect, or confusing behavior info-needed waiting for more info needs-triage

Comments

@iils-jschmidt
Copy link

iils-jschmidt commented Jan 26, 2023

Description of Issue

The following state throws an exception at locale.system. This has worked previously, so I assume it as a recent development.
Also, I reinstalled the system where the state is applied, but I doubt that is the reason for the exception.

Setup

baseconfig-locales-debconf-set-locales:
  debconf.set:
    - name: locales
    - data:
        'locales/default_environment_locale': {'type': 'select', 'value': 'en_US.UTF-8'}
        'locales/locales_to_be_generated': {'type': 'multiselect', 'value': '[en_US.UTF-8 UTF-8, de_DE.UTF-8 UTF-8]'}

baseconfig-locales-pkg-installed-locales:
  pkg.installed:
    - pkgs:
      - locales
    - require:
      - debconf: locales

baseconfig-locales-locale-present-us-locale:
  locale.present:
    - name: en_US.UTF-8

baseconfig-locales-locale-present-de-locale:
  locale.present:
    - name: de_DE.UTF-8

baseconfig-locales-locale-present-default-locale:
  locale.system:
    - name: en_US.UTF-8

Steps to Reproduce Issue


      ID: baseconfig-locales-locale-present-default-locale
Function: locale.system
    Name: en_US.UTF-8
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "salt/state.py", line 2276, in call                                                                                                                                    
              ret = self.states[cdata["full"]](                                                                                                                                         
            File "salt/loader/lazy.py", line 149, in __call__                                                                                                                           
              return self.loader.run(run_func, *args, **kwargs)                                                                                                                         
            File "salt/loader/lazy.py", line 1228, in run                                                                                                                               
              return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)                                                                                             
            File "salt/loader/lazy.py", line 1243, in _run_as                                                                                                                           
              return _func_or_method(*args, **kwargs)                                                                                                                                   
            File "salt/loader/lazy.py", line 1276, in wrapper                                                                                                                           
              return f(*args, **kwargs)                                                                                                                                                 
            File "/opt/saltstack/salt/run/salt/states/locale.py", line 42, in system                                                                                                    
              if __salt__["locale.get_locale"]() == name:                                                                                                                               
            File "salt/loader/lazy.py", line 149, in __call__                                                                                                                           
              return self.loader.run(run_func, *args, **kwargs)                                                                                                                         
            File "salt/loader/lazy.py", line 1228, in run                                                                                                                               
              return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)                                                                                             
            File "salt/loader/lazy.py", line 1243, in _run_as                                                                                                                           
              return _func_or_method(*args, **kwargs)                                                                                                                                   
            File "/opt/saltstack/salt/run/salt/modules/localemod.py", line 154, in get_locale                                                                                           
              else _localectl_status()["system_locale"]                                                                                                                                 
          KeyError: 'system_locale'                                                                                                                                                     
 Started: 14:00:25.848827
Duration: 28.94 ms
 Changes:  

Versions Report

Salt Version:
          Salt: 3005.1
 
Dependency Versions:
          cffi: 1.14.6
      cherrypy: unknown
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.0
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.9.16 (main, Jan  6 2023, 22:49:58)
  python-gnupg: 0.4.8
        PyYAML: 5.4.1
         PyZMQ: 23.2.0
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
System Versions:
          dist: debian 11 bullseye
        locale: utf-8
       machine: x86_64
       release: 5.10.0-21-amd64
        system: Linux
       version: Debian GNU/Linux 11 bullseye

@OrangeDog
Copy link
Contributor

I assume you get the same exception from salt-call local.get_locale?

What does the locale command return? Your system appears to be missing a language, but the Salt state should be able to set it for you instead of failing to check the current one.

Note also your states are missing requisites. For example, baseconfig-locales-locale-present-default-locale should require baseconfig-locales-locale-present-us-locale.

@OrangeDog OrangeDog added Bug broken, incorrect, or confusing behavior info-needed waiting for more info needs-triage labels Jan 26, 2023
@iils-jschmidt
Copy link
Author

Ah ya thx for the requisites, I included them now, but it's the same exception. I assumed salt uses the order the states appear in the file. Does this mean requisites are needed everytime there is a dependency in the order of operations?

I assume you meant locale.get_locale?

salt-call local.get_locale
'local.get_locale' is not available.

salt-call locale.get_locale
local:
    en_US.UTF-8

locale returns

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

@iils-jschmidt
Copy link
Author

WTF, now the states work? After I ran salt-call locale.get_locale
This did not work before (with or without the requisites).

@OrangeDog
Copy link
Contributor

OrangeDog commented Jan 26, 2023

I think your system locale was uninitialised when you reinstalled the system, but something has now set it. Has the locale in the versions report now changed too?

I still think it's a bug that Salt doesn't handle that, but if it's hard to reproduce it's not going to be high priority.

salt uses the order the states appear in the file

Sometimes. You should always explicitly add dependencies where they exist, to avoid cascading failures if nothing else.

@iils-jschmidt
Copy link
Author

I modified the state from above to include a call to salt-call locale.get_locale.
To test it I set up a new system and ran the state.
The exception now moved from locale.system to the get_locale.

State:

baseconfig-locales-debconf-set-locales:
  debconf.set:
    - name: locales
    - data:
        'locales/default_environment_locale': {'type': 'select', 'value': 'en_US.UTF-8'}
        'locales/locales_to_be_generated': {'type': 'multiselect', 'value': '[en_US.UTF-8 UTF-8, de_DE.UTF-8 UTF-8]'}

baseconfig-locales-pkg-installed-locales:
  pkg.installed:
    - pkgs:
      - locales
    - require:
      - debconf: locales

baseconfig-locales-locale-present-us-locale:
  locale.present:
    - name: en_US.UTF-8

baseconfig-locales-locale-present-de-locale:
  locale.present:
    - name: de_DE.UTF-8


#this might be not needed anymore, there was a bug where
# baseconfig-locales-locale-present-default-locale threw an exception
salt-call-locale.get_locale:
  cmd.run:
    - name: salt-call locale.get_locale
    - requires: 
      - locale: baseconfig-locales-locale-present-de-locale
      - locale: baseconfig-locales-locale-present-us-locale


baseconfig-locales-locale-present-default-locale:
  locale.system:
    - name: en_US.UTF-8
    - require:
      - cmd: salt-call-locale.get_locale
      - locale: baseconfig-locales-locale-present-de-locale
      - locale: baseconfig-locales-locale-present-us-locale

Errors:

----------
          ID: salt-call-locale.get_locale
    Function: cmd.run
        Name: salt-call locale.get_locale
      Result: False
     Comment: Command "salt-call locale.get_locale" run
     Started: 17:18:09.506851
    Duration: 1961.975 ms
     Changes:   
              ----------
              pid:
                  14081
              retcode:
                  1
              stderr:
                  [ERROR   ] Command 'localectl' failed with return code: 1
                  [ERROR   ] stdout: ?[0;1;31mFailed to connect to bus: No such file or directory?[0m
                  [ERROR   ] retcode: 1
                  [ERROR   ] Command 'localectl' failed with return code: 1
                  [ERROR   ] output: ?[0;1;31mFailed to connect to bus: No such file or directory?[0m
                  [ERROR   ] An un-handled exception was caught by Salt's global exception handler:
                  KeyError: 'system_locale'
                  Traceback (most recent call last):
                    File "/root/.pyenv/versions/3.9.16/envs/tmpcaak_5km/bin/salt", line 118, in <module>
                    File "/root/.pyenv/versions/3.9.16/envs/tmpcaak_5km/bin/salt", line 113, in redirect
                    File "salt/scripts.py", line 441, in salt_call
                      client.run()
                    File "salt/cli/call.py", line 50, in run
                      caller.run()
                    File "salt/cli/caller.py", line 95, in run
                      ret = self.call()
                    File "salt/cli/caller.py", line 202, in call
                      ret["return"] = self.minion.executors[fname](
                    File "salt/loader/lazy.py", line 149, in __call__
                      return self.loader.run(run_func, *args, **kwargs)
                    File "salt/loader/lazy.py", line 1228, in run
                      return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                    File "salt/loader/lazy.py", line 1243, in _run_as
                      return _func_or_method(*args, **kwargs)
                    File "/opt/saltstack/salt/run/salt/executors/direct_call.py", line 10, in execute
                      return func(*args, **kwargs)
                    File "salt/loader/lazy.py", line 149, in __call__
                      return self.loader.run(run_func, *args, **kwargs)
                    File "salt/loader/lazy.py", line 1228, in run
                      return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
                    File "salt/loader/lazy.py", line 1243, in _run_as
                      return _func_or_method(*args, **kwargs)
                    File "/opt/saltstack/salt/run/salt/modules/localemod.py", line 154, in get_locale
                      else _localectl_status()["system_locale"]
                  KeyError: 'system_locale'
                  Traceback (most recent call last):
                    File "/root/.pyenv/versions/3.9.16/envs/tmpcaak_5km/bin/salt", line 118, in <module>
                    File "/root/.pyenv/versions/3.9.16/envs/tmpcaak_5km/bin/salt", line 113, in redirect
                    File "salt/scripts.py", line 441, in salt_call
                    File "salt/cli/call.py", line 50, in run
                    File "salt/cli/caller.py", line 95, in run
                    File "salt/cli/caller.py", line 202, in call
                    File "salt/loader/lazy.py", line 149, in __call__
                    File "salt/loader/lazy.py", line 1228, in run
                    File "salt/loader/lazy.py", line 1243, in _run_as
                    File "/opt/saltstack/salt/run/salt/executors/direct_call.py", line 10, in execute
                      return func(*args, **kwargs)
                    File "salt/loader/lazy.py", line 149, in __call__
                    File "salt/loader/lazy.py", line 1228, in run
                    File "salt/loader/lazy.py", line 1243, in _run_as
                    File "/opt/saltstack/salt/run/salt/modules/localemod.py", line 154, in get_locale
                      else _localectl_status()["system_locale"]
                  KeyError: 'system_locale'
                  [14082] Failed to execute script 'salt' due to unhandled exception!
              stdout:
----------

@iils-jschmidt
Copy link
Author

I could trace it back to the cause: salt's locale state depends on localectl which in turn depends on dbus.
dbus was neither installed nor running on the new system, hence the exceptions.

These dependencies are not mentioned in the docs. And I am not entierly sure it is good to depend on both.
I think the command "locale" does the same, at least for getting the locale settings.

@OrangeDog
Copy link
Contributor

A Debian system is expected to have dbus, just as it's expected to have systemd and apt.

localectl is required for changing the system locale, so it probably should be using it to query it too.

@iils-jschmidt
Copy link
Author

Probably right. However, dbus is only in systemd's recommended list, so it is not always installed. I suggest updating the doc to include dbus.

@iils-jschmidt
Copy link
Author

Heads up localectl fails inside an incus container running debian 12. Reason: localectl depends on systemd-localed which (at least on Debian 12) uses PrivateNetwork=yes. Which is blocked by apparmor of the host. I guess this is more of an incus bug, I'll report it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior info-needed waiting for more info needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants