Skip to content
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

Merged
merged 4 commits into from
Feb 25, 2017

Conversation

dagwieers
Copy link
Contributor

@dagwieers dagwieers commented Jan 18, 2017

ISSUE TYPE
  • Feature Pull Request
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 being
performed 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).

@ansibot
Copy link
Contributor

ansibot commented Jan 18, 2017

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 core_review In order to be merged, this PR must follow the core review workflow. feature_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. windows Windows community labels Jan 18, 2017
@dagwieers dagwieers changed the title win_copy: Add 'creates' parameter win_copy: Add creates/removes parameter Jan 19, 2017
@dagwieers dagwieers force-pushed the win_copy-creates branch 3 times, most recently from 707777e to cb333f1 Compare January 19, 2017 11:59
@nitzmahone
Copy link
Member

nitzmahone commented Jan 19, 2017

creates/removes is ... weird for win_copy IMO. For the use case you mentioned, the force arg as implemented by copy makes more sense to me.

@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Jan 19, 2017
@dagwieers
Copy link
Contributor Author

dagwieers commented Jan 19, 2017

I knew you were going to say that :-)

The force parameter is weird. In my case I want to skip the checksum on huge files, which is why creates: does make sense (it shorts the normal idempotency based on presence or absence of a file). I know it sounds pretty weird as win_copy' does not really remove something, but I figured it could be useful to base your decision to copy something on something else. (e.g. only install inkscape templates if the inkscape-directory exists, aka. removes`)

So I will have to say force: no to skip the checksum. These parameters are so wrong on so many levels it hurts :-/

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)...

@dagwieers dagwieers force-pushed the win_copy-creates branch 5 times, most recently from 84ec849 to 87ea122 Compare January 20, 2017 12:50
@dagwieers dagwieers changed the title win_copy: Add creates/removes parameter win_copy: Add force parameter and check-mode support Jan 20, 2017
@dagwieers dagwieers force-pushed the win_copy-creates branch 2 times, most recently from a551c1e to 8ff9589 Compare January 20, 2017 12:55
@dagwieers
Copy link
Contributor Author

Have it your way :-)

As a bonus, to please the gods, I also added check-mode support !

@dagwieers
Copy link
Contributor Author

dagwieers commented Jan 20, 2017

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.

@dagwieers
Copy link
Contributor Author

dagwieers commented Jan 25, 2017

@nitzmahone @jhawkesworth Is this ready to be merged ?

@bcoca
Copy link
Member

bcoca commented Feb 24, 2017

@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 force=true reflects) was always 'copy when we detect it is needed'. The force=no was added to allow for not copying when file existed even if it is different.

@dagwieers
Copy link
Contributor Author

@bcoca Can you sign this PR off ? I'd like to leave this one behind me now :-)

@bcoca
Copy link
Member

bcoca commented Feb 24, 2017

@dagwieers you are not making the local checksum conditional on force?

@dagwieers
Copy link
Contributor Author

dagwieers commented Feb 24, 2017

@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 force: no, but we do need it in case the remote file exists, otherwise it will fail because local_checksum was not defined.

@bcoca
Copy link
Member

bcoca commented Feb 24, 2017

which i avoided with if force prepended, you don't need it to decide a copy when force=no

try:
source_full = self._loader.get_real_file(source_full)
except AnsibleFileNotFound:
e = get_exception()
Copy link
Member

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

@dagwieers
Copy link
Contributor Author

dagwieers commented Feb 24, 2017

@bcoca The very next line compares local_checksum with the remote checksum in case force: yes or the remote file does not exist. So strictly it is not needed, but the code still expects it. We could of course initialize it to None to avoid it. Let me know what you prefer.

@bcoca
Copy link
Member

bcoca commented Feb 24, 2017

in my paste i had 'if force and ...` to avoid that, no preference either way.

@dagwieers
Copy link
Contributor Author

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.
@bcoca
Copy link
Member

bcoca commented Feb 24, 2017

I always win, <voice_of_tree_creature>I AM ROOT</voice_of_tree_creature>.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. core_review In order to be merged, this PR must follow the core review workflow. labels Feb 24, 2017
@mattclay
Copy link
Member

CI failure in integration tests due to:

2017-02-24 19:25:05 An exception occurred during task execution. The full traceback is:
2017-02-24 19:25:05 Traceback (most recent call last):
2017-02-24 19:25:05   File "/private/var/root/ansible/lib/ansible/executor/task_executor.py", line 126, in run
2017-02-24 19:25:05     res = self._execute()
2017-02-24 19:25:05   File "/private/var/root/ansible/lib/ansible/executor/task_executor.py", line 512, in _execute
2017-02-24 19:25:05     result = self._handler.run(task_vars=variables)
2017-02-24 19:25:05   File "/private/var/root/ansible/lib/ansible/plugins/action/copy.py", line 295, in run
2017-02-24 19:25:05     module_return['checksum'] = local_checksum
2017-02-24 19:25:05 UnboundLocalError: local variable 'local_checksum' referenced before assignment
2017-02-24 19:25:05 
2017-02-24 19:25:05 fatal: [testhost]: FAILED! => {
2017-02-24 19:25:05     "failed": true, 
2017-02-24 19:25:05     "msg": "Unexpected failure during module execution.", 
2017-02-24 19:25:05     "stdout": ""
2017-02-24 19:25:05 }

@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Feb 24, 2017
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Feb 24, 2017
@nitzmahone nitzmahone merged commit 9893493 into ansible:devel Feb 25, 2017
@nitzmahone
Copy link
Member

(single failure was the flaky win_service test, unrelated to anything about this)

Thanks all for the input to get this one done!

@jhawkesworth
Copy link
Contributor

Yay!!!!

@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 c:plugins/action feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants