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

fix(map): path_join can't be used to load YAML files on windows #80

Merged
merged 1 commit into from
Jul 24, 2020

Conversation

baby-gnu
Copy link
Contributor

@baby-gnu baby-gnu commented Jul 24, 2020

PR progress checklist (to be filled in by reviewers)

  • Changes to documentation are appropriate (or tick if not required)
  • Changes to tests are appropriate (or tick if not required)
  • Reviews completed

What type of PR is this?

Primary type

  • [build] Changes related to the build system
  • [chore] Changes to the build process or auxiliary tools and libraries such as documentation generation
  • [ci] Changes to the continuous integration configuration
  • [feat] A new feature
  • [fix] A bug fix
  • [perf] A code change that improves performance
  • [refactor] A code change that neither fixes a bug nor adds a feature
  • [revert] A change used to revert a previous commit
  • [style] Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)

Secondary type

  • [docs] Documentation changes
  • [test] Adding missing or correcting existing tests

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

Describe the changes you're proposing

It looks like path_join can't be used to build pathes for fileserver, it fails with jinja2.exceptions.TemplateNotFound.

  • libvirt/map.jinja: replace all path_join with string concatenation.

Pillar / config required to test the proposed changes

I created a test-map.sls with a minial parameters/defaults.yaml and execute it on a windows 10 minion version 3001:

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ '/map.jinja' import mapdata with context %}

test-map-jinja-on-windows:
  test.nop:
    - name: {{ mapdata | json }}

Debug log showing how the proposed changes work

Before:

    2020-07-24 07:33:16,410 [salt.state       :3968][CRITICAL][4864] Rendering SLS 'base:test-map' failed: Jinja error: test-map\parameters\defaults.yaml
    c:\salt\var\cache\salt\minion\files\base\test-map/map.jinja(17):
    ---
    [...]
    {%- set _defaults_filename = map_sources_dir | path_join("defaults.yaml") %}
    {%- do salt["log.debug"](
          "map.jinja: initialise parameters from "
          ~ _defaults_filename
        ) %}
    {%- import_yaml _defaults_filename as default_settings %}    <======================
    
    {#- List of sources to lookup for parameters #}
    {%- do salt["log.debug"]("map.jinja: lookup 'map_jinja' configuration sources") %}
    {#- Fallback to previously used grains plus minion `id` #}
    {%- set map_sources = [
    [...]
    ---
    Traceback (most recent call last):
      File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\utils\templates.py", line 400, in render_jinja_tmpl
        output = template.render(**decoded_context)
      File "c:\salt\bin\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
        return original_render(self, *args, **kwargs)
      File "c:\salt\bin\lib\site-packages\jinja2\environment.py", line 1008, in render
        return self.environment.handle_exception(exc_info, True)
      File "c:\salt\bin\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "c:\salt\bin\lib\site-packages\jinja2\_compat.py", line 37, in reraise
        raise value.with_traceback(tb)
      File "<template>", line 3, in top-level template code
      File "c:\salt\bin\lib\site-packages\jinja2\environment.py", line 1073, in make_module
        return TemplateModule(self, self.new_context(vars, shared, locals))
      File "c:\salt\bin\lib\site-packages\jinja2\environment.py", line 1152, in __init__
        body_stream = list(template.root_render_func(context))
      File "c:\salt\var\cache\salt\minion\files\base\test-map/map.jinja", line 17, in top-level template code
        {%- import_yaml _defaults_filename as default_settings %}
      File "c:\salt\bin\lib\site-packages\salt-3001-py3.7.egg\salt\utils\jinja.py", line 204, in get_source
        raise TemplateNotFound(template)
    jinja2.exceptions.TemplateNotFound: test-map\parameters\defaults.yaml

After:

          ID: test-map-jinja-on-windows
    Function: test.nop
      Result: True
     Comment: Success!
     Started: 07:49:32.738854
    Duration: 0.0 ms
     Changes:   

Documentation checklist

  • Updated the README (e.g. Available states).
  • Updated pillar.example.

Testing checklist

  • Included in Kitchen (i.e. under state_top).
  • Covered by new/existing tests (e.g. InSpec, Serverspec, etc.).
  • Updated the relevant test pillar.

Additional context

@pull-assistant
Copy link

pull-assistant bot commented Jul 24, 2020

Score: 1.00

Best reviewed: commit by commit


Optimal code review plan

     fix(map): path_join can't be used on windows

Powered by Pull Assistant. Last update c2b3465 ... c2b3465. Read the comment docs.

@baby-gnu baby-gnu requested a review from myii July 24, 2020 08:14
@baby-gnu baby-gnu changed the title fix(map): path_join can't be used on windows fix(map): path_join can't be used to load YAML files on windows Jul 24, 2020
libvirt/map.jinja Outdated Show resolved Hide resolved
It looks like `path_join` can't be used to build pathes for
`fileserver`, it fails with `jinja2.exceptions.TemplateNotFound`.

* libvirt/map.jinja: replace all `path_join` with string
  concatenation.
@myii myii merged commit d986cca into saltstack-formulas:master Jul 24, 2020
@saltstack-formulas-travis

🎉 This PR is included in version 3.8.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants