saltstack / saltstack/salt

saltclass error when expanding pillar value that is not of type 'str'

Open
#61,934 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description of Issue

When using saltclass for pillar data, variable expansion/interpolation fails when referenced pillar value is not a string. This does not appear to be an issue when simply referencing non-string pillar data within states, only when doing interpolation within saltclass itself.

Using the example below, referencing defaults:default_service_port in a state works fine. Interpolating as the value for myservice:port fails with the following exception shown in the master log: [salt.pillar :1218][CRITICAL][22870] Pillar render error: Failed to load ext_pillar saltclass: replace() argument 2 must be str, not int

This appears to be coming from salt.utils.saltclass in find_and_process_re() and/or find_value_to_expand(). The call to str.replace() in find_and_process_re() fails because find_value_to_expand() returns expanded pillar data in its original type, and str.replace() needs its second argument to be a string, as the log entry states.

Setup
Example pillar data
pillar:
  defaults:
    default_service_port: 1234
  myservice:
    port: ${defaults:default_service_port}
Steps to Reproduce Issue
  1. Call salt <target> pillar.get defaults:default_service_port. This should return 1234 correctly.
  2. Call salt <target> pillar.get myservice:port, salt <target> pillar.items, or anything else that would make the interpolation attempt occur. The only log entry Salt provides that I have seen is [salt.pillar :1218][CRITICAL][22870] Pillar render error: Failed to load ext_pillar saltclass: replace() argument 2 must be str, not int, but more details can be seen with pdb.
Versions Report
Salt Version:
          Salt: 3003.4

Dependency Versions:
          cffi: 1.14.0
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.1
       libgit2: 0.28.4
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: 2.6.1
  pycryptodome: 3.13.0
        pygit2: 1.0.3
        Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
  python-gnupg: Not Installed
        PyYAML: 5.3
         PyZMQ: 17.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.1.4

Salt Extensions:
        sseape: 8.6.0.3

System Versions:
          dist: centos 7 Core
        locale: UTF-8
       machine: x86_64
       release: 3.10.0-1160.59.1.el7.x86_64
        system: Linux
       version: CentOS Linux 7 Core

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/utils/saltclass.py, focusing on find_and_process_re() and find_value_to_expand(), then reproduce the example with a numeric defaults:default_service_port value. Confirm that pillar.get myservice:port and pillar.items complete without the reported replace() type error while direct access to the numeric value still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.