-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(utils/url): handle Windows relative path backslash when caching file #61829
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
🙌 Awesome find/fix! We discussed this a bit on Slack, and I think we've come to the conclusion that this is the right fix in the wrong place 🙃 Specifically, my thinking is that Naturally, the Salt master & minion should translate Soooo all of that being said, I'm totally on board with this fix, but since the documentation says that we're creating a Line 42 in fd216e1
\ - / only.
|
b009244
to
e2dd512
Compare
Thanks for the advice, @waynew. I made the adjustments and added a couple of tests. These are the failures before the proposed fix is applied: ======================================================================
FAIL: test_create_url_with_backslash_in_path (tests.unit.utils.test_url.UrlTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../salt/tests/unit/utils/test_url.py", line 81, in test_create_url_with_backslash_in_path
self.assertEqual(salt.utils.url.create(src_path), url)
AssertionError: 'salt://? interesting\\&path.filetype' != 'salt://? interesting/&path.filetype'
- salt://? interesting\&path.filetype
? ^
+ salt://? interesting/&path.filetype
? ^
======================================================================
FAIL: test_create_url_saltenv_with_backslash_in_path (tests.unit.utils.test_url.UrlTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../salt/tests/unit/utils/test_url.py", line 95, in test_create_url_saltenv_with_backslash_in_path
self.assertEqual(salt.utils.url.create(src_path, saltenv), url)
AssertionError: 'salt://? interesting\\&path.filetype?saltenv=raumklang' != 'salt://? interesting/&path.filetype?saltenv=raumklang'
- salt://? interesting\&path.filetype?saltenv=raumklang
? ^
+ salt://? interesting/&path.filetype?saltenv=raumklang
? ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jenkins.saltproject.io/job/pr-windows-2019-x64-py3-pytest/job/PR-61829/3/testReport/tests.pytests.unit.utils.jinja/test_salt_cache_loader/test_relative_import/ Mentioned in chat, but looks like there's a test that was requesting the broken behavior 🙃
Should just be a matter of changing the \
to /
in that test, though I'd double check to make sure that it really is an incorrect test 🤔
Fix saltstack#61040. Jinja imports with relative paths was introduced in saltstack#47490. Unfortunately, relative imports have never been working on Windows. That's due to backslashes being unhandled by the `cache_file` function: * https://github.com/saltstack/salt/blob/7275ecf073197faed26f3a571c25fcd59bfbfd60/salt/utils/jinja.py#L114 Instead of getting: * `salt://packages/map.jinja` We're ending up with: * `salt://packages\map.jinja` Thus, the file isn't cached from the master. There's actually a `FIXME` note about it: * https://github.com/saltstack/salt/blob/7275ecf073197faed26f3a571c25fcd59bfbfd60/salt/utils/jinja.py#L136 And the replacement is actually done for setting `tpldir`: * https://github.com/saltstack/salt/blob/7275ecf073197faed26f3a571c25fcd59bfbfd60/salt/utils/jinja.py#L165 This commit ensures the replacement is also done when caching files.
Heeeey! Checks all passing! 👍 must've just been some flaky infrastructure |
What does this PR do?
Jinja imports with relative paths was introduced in #47490.
Unfortunately, relative imports have never been working on Windows.
That's due to backslashes being unhandled by the
cache_file
function:salt/salt/utils/jinja.py
Line 114 in 7275ecf
Instead of getting:
salt://packages/map.jinja
We're ending up with:
salt://packages\map.jinja
Thus, the file isn't cached from the master.
There's actually a
FIXME
note about it:salt/salt/utils/jinja.py
Line 136 in 7275ecf
And the replacement is actually done for setting
tpldir
:salt/salt/utils/jinja.py
Line 165 in 7275ecf
This commit ensures the replacement is also done when caching files.
CC: @twangboy.
What issues does this PR fix or reference?
Fix #61040.
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes