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

fix: Parse docker_service scale parameter to int #45508

Merged
merged 1 commit into from
Oct 17, 2018

Conversation

danihodovic
Copy link
Contributor

@danihodovic danihodovic commented Sep 11, 2018

SUMMARY

Parses the scale parameter to an int. If scale is interpolated with jinja
(e.g when performing arithmetics) it will be a string.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

docker_service

ANSIBLE VERSION
ansible 2.7.0rc1
  config file = /home/dani/ansible/ansible.cfg
  configured module search path = [u'/home/dani/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/dani/.local/lib/python2.7/site-packages/ansible
  executable location = /home/dani/.local/bin/ansible
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
ADDITIONAL INFORMATION

When passing scale to the docker_service module to start N number of containers
it expects an int. For directly defined values, e.g 5 this works. However for more
complex values, e.g '{{ (ansible_processor_vcpus - 1) }}' it doesn't because a string
is passed to the module due to jinja interpolation.

This commit resolves the issue by attempting to parse scale to an int and
failing with an informative error message if the value cannot be parsed.

@ansibot
Copy link
Contributor

ansibot commented Sep 11, 2018

@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. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 11, 2018
@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. labels Sep 11, 2018
@danihodovic danihodovic force-pushed the fix/parse-docker-service-scale branch 2 times, most recently from 1a88cff to fe177f6 Compare September 11, 2018 19:00
@ansibot
Copy link
Contributor

ansibot commented Sep 11, 2018

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/modules/cloud/docker/docker_service.py:1030:25: undefined-variable Undefined variable 's'

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Sep 11, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Sep 11, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Sep 13, 2018
@danihodovic
Copy link
Contributor Author

I'm unsure how to prove that this works with tests as I saw no unit test file corresponding to docker_service.

Here's an example of the fix running locally:
https://asciinema.org/a/QbMAmQC1zlPAhTbOAysEgWd8G

$ \cat docker-compose.yml
---
version: '2.4'
services:
  nginx:
    image: nginx
$ \cat test.yml
---
- name: Playbook
  hosts: localhost
  vars:
    cpus: '{{ ansible_processor_vcpus - 1 }}'
  tasks:
    - debug: var=ansible_processor_vcpus

    - name: docker service
      docker_service:
        project_src: .
        scale:
          nginx: '{{ cpus }}'

@danihodovic
Copy link
Contributor Author

bot_status

@ansibot
Copy link
Contributor

ansibot commented Sep 19, 2018

Components

lib/ansible/modules/cloud/docker/docker_service.py
support: community
maintainers: chouseknecht

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): 0
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 0
shipit_actors (maintainer or core team member): []
shipit_actors_other: []
automerge: automerge shipit test failed

click here for bot help

@danihodovic
Copy link
Contributor Author

ready_for_review

@danihodovic
Copy link
Contributor Author

@chouseknecht any chance you could have a look at this?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Sep 26, 2018
@danihodovic danihodovic force-pushed the fix/parse-docker-service-scale branch from 55ecce9 to 23ff14d Compare October 3, 2018 17:45
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Oct 12, 2018
@felixfontein
Copy link
Contributor

shipit

(since the last one probably was cleared because of the rebase)

@felixfontein
Copy link
Contributor

bot_status

1 similar comment
@danihodovic
Copy link
Contributor Author

bot_status

@ansibot
Copy link
Contributor

ansibot commented Oct 16, 2018

Components

lib/ansible/modules/cloud/docker/docker_service.py
support: community
maintainers: chouseknecht

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): 0
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 1
shipit_actors (maintainers or core team members): felixfontein
shipit_actors_other: []
automerge: automerge shipit test failed

click here for bot help

@felixfontein
Copy link
Contributor

@danihodovic ansibot seems to be pretty slow for a couple of days now...

@dariko @jwitko @kassiansun @tbouvet Can anyone of you take a look here?

@jwitko
Copy link
Contributor

jwitko commented Oct 17, 2018

LGTM

@ansibot ansibot added automerge This PR was automatically merged by ansibot. 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 Oct 17, 2018
@ansibot ansibot merged commit 28ba10b into ansible:devel Oct 17, 2018
@danihodovic danihodovic deleted the fix/parse-docker-service-scale branch October 17, 2018 19:38
danihodovic added a commit to danihodovic/ansible that referenced this pull request Oct 17, 2018
@felixfontein
Copy link
Contributor

Awesome! @danihodovic thanks for your work on this! @jwitko thanks for reviewing!

@danihodovic Do you want to create backport PRs (for Ansible 2.6 and 2.7) for this? I can do that, but in case you want to try this yourself... :) Here are some instructions: https://docs.ansible.com/ansible/latest/community/development_process.html#backport-pull-request-process

Also, we forgot to add a changelog for this fix. I guess that's ok for devel, but we should really add something for the backports. You can find an example here: https://github.com/ansible/ansible/blob/devel/changelogs/fragments/46595-docker_container-expected_ports.yml

danihodovic added a commit to danihodovic/ansible that referenced this pull request Oct 17, 2018
danihodovic added a commit to danihodovic/ansible that referenced this pull request Oct 17, 2018
abadger pushed a commit that referenced this pull request Oct 22, 2018
* fix: Parse docker_service scale parameter to int (#45508)

* Changelog: add fragment for docker_service scale fix
mattclay pushed a commit that referenced this pull request Nov 6, 2018
* fix: Parse docker_service scale parameter to int (#45508)

* Changelog: add fragment for docker_service scale fix
Tomorrow9 pushed a commit to Tomorrow9/ansible that referenced this pull request Dec 4, 2018
@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 automerge This PR was automatically merged by ansibot. bug This issue/PR relates to a bug. cloud docker module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants