You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/units/modules
Sean Reifschneider 243aea45ce
Symbolic modes with X or =[ugo] always use original mode (#80132)
* Symbolic modes with X or =[ugo] always use original mode (Fixes #80128)

Here's what's happening, by way of this mode example: u=,u=rX

At the first step in the loop, the "u" bits of are set to 0. On the next
step in the loop, the current stat of the filesystem object is used to
determine X, not the "new_mode" in the previous iteration of the loop. So
while most operations kind of operate left to right, "X" is always going
back to the original file to determine whether to set x bit.

The Linux "chmod" (the only one I've tested) doesn't operate this way. In
it, "X" operates on the current state the loop understands it is in,
based on previous operations (and starting with the file permissions).

This is an issue with "X" and any of the "=[ugo]" settings, because
they are lookups. For example, if a file is 755 and you do "ug=rx,o=u",
file module produces 0557 and chmod produces 0555.

This really becomes a problem when you want to recursively change a
directory of files, and the files are currently 755, but you want to
change the directory to 750 and the files to 640. In chmod you can do
"a=,ug=rX,u+w" (or "a=,u=rwX,g=rX"), and have it apply equally to the
directory and the files. I can't come up with a single way in the ansible
file module to deterministically, recursively, set a directory to 750
and the contents to 640 no matter what the current permissions are,
as the code currently is.

The fix is to pass in "new_mode" to _get_octal_mode_from_symbolic_perms
in lib/ansible/module_utils/basic.py inside _symbolic_mode_to_octal. And
then take "new_mode" as an argument and use it instead of the filesystem
object stat.st_mode value.

* Fixing my new unit test, fixing bug in test comments
2 years ago
..
__init__.py
conftest.py Update collections.abc imports (#79911) 2 years ago
test_apt.py Prefer unittest.mock over mock. (#77886) 2 years ago
test_apt_key.py Prefer unittest.mock over mock. (#77886) 2 years ago
test_async_wrapper.py Clean up unused imports in unit tests (#79893) 2 years ago
test_copy.py Symbolic modes with X or =[ugo] always use original mode (#80132) 2 years ago
test_hostname.py Clean up unused imports in unit tests (#79893) 2 years ago
test_iptables.py Prefer unittest.mock over mock. (#77886) 2 years ago
test_known_hosts.py
test_pip.py
test_service.py
test_service_facts.py Prefer unittest.mock over mock. (#77886) 2 years ago
test_systemd.py
test_unarchive.py
test_yum.py yum: fix parsing of check-update with subsequent empty lines (#75452) 3 years ago
utils.py Prefer unittest.mock over mock. (#77886) 2 years ago