-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
win_copy: Add force parameter and check-mode support #20405
Conversation
784a348
to
0e2e273
Compare
707777e
to
cb333f1
Compare
creates/removes is ... weird for |
I knew you were going to say that :-) The So I will have to say I guess the name of all these parameters was a bad choice (since its name does make sense for all use-cases, quite the opposite sometimes)... |
84ec849
to
87ea122
Compare
a551c1e
to
8ff9589
Compare
Have it your way :-) As a bonus, to please the gods, I also added check-mode support ! |
8ff9589
to
2fb3ca5
Compare
After careful testing, it appears we have another problem. The checksumming is done first by the action plugin at the source (4GB), then again with a remote stat at the destination. And then again by the module itself on the copied source, old destination and copied destination. So in fact it is being done 5 times (once at the controlling master, and four times at the target node). Fine for small files, but it explains why it takes this long even if the file is already there and identical :-( Maybe we also need a dedicated option to disable any checksums. Update: I refactored some of the logic to delay the checksumming so we can avoid it for some codepaths. |
2fb3ca5
to
50763b3
Compare
@nitzmahone @jhawkesworth Is this ready to be merged ? |
@jborean93 @dagwieers the force parameter came 'late' to copy, it was added to allow 'not copying' a file, I agree it is not well named but the default behaviour (which |
@bcoca Can you sign this PR off ? I'd like to leave this one behind me now :-) |
@dagwieers you are not making the local checksum conditional on force? |
@bcoca Yes, we do. We only skip it when the file does not exist remotely. if dest_status['exists'] and not force:
# remote_file exists so continue to next iteration.
continue
# Generate a hash of the local file.
local_checksum = checksum(source_full) This was the original code BTW. I only corrected the comment. In your proposal it was not attempted when |
which i avoided with |
lib/ansible/plugins/action/copy.py
Outdated
try: | ||
source_full = self._loader.get_real_file(source_full) | ||
except AnsibleFileNotFound: | ||
e = get_exception() |
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.
just use as e
, controller supports >=2.6 so no need for this work around
@bcoca The very next line compares local_checksum with the remote checksum in case |
in my paste i had 'if force and ...` to avoid that, no preference either way. |
You are right, I missed that. Damnit, you win ! |
The rationale behind this is that if you're working with +3GB files, creating the checksum takes a lot of time, which we can avoid by simply testing if the file exists. I also took the liberty to put the various parameters together. It probably takes a (neglible) performance hit but makes the code a bit easier to inspect/work with, as its closer to all other windows modules. On a normal run, the action plugin does a local checksum of the source and a remote checksum of the destination. And afterwards, the module will do another remote checksum of the copied source, a remote checksum of the original destination, and another remote checksum of the copied destination. On a very huge file (think 4GB) that means 5x reading the complete file (if you have a large cache you may get away with it, otherwise you're doomed !). This patch will ensure with `force: no` that not checksums are being performed.
I always win, |
e79b43e
to
52d01ab
Compare
CI failure in integration tests due to:
|
52d01ab
to
b977f30
Compare
(single failure was the flaky win_service test, unrelated to anything about this) Thanks all for the input to get this one done! |
Yay!!!! |
ISSUE TYPE
COMPONENT NAME
win_copy
ANSIBLE VERSION
v2.3
SUMMARY
The rationale behind this is that if you're working with +3GB files,
creating the checksum takes a lot of time, which we can avoid by simply
testing if the file exists.
I also took the liberty to put the various parameters together. It
probably takes a (neglible) performance hit but makes the code a bit
easier to inspect/work with, as its closer to all other windows modules.
On a normal run, the action plugin does a local checksum of the source
and a remote checksum of the destination. And afterwards, the module
will do another remote checksum of the copied source, a remote checksum
of the original destination, and another remote checksum of the copied
destination.
On a very huge file (think 4GB) that means no less than 5x reading the
complete file If you have a large cache you may get away with it, otherwise
you're doomed !
This patch will ensure with
force: no
that no checksums are beingperformed by the action plugin and the module. We do this by delaying
the checksum calls until we have determined whether the destination in
fact exists. More optimisations are still possible, especially in the case the
destination does not exist (we don't need a checksum in that case anyhow).