Basic: don't call lstat when check_mode (#64279)
While mode is specified in check_mode, don't call lstat. Since file may not present. Fixes: #61185
This commit is contained in:
parent
b043afa025
commit
7099657dd7
3 changed files with 11 additions and 1 deletions
2
changelogs/fragments/61185-basic.py-fix-check_mode.yaml
Normal file
2
changelogs/fragments/61185-basic.py-fix-check_mode.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- AnsibleModule.set_mode_if_different - don't check file existence when check_mode is activated (https://github.com/ansible/ansible/issues/61185).
|
|
@ -890,11 +890,12 @@ class AnsibleModule(object):
|
|||
b_path = to_bytes(path, errors='surrogate_or_strict')
|
||||
if expand:
|
||||
b_path = os.path.expanduser(os.path.expandvars(b_path))
|
||||
path_stat = os.lstat(b_path)
|
||||
|
||||
if self.check_file_absent_if_check_mode(b_path):
|
||||
return True
|
||||
|
||||
path_stat = os.lstat(b_path)
|
||||
|
||||
if not isinstance(mode, int):
|
||||
try:
|
||||
mode = int(mode, 8)
|
||||
|
|
|
@ -100,6 +100,13 @@ def test_mode_unchanged_when_already_0660(am, mock_stats, mocker, mode, check_mo
|
|||
assert not m_lchmod.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize('mode, stdin', product(SYNONYMS_0660, ({},)), indirect=['stdin'])
|
||||
def test_mode_changed_to_0660_check_mode_no_file(am, mocker, mode):
|
||||
am.check_mode = True
|
||||
mocker.patch('os.path.exists', return_value=False)
|
||||
assert am.set_mode_if_different('/path/to/file', mode, False)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('check_mode, stdin',
|
||||
product((True, False), ({},)),
|
||||
indirect=['stdin'])
|
||||
|
|
Loading…
Reference in a new issue