saltstack / saltstack/salt

[BUG] sysrc.managed test=True TypeError: can only concatenate str (not "bool") to str

Open
#60,048 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-low
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
When running sysrc.managed in test mode a bool is returned instead of a string . I could not figure out why , it only happens on one of my systems. Most of the time it works with the current code .

Setup

syssrc_vm_enable:
  sysrc.managed:
    - name: vm_enable
    - value: YES

Steps to Reproduce the behavior
salt '*' state.apply teststate test=True

Expected behavior

          ID: syssrc_vm_enable
    Function: sysrc.managed
        Name: vm_enable
      Result: None
     Comment: The value of "vm_enable" will be changed!
     Started: 20:45:55.254429
    Duration: 23.909 ms
     Changes:
              ----------
              new:
                  vm_enable = True will be set.
              old:
                  None

Versions Report

╰─ salt -V
Salt Version:
          Salt: 3002.6

Dependency Versions:
          cffi: 1.14.5
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.2
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.7.9 (default, Mar 27 2021, 01:17:51)
  python-gnupg: Not Installed
        PyYAML: 5.3.1
         PyZMQ: 22.0.3
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.1

System Versions:
          dist: freebsd 12.2
        locale: UTF-8
       machine: amd64
       release: 12.2-RELEASE-p4
        system: FreeBSD
       version: FreeBSD 12.2

Possible fix is salte/states/sysrc.py line 60

      if __opts__["test"] is True:
         ret["comment"] = 'The value of "{0}" will be changed!'.format(name)
         ret["changes"] = {
             "old": current_state,
             "new": name + " = " + str(value) + " will be set.",
         }

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

Start in salt/states/sysrc.py around line 60 and inspect the test-mode handling for sysrc.managed, using the provided FreeBSD reproduction and state configuration. Verify that test=True handles the reported value without a string/boolean concatenation error, then confirm the resulting state output matches the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.