This adds a new decorator which creates a temporary directory and cleans
it after the test completes. It also modifies an existing decorator for
creating temporary files so that it accepts arguments, which will be
passed through to salt.utils.files.mkstemp().
This was partially fixed before 2018.3.0, but some careless programming
since then has caused problems to return. This fixes those by making
`file.lsattr` return `None` when lsattr is not installed, and then fixes
all references to take this into account.
PyYAML's scanner is not written to handle Python's unicode literal
strings, since they are not part of the YAML spec. With all strings
loaded in the YAML context now being unicode types, this causes errors
when scanning the document to construct the next node. The unicode
string literal is misidentified as a plain scalar and any colons within
it are interpreted as delimiting a mapping node. Since no whitespace appears
after the colon, this causes scanning error.
To fix it, we check for this scanning error and reset the scanner's
position and check if the first char is the "u" prefix. If so, and if
the following char is a quote, then we attempt to scan for a string
literal instead.
prepare test case:
# echo '{% import_yaml "a.yaml" as a with context %}' > a.sls
# echo 'a: {{ "now"|strftime }}' > a.yaml
remove 'import salt.utils.daeutils' from salt/utils/templates.py, then run
# salt-call state.sls a
[CRITICAL] Rendering SLS 'base:a' failed: Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 169, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 395, in render_jinja_tmpl
line, out = _get_jinja_error(trace, context=decoded_context)
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 248, in _get_jinja_error
line = _get_jinja_error_line(trace)
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 231, in _get_jinja_error_line
return _get_jinja_error_slug(tb_data)[1]
TypeError: 'NoneType' object has no attribute '__getitem__'
after apply the patch:
# salt-call state.sls a
Traceback (most recent call last):
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 169, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib64/python2.7/site-packages/salt/utils/templates.py", line 402, in render_jinja_tmpl
tmplstr)
SaltRenderError: Jinja syntax error: no filter named 'strftime'
/var/cache/salt/minion/files/base/a.yaml(1):
---
a: {{ "now"|strftime }} <======================
---
[CRITICAL] Rendering SLS 'base:a' failed: Jinja syntax error: no filter named 'strftime'
/var/cache/salt/minion/files/base/a.yaml(1):
---
a: {{ "now"|strftime }} <======================
---
which shows accurate information for debug.
The commit ba7d00f5 change _cpv_to_cp inner implementation, but the
original parameter cpv is not changed, its format is `<p>-<v>`, and
`dep_getkey` need format for `=<p>-<v>` if `cpv` with version, so it cause
`InvalidAtom` exception and actually return cpv itself. So I add the
original implementation back to fix this problem and still keep
`dep_getkey` if the cpv format will be fixed in the future