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

[BUG] removed Jinja templates can still be loaded from cache #62042

Closed
nicholasmhughes opened this issue May 9, 2022 · 0 comments · Fixed by #62043
Closed

[BUG] removed Jinja templates can still be loaded from cache #62042

nicholasmhughes opened this issue May 9, 2022 · 0 comments · Fixed by #62043
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@nicholasmhughes
Copy link
Collaborator

Description
Found a bug where an included Jinja template can still be loaded from the cache despite being removed from the Salt filesystem.

Setup

Create two test files on the Salt filesystem:

# /srv/salt/jinja_cache.sls
{% from "jinja_cache.jinja" import myvar -%}

test:
  test.show_notification:
    - text: {{ myvar }}
# /srv/salt/jinja_cache.jinja
{% set myvar = "hello" -%}

Steps to Reproduce the behavior

Applying the state file as-is produces the expected "hello" notification:

# salt-call state.apply jinja_cache
local:
----------
          ID: test
    Function: test.show_notification
      Result: True
     Comment: hello
     Started: 21:19:26.078569
    Duration: 0.329 ms
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.329 ms

...and changing the variable text like so:

{% set myvar = "world" -%}

...results in a changed notification text to match "world" from the variable as expected:

# salt-call state.apply jinja_cache
local:
----------
          ID: test
    Function: test.show_notification
      Result: True
     Comment: world
     Started: 21:19:37.647817
    Duration: 0.894 ms
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.894 ms

However, removing the included jinja file after it has already been cached can result in the file being loaded from cache despite no longer being present on the Salt filesystem:

# mv jinja_cache.jinja{,.bak}
# salt-call state.apply jinja_cache
local:
----------
          ID: test
    Function: test.show_notification
      Result: True
     Comment: world
     Started: 21:22:55.004962
    Duration: 0.386 ms
     Changes:   

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.386 ms

Expected behavior
After the Jinja file is removed from the Salt filesystem, the state should failed to run with a TemplateNotFound error. Loading cached files can result in user surprise when complex map loading decisions are made.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3004.1
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: Not Installed
         gitdb: 2.0.5
     gitpython: 2.1.11
        Jinja2: 2.10
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.5.6
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: 2.6.1
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.7.3 (default, Jan 22 2021, 20:04:44)
  python-gnupg: Not Installed
        PyYAML: 3.13
         PyZMQ: 17.1.2
         smmap: 2.0.5
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.1
 
System Versions:
          dist: debian 10 buster
        locale: UTF-8
       machine: x86_64
       release: 4.19.0-20-amd64
        system: Linux
       version: Debian GNU/Linux 10 buster
@nicholasmhughes nicholasmhughes added the Bug broken, incorrect, or confusing behavior label May 9, 2022
nicholasmhughes added a commit to nicholasmhughes/salt that referenced this issue May 9, 2022
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 needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants