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

Projects
None yet
6 participants
@underwaynyc
Contributor

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

This comment has been minimized.

Contributor

ansibot commented Aug 14, 2017

@ansibot

This comment has been minimized.

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

@danramteke

This comment has been minimized.

danramteke commented Sep 6, 2017

@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

This comment has been minimized.

Contributor

agronholm commented Sep 21, 2017

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

@s-hertel

This comment has been minimized.

Contributor

s-hertel commented Oct 30, 2017

rebuild_merge

@ansibot ansibot removed the stale_ci label Oct 30, 2017

@ansibot ansibot merged commit 11faafc into ansible:devel Oct 30, 2017

1 check passed

Shippable Run 42461 status is SUCCESS.
Details

@ansibot ansibot added bug and removed bugfix_pull_request labels Mar 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment