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 error when there are no docker volumes present yet #28145

Merged
merged 2 commits into from
Oct 30, 2017

Conversation

underwaynyc
Copy link
Contributor

@underwaynyc underwaynyc commented Aug 14, 2017

SUMMARY

The existing code will attempt to iterate over None. A quick if statement protects the for loop and returns None. Return of None because there are no volumes.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

In the cloud module, in the docker module, the docker_volume command

ANSIBLE VERSION
ansible 2.4.0 (devel cd32ed1929) last updated 2017/08/14 04:01:47 (GMT +000)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/underway/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/underway/underway-server/ansible-fork/lib/ansible
  executable location = /home/underway/underway-server/ansible-fork/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
ADDITIONAL INFORMATION

Attempt to create a volume, where there isn't one on the server yet. Manually do docker volume ls -q | xargs docker volume rm if needed

- name: Install pip
   easy_install:
    name: pip
    ��state: present

- name: Install docker-py via pip
   pip:
    name: docker-py
    state: present

- name: Create docker volume
  docker_volume:
     name: volume_name
     state: present

Before:

TASK [Create docker volume] *******************************************************************************************fatal: [HOST_NAME]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to HOST_NAME closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_wJEYrH/ansible_module_docker_volume.py\", line 254, in <module>\r\n    main()\r\n  File \"/tmp/ansible_wJEYrH/ansible_module_docker_volume.py\", line 249, in main\r\n    cm = DockerVolumeManager(client)\r\n  File \"/tmp/ansible_wJEYrH/ansible_module_docker_volume.py\", line 138, in __init__\r\n    self.existing_volume = self.get_existing_volume()\r\n  File \"/tmp/ansible_wJEYrH/ansible_module_docker_volume.py\", line 152, in get_existing_volume\r\n    for volume in volumes[u'Volumes']:\r\nTypeError: 'NoneType' object is not iterable\r\n", "msg": "MODULE FAILURE", "rc": 0}
        to retry, use: --limit @RETRY_FILE.retry

After:

TASK [Create docker volume ] ****************************************************************************************************changed: [HOSTNAME]

@ansibot
Copy link
Contributor

ansibot commented Aug 14, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bugfix_pull_request 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. labels Aug 14, 2017
@ansibot
Copy link
Contributor

ansibot commented Aug 14, 2017

The test ansible-test sanity --test pep8 failed with the following errors:

lib/ansible/modules/cloud/docker/docker_volume.py:152:32: E711 comparison to None should be 'if cond is None:'
lib/ansible/modules/cloud/docker/docker_volume.py:154:1: W293 blank line contains whitespace

click here for bot help

@ansibot ansibot added 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. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Aug 14, 2017
@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 Aug 14, 2017
@alikins alikins removed the needs_triage Needs a first human triage before being processed. label Aug 14, 2017
@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 Aug 22, 2017
@danramteke
Copy link

@chouseknecht @alikins Any word on this? Would love to get this fix in (or someone else's fix for the same error) so I can go back to using Ansible's master branch.

@agronholm
Copy link
Contributor

@chouseknecht it's too bad this didn't make it into 2.4.0.0, but it should be merged ASAP. I could not imagine that the Docker API would give a None instead of an empty list when there are no volumes.

@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Oct 18, 2017
@s-hertel
Copy link
Contributor

rebuild_merge

@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 30, 2017
@ansibot ansibot merged commit 11faafc into ansible:devel Oct 30, 2017
@ansibot ansibot added the bug This issue/PR relates to a bug. label Mar 6, 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.4 This issue/PR affects Ansible v2.4 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. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants