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

get_url: return no change in check mode when checksum matches #53070

Merged
merged 1 commit into from Mar 1, 2019

Conversation

fanf2
Copy link
Contributor

@fanf2 fanf2 commented Feb 27, 2019

SUMMARY

In check_mode, get_url does not compare the checksum with the destination file, so it produces spurious changed results which turn out to be green when check_mode is False.

This change moves the check_mode logic a little bit later in get_url so that the destination file checksum is available for comparison with the source file checksum.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

get_url

ADDITIONAL INFORMATION

I have updated the get_url test with a case that illustrates this problem and fix.

Signed-off-by: Tony Finch <dot@dotat.at>
@jpmens
Copy link
Contributor

jpmens commented Feb 27, 2019

shipit

@ansibot
Copy link
Contributor

ansibot commented Feb 27, 2019

cc @ptux
click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. net_tools Net-tools category new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Feb 27, 2019
if module.check_mode:
if os.path.exists(tmpsrc):
os.remove(tmpsrc)
result['changed'] = ('checksum_dest' not in result or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd better add a test for 'checksum_dest' not in result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the existing check_mode tests already cover that case, or have I missed something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.

the following test case covers your code.

name: test HTTP HEAD request for file in check mode

@ptux
Copy link
Contributor

ptux commented Mar 1, 2019

shipit

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 1, 2019
@gundalow gundalow merged commit ccad79d into ansible:devel Mar 1, 2019
@gundalow
Copy link
Contributor

gundalow commented Mar 1, 2019

@fanf2 Thank you for this fix and for extending the tests
@jpmens @ptux Thank you for the reviews.

@fanf2 If you'd like to see this fixed in the next Ansible 2.7 release please raise a backport PR with a changelog/fragment by following https://docs.ansible.com/ansible/devel/community/development_process.html#making-your-pr-merge-worthy

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. net_tools Net-tools category new_contributor This PR is the first contribution by a new community member. shipit This PR is ready to be merged by Core support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants