saltstack / saltstack/salt

Imported jinja without context in .sls are not cached

Open
#66,485 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When doing an import of a Jinja from a .sls without passing context should be cached according to Jinja template but it seems to not be the case.

Setup

Install latest onedir on Debian 12 according to documentation

Please be as specific as possible and give set-up details.

  • on-prem machine
  • VM (KVM)
  • 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

  • create a /srv/salt/test-cache/init.sls
    include:
      - .test1
      - .test2
    
  • create the /srv/salt/test-cache/test1.sls
    {%- profile as 'load slow-sha-compute from test1' %}
    {%-   from "test-cache/slow-compute.jinja" import slow_value %}
    {%- endprofile %}
    
    test1-show-slow-value:
      test.nop:
        - name: {{ slow_value }}
    
  • create the /srv/salt/test-cache/test2.sls
    {%- profile as 'load slow-sha-compute from test2' %}
    {%-   from "test-cache/slow-compute.jinja" import slow_value %}
    {%- endprofile %}
    
    test2-show-slow-value:
      test.nop:
        - name: {{ slow_value }}
    
  • create the jinja file /srv/salt/test-cache/slow-compute.sls
    {%- do salt["test.sleep"](10) %}
    {%- set slow_value = "10" %}
    
  • execute the command salt-call -l profile state.apply test-cache
    [WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
    [INFO    ] Loading fresh modules for state activity
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/init.sls' using 'jinja' renderer: 0.0031363964080810547
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/init.sls' using 'yaml' renderer: 0.0005271434783935547
    [PROFILE ] Time (in seconds) to render profile block 'load slow-sha-compute from test1': 10.01871919631958
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/test1.sls' using 'jinja' renderer: 10.022127628326416
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/test1.sls' using 'yaml' renderer: 0.0008547306060791016
    [PROFILE ] Time (in seconds) to render profile block 'load slow-sha-compute from test2': 10.018997192382812
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/test2.sls' using 'jinja' renderer: 10.021836757659912
    [PROFILE ] Time (in seconds) to render '/var/cache/salt/minion/files/base/test-cache/test2.sls' using 'yaml' renderer: 0.0007636547088623047
    [INFO    ] Running state [test1-show-slow-value] at time 17:00:44.647191
    [INFO    ] Executing state test.nop for [test1-show-slow-value]
    [INFO    ] Success!
    [INFO    ] Completed state [test1-show-slow-value] at time 17:00:44.648329 (duration_in_ms=1.14)
    [INFO    ] Running state [test2-show-slow-value] at time 17:00:44.648555
    [INFO    ] Executing state test.nop for [test2-show-slow-value]
    [INFO    ] Success!
    [INFO    ] Completed state [test2-show-slow-value] at time 17:00:44.649393 (duration_in_ms=0.839)
    local:
    ----------
              ID: test1-show-slow-value
        Function: test.nop
          Result: True
         Comment: Success!
         Started: 17:00:44.647189
        Duration: 1.14 ms
         Changes:
    ----------
              ID: test2-show-slow-value
        Function: test.nop
          Result: True
         Comment: Success!
         Started: 17:00:44.648554
        Duration: 0.839 ms
         Changes:
    
    Summary for local
    ------------
    Succeeded: 2
    Failed:    0
    ------------
    Total states run:     2
    Total run time:   1.979 ms
    

Expected behavior

The rendering of /srv/salt/test-cache/slow-compute.jinja show be quick when loaded from /srv/salt/test-cache/test2.sls instead of during more than 10 seconds.

Screenshots

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3007.0
 
Python Version:
        Python: 3.10.13 (main, Feb 19 2024, 03:31:20) [GCC 11.2.0]
 
Dependency Versions:
          cffi: 1.16.0
      cherrypy: unknown
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.3
       libgit2: 1.7.2
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: 1.14.1
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.15.1
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.3.3
           ZMQ: 4.3.4
 
Salt Package Information:
  Package Type: onedir
 
System Versions:
          dist: debian 12.5 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.1.0-12-cloud-amd64
        system: Linux
       version: Debian GNU/Linux 12.5 bookworm

Additional context

Following #59441 for 3007.0 with simpler instruction by using salt["test.sleep"](10) instead of complicated ISO hash computation.

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

Reproduce the issue with /srv/salt/test-cache/init.sls, test1.sls, test2.sls, and the slow-compute.jinja example, then run salt-call -l profile state.apply test-cache. Trace the Jinja import and rendering behavior around the reported Salt 3007.0 setup; done means the second import is cached and no longer incurs the additional 10-second delay.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.