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

[docker_container] Failing on non-string env values #49843

Merged
merged 3 commits into from
Dec 14, 2018
Merged

[docker_container] Failing on non-string env values #49843

merged 3 commits into from
Dec 14, 2018

Conversation

DBendit
Copy link
Contributor

@DBendit DBendit commented Dec 12, 2018

SUMMARY

Fixes #49802

Fail the module when non-string env values are used. Avoids issues (documented by @felixfontein below) around data loss due to YAML parsing.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

docker_container

ADDITIONAL INFORMATION

N/A

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. labels Dec 12, 2018
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

I'm not sure this is a good idea. We have no clue what exactly the user wanted (yes/true/True/..., no/false/False/...), and we currently simply select a random variant (true/false). It's probably better to fail and advise the user to quote this correctly. The official values accepted by YAML as booleans are y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF (see here).

The clean_dict_booleans_for_docker_api function has so far been used in situations where certain boolean strings are more likely (namely true and false). But here, any of these variants is equally likely.

Instead of making a random choice, we should fail when we find a non-string (the same problem is true if the user writes 1.00, which will end up as 1.0 by being converted to a float first -- depending on the context this is ok, or absolutely not ok).

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. needs_triage Needs a first human triage before being processed. labels Dec 13, 2018
@DBendit DBendit changed the title [docker_container] Cleaning env of Python booleans [docker_container] Failing on non-string env values Dec 13, 2018
@DBendit
Copy link
Contributor Author

DBendit commented Dec 13, 2018

@felixfontein Alright, I've redone it all to error out on non-string values. I've had my fair share of issues with YAML in the past, but I didn't realize that data loss was one of them. Totally with you - failure (with a helpful error message) is better than silent data loss.

ready_for_review

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 13, 2018
felixfontein and others added 2 commits December 13, 2018 16:54
Co-Authored-By: DBendit <David@ibendit.com>
@DBendit
Copy link
Contributor Author

DBendit commented Dec 13, 2018

Updated.

ready_for_review

Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

LGTM

@felixfontein
Copy link
Contributor

bot_status

@ansibot
Copy link
Contributor

ansibot commented Dec 14, 2018

Components

changelogs/fragments/49843-docker_container-wrap-env.yaml
support: community
maintainers:

lib/ansible/modules/cloud/docker/docker_container.py
support: community
maintainers: DBendit akshay196 chouseknecht cove danihodovic dariko dusdanig felixfontein joshuaconner jwitko kassiansun softzilla tbouvet zfil

test/integration/targets/docker_container/tasks/tests/options.yml
support: community
maintainers: DBendit akshay196 chouseknecht cove danihodovic dariko dusdanig felixfontein joshuaconner jwitko kassiansun softzilla tbouvet zfil

Metadata

waiting_on: maintainer
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 1
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 1
shipit_actors (maintainers or core team members): felixfontein DBendit
shipit_actors_other: []
automerge: automerge !module file(s) test failed

click here for bot help

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels Dec 14, 2018
@sivel sivel merged commit d62d717 into ansible:devel Dec 14, 2018
maxamillion added a commit to maxamillion/ansible that referenced this pull request Dec 14, 2018
* devel:
  Fix yum/dnf handling of URIs that don't end in .rpm (ansible#49912)
  [docker_container] Failing on non-string env values (ansible#49843)
  [docker_volume] Checking option minimal versions (ansible#49839)
  Support for cache_from parameter in docker_image module (ansible#49787)
  Move verify up so approle and other methods work as intended.
@felixfontein
Copy link
Contributor

@DBendit thanks for the PR! Do you want to create a backport PR for it?
@sivel thanks for merging!

@felixfontein
Copy link
Contributor

@DBendit please don't forget the backport PR for this and #49839 :-)

@DBendit
Copy link
Contributor Author

DBendit commented Jan 4, 2019

@felixfontein I completely had! Thank you for the reminder. Still trying to get back into the swing of things post-holidays

@felixfontein
Copy link
Contributor

@DBendit no problem :) There will probably be a new 2.7 release next week, so backports should probably be there until next Monday or so. (If you don't have time, I can also create them, just tell me.)

kbreit pushed a commit to kbreit/ansible that referenced this pull request Jan 11, 2019
* [docker_container] Failing on non-string env values

Fixes ansible#49802

* Clarify failure message

Co-Authored-By: DBendit <David@ibendit.com>

* Fixup from review
felixfontein pushed a commit to felixfontein/ansible that referenced this pull request Jan 14, 2019
* [docker_container] Failing on non-string env values

Fixes ansible#49802

* Clarify failure message

Co-Authored-By: DBendit <David@ibendit.com>

* Fixup from review

(cherry picked from commit d62d717)
@felixfontein
Copy link
Contributor

@DBendit I created a backport in #50899 for this one; I also noticed that the other one was a Feature PR, so it won't get backported anyway. I hope you don't mind me creating the backport, I just wanted to have it in 2.7.6 :)

abadger pushed a commit that referenced this pull request Jan 15, 2019
* [docker_container] Failing on non-string env values (#49843)

* [docker_container] Failing on non-string env values

Fixes #49802

* Clarify failure message

Co-Authored-By: DBendit <David@ibendit.com>

* Fixup from review

(cherry picked from commit d62d717)

* Turn fail into warning for 2.7 backport.

* Fix test for backport

The behaviour in the backport is to warn rather than error
@ansible ansible locked and limited conversation to collaborators Jul 22, 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. cloud docker module This issue/PR relates to a module. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discrepancy in results from Docker container started with Ansible docker_container versus Docker CLI commands
4 participants