saltstack / saltstack/salt

[BUG] Setting keyboard layout fails but returns success

Open
#62,838 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage State-Module
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
When the user applies a state to set a keyboard keymap that is not available,
the command fails, but salt reports a success.
I think I have found the cause and am working on a patch.

Setup
I think this would affect everyone using this module, but this is where
I encountered it:

  • on-prem machine
  • VM (libvirt, qemu, suse SLES15SP4 minion, provisioned with sumaform)
  • 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
  • classic packaging
  • onedir packaging
  • used bootstrap to install

Steps to Reproduce the behavior

Run:
salt-call --local state.single keyboard.system ca.map.gz

[ERROR   ] Command 'localectl' failed with return code: 1
[ERROR   ] stdout: Failed to set keymap: Keymap ca.map.gz is not installed.
[ERROR   ] retcode: 1
[ERROR   ] Command 'localectl' failed with return code: 1
[ERROR   ] output: Failed to set keymap: Keymap ca.map.gz is not installed.
local:
----------
          ID: ca.map.gz
    Function: keyboard.system
      Result: True
     Comment: Set system keyboard layout ca.map.gz
     Started: 17:53:24.783471
    Duration: 214.29 ms
     Changes:   
              ----------
              layout:
                  ca.map.gz

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time: 214.290 ms

Expected behavior
Result should be False, Succeeded should be 0, Failed should be 1.

Screenshots

Versions Report

salt --versions-report ```yaml Salt Version: Salt: 3004

Dependency Versions:
cffi: 1.13.2
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: 0.38.0
Mako: Not Installed
msgpack: 0.5.6
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: 2.17
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC]
python-gnupg: Not Installed
PyYAML: 5.4.1
PyZMQ: 17.1.2
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.2.3

System Versions:
dist: sles 15.4
locale: UTF-8
machine: x86_64
release: 5.14.21-150400.22-default
system: Linux
version: SLES 15.4```

Additional context
I think I've worked out why this happens and am working on a fix, over here:
https://github.com/saltstack/salt/compare/master...zzaimeche:salt:fix-keyboard-fails
I think Salt does not check whether the shell command was successful, but whether
the python calling the command ran successfully. So whether the shell command
succeeds or fails, Salt reports a success.
The issue is in https://github.com/saltstack/salt/blob/master/salt/modules/keyboard.py
and https://github.com/saltstack/salt/blob/master/salt/states/keyboard.py .
I think Salt needs to check for the retcode, so I used cmd.retcode based on other
examples in the codebase, though I couldn't find the documentation for cmd.retcode,
so maybe there's a better way. My WIP patch seems to fix
the issue on my machine (but my WIP patch will break things on other
distros at the moment). I'll make a PR shortly. I'm hoping someone from the Salt
team can take a look and advise if there's a preferred approach, since I suspect there
might have been similar issues with other modules and there may be a convention for
this kind of fix.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read salt/modules/keyboard.py and salt/states/keyboard.py, then reproduce the failure with salt-call --local state.single keyboard.system ca.map.gz. Compare the behavior with the linked WIP patch and verify that a failed localectl command produces Result: False, Succeeded: 0, and Failed: 1 without breaking other distributions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.