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

Bug 42787 create volume with label #46527

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ansible/module_utils/docker_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@


if not HAS_DOCKER_PY:
docker_version = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you add this here? Is this used by any of the modules?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, and that doesn't work if docker_version has not been defined?

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't work if docker_version has not been defined.


# No docker-py. Create a place holder client to allow
# instantiation of AnsibleModule and proper error handing
class Client(object): # noqa: F811
Expand Down
31 changes: 31 additions & 0 deletions test/units/modules/cloud/docker/test_docker_volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2018 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import json

import pytest

from ansible.modules.cloud.docker import docker_volume
from ansible.module_utils import docker_common

pytestmark = pytest.mark.usefixtures('patch_ansible_module')

TESTCASE_DOCKER_VOLUME = [
{
'name': 'daemon_config',
'state': 'present'
}
]


@pytest.mark.parametrize('patch_ansible_module', TESTCASE_DOCKER_VOLUME, indirect=['patch_ansible_module'])
def test_create_volume_on_invalid_docker_version(mocker, capfd):
mocker.patch.object(docker_common, 'HAS_DOCKER_PY', True)
mocker.patch.object(docker_common, 'docker_version', '1.8.0')

with pytest.raises(SystemExit):
docker_volume.main()

out, dummy = capfd.readouterr()
results = json.loads(out)
assert results['failed']
assert 'Error: docker / docker-py version is 1.8.0. Minimum version required is 1.10.0.' in results['msg']