-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
If check mode enabled and file missing set changed to true 32676 #33967
If check mode enabled and file missing set changed to true 32676 #33967
Conversation
@@ -89,6 +92,7 @@ def test_mode_unchanged_when_already_0660(am, mock_stats, mocker, mode, check_mo | |||
am.check_mode = check_mode | |||
mocker.patch('os.lstat', side_effect=[mock_stats['after'], mock_stats['after'], mock_stats['after']]) | |||
m_lchmod = mocker.patch('os.lchmod', return_value=None, create=True) | |||
mocker.patch('os.path.exists', return_value=True) |
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.
For consistency, shouldn't you assert that this is called, like os.lchmod ?
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.
Following @Spredzy advice, in order to be consistent with mock of os.lstat
, assert not m_path_exists.called
was removed :)
We kept it only when return_value
of the os.path.exists
mock is parametrized.
Adding this assert for every os.path.exists
mock doesn't hurt, what do you think ?
CI Errors seems unrelated to these updates:
|
shipit |
3a942df
to
d130c09
Compare
d130c09
to
6123962
Compare
One minor update:
|
6123962
to
0a995d2
Compare
0a995d2
to
e6a22ad
Compare
lib/ansible/module_utils/basic.py
Outdated
@@ -1450,6 +1473,9 @@ def set_fs_attributes_if_different(self, file_args, changed, diff=None, expand=T | |||
) | |||
return changed | |||
|
|||
def check_file_absent_if_check_mode(self, file_path): | |||
return not os.path.exists(file_path) and self.check_mode |
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.
Tiny optimization: check self.check_mode before checking os.path.exists. That way in the common case we don't have to use a system call to determine if the path exists.
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.
Updated, thanks.
… to True Fixes ansible#32676 Thanks to mscherer and Spredzy for the distributed triplet programming session!
e6a22ad
to
4f7cd0d
Compare
@pilou- Looks good. I'm just waiting on the shippable tests to complete. |
Merged to devel and cherrypicked for 2.4.3rc1 |
SUMMARY
Modify
AnsibleModule.set_*_if_different
methods: whencheck_mode
is enabled and file is missing, returnsTrue
instead ofFalse
Unit tests updated.
Fixes #32676: this allows to avoid exception mentioned in the issue.
ISSUE TYPE
COMPONENT NAME
lib/ansible/module_utils/basic.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
Thanks to @mscherer and @Spredzy for the distributed triplet programming session.