Merge pull request #39474 from terminalmage/deprecate-dockerio

Move legacy docker state/exec module to salt-contrib, rename dockerng to docker
This commit is contained in:
Mike Place 2017-02-19 10:56:58 -07:00 committed by GitHub
commit 92cc2db1fd
22 changed files with 934 additions and 4831 deletions

View File

@ -108,8 +108,7 @@ execution modules
dnsmasq
dnsutil
dockercompose
dockerio
dockerng
docker
dpkg
drac
dracr

View File

@ -0,0 +1,7 @@
===================
salt.modules.docker
===================
.. automodule:: salt.modules.docker
:members:
:exclude-members: cp, freeze, unfreeze

View File

@ -1,6 +0,0 @@
=====================
salt.modules.dockerio
=====================
.. automodule:: salt.modules.dockerio
:members:

View File

@ -1,7 +0,0 @@
=====================
salt.modules.dockerng
=====================
.. automodule:: salt.modules.dockerng
:members:
:exclude-members: cp, freeze, unfreeze

View File

@ -71,8 +71,7 @@ state modules
debconfmod
dellchassis
disk
dockerio
dockerng
docker
drac
elasticsearch_index
elasticsearch_index_template

View File

@ -0,0 +1,6 @@
==================
salt.states.docker
==================
.. automodule:: salt.states.docker
:members:

View File

@ -1,6 +0,0 @@
====================
salt.states.dockerio
====================
.. automodule:: salt.states.dockerio
:members:

View File

@ -1,6 +0,0 @@
====================
salt.states.dockerng
====================
.. automodule:: salt.states.dockerng
:members:

View File

@ -188,7 +188,6 @@ dnspython
dnsservers
dnsutil
dockerfile
dockerio
docstring
docstrings
dpkg

View File

@ -139,11 +139,25 @@ Custom Refspecs in GitFS / git_pillar / winrepo
===============================================
It is now possible to specify the refspecs to use when fetching from remote
repositores for GitFS, git_pillar, and winrepo. More information on how this
repositories for GitFS, git_pillar, and winrepo. More information on how this
feature works can be found :ref:`here <gitfs-custom-refspecs>` in the GitFS
Walkthrough. The git_pillar and winrepo versions of this feature work the same
as their GitFS counterpart.
``dockerng`` State/Execution Module Renamed to ``docker``
=========================================================
The old ``docker`` state and execution modules have been moved to
salt-contrib_. The ``dockerng`` state and execution module have been renamed to
``docker`` and now serve as the official Docker state and execution modules.
These state and execution modules can be used interchangeably both with
``docker`` and ``dockerng`` to preserve backward-compatibility, but it is
recommended to update your SLS files to use ``docker`` instead of ``dockerng``
in event that the ``dockerng`` alias is dropped in a future release.
.. _salt-contrib: https://github.com/saltstack/salt-contrib
Deprecations
============

View File

@ -6,7 +6,7 @@ Common resources for LXC and systemd-nspawn containers
These functions are not designed to be called directly, but instead from the
:mod:`lxc <salt.modules.lxc>`, :mod:`nspawn <salt.modules.nspawn>`, and
:mod:`dockerng <salt.modules.dockerng>` execution modules. They provide for
:mod:`docker <salt.modules.docker>` execution modules. They provide for
common logic to be re-used for common actions.
'''
@ -40,7 +40,7 @@ def _validate(wrapped):
container_type = kwargs.get('container_type')
exec_driver = kwargs.get('exec_driver')
valid_driver = {
'dockerng': ('lxc-attach', 'nsenter', 'docker-exec'),
'docker': ('lxc-attach', 'nsenter', 'docker-exec'),
'lxc': ('lxc-attach',),
'nspawn': ('nsenter',),
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -407,7 +407,7 @@ def get_docker(interfaces=None, cidrs=None, with_container_id=False):
cidrs = cidr_
# Get docker info
cmd = 'dockerng.ps'
cmd = 'docker.ps'
docker_hosts = get('*', cmd)
proxy_lists = {}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,138 +0,0 @@
# -*- coding: utf-8 -*-
'''
Tests for integration with Docker's Python library
:codeauthor: :email:`C. R. Oldham <cr@saltstack.com>`
'''
# Import python libs
from __future__ import absolute_import
import os
import string
import logging
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath, requires_salt_modules
from salttesting import skipIf
ensure_in_syspath('../../')
# Import salt libs
import integration
log = logging.getLogger(__name__)
@requires_salt_modules('docker')
class DockerTest(integration.ModuleCase):
'''
Test docker integration
'''
def _get_container_id(self, image_name=None):
cmdstring = 'docker ps | grep {0}'.format(image_name)
ret_cmdrun = self.run_function('cmd.run_all', cmd=cmdstring)
ids = []
for l in ret_cmdrun['stdout'].splitlines():
try:
ids.append(string.split(ret_cmdrun['stdout'])[0])
except IndexError:
pass
return ids
def test_version(self):
'''
dockerio.version
'''
ret = self.run_function('docker.version')
ret_cmdrun = self.run_function('cmd.run_all', cmd='docker version | grep "Client version:"')
self.assertEqual('Client version: {0}'.format(ret['out']['Version']), ret_cmdrun['stdout'])
def test_build(self):
'''
dockerio.build
Long timeout here because build will transfer many images from the Internet
before actually creating the final container
'''
dockerfile_path = os.path.join(integration.INTEGRATION_TEST_DIR, 'files/file/base/')
ret = self.run_function('docker.build', timeout=300, path=dockerfile_path, tag='testsuite_image')
self.assertTrue(ret['status'], 'Image built')
def test_images(self):
'''
dockerio.get_images
'''
ret = self.run_function('docker.get_images')
foundit = False
for i in ret['out']:
try:
if i['RepoTags'][0] == 'testsuite_image:latest':
foundit = True
break
except KeyError:
pass
self.assertTrue(foundit, 'Could not find created image.')
def test_create_container(self):
'''
dockerio.create_container
'''
ret = self.run_function('docker.create_container', image='testsuite_image', command='echo ping')
self.assertTrue(ret['status'], 'Container was not created')
@skipIf(True, "Currently broken")
def test_stop(self):
'''
dockerio.stop
'''
container_id = self._get_container_id(image_name='testsuite_image')
self.assertTrue(container_id, 'test_stop: found no containers running')
for i in container_id:
ret = self.run_function('docker.stop', i)
self.assertFalse(self.run_function('docker.is_running', i))
@skipIf(True, "Currently broken")
def test_run_stdout(self):
'''
dockerio.run_stdout
The testsuite Dockerfile creates a file in the image's /tmp folder called 'cheese'
The Dockerfile is in salt/tests/integration/files/file/base/Dockerfile
'''
run_ret = self.run_function('docker.create_container', image='testsuite_image')
base_container_id = run_ret['id']
ret = self.run_function('docker.run_stdout', container=base_container_id, cmd="cat /tmp/cheese")
run_container_id = ret['id']
self.assertEqual(ret['out'], 'The cheese shop is open')
self.run_function('docker.stop', base_container_id)
self.run_function('docker.stop', run_container_id)
self.assertFalse(self.run_function('docker.is_running', base_container_id))
self.assertFalse(self.run_function('docker.is_running', run_container_id))
@skipIf(True, "Currently broken")
def test_commit(self):
'''
dockerio.commit
'''
run_ret = self.run_function('docker.create_container', image='testsuite_image')
log.debug("first container: {0}".format(run_ret))
base_container_id = run_ret['id']
ret = self.run_function('docker.run_stdout', container=base_container_id, cmd='echo "The cheese shop is now closed." > /tmp/deadcheese')
log.debug("second container: {0}".format(ret))
run_container_id = ret['id']
commit_ret = self.run_function('docker.commit', container=base_container_id, repository='testsuite_committed_img', message='This image was created by the testsuite')
log.debug("post-commit: {0}".format(commit_ret))
self.run_function('docker.stop', run_container_id)
new_container = self.run_function('docker.create_container', image='testsuite_committed_img')
final_ret = self.run_function('docker.run_stdout', container=new_container['id'], cmd='cat /tmp/cheese')
self.assertEqual(final_ret['out'], 'The cheese shop is now closed.')
if __name__ == '__main__':
from integration import run_tests
run_tests(DockerTest)

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
'''
Unit tests for the dockerng module
Unit tests for the docker module
'''
# Import Python Libs
@ -21,52 +21,52 @@ ensure_in_syspath('../../')
# Import Salt Libs
from salt.ext.six.moves import range
from salt.modules import dockerng as dockerng_mod
from salt.modules import docker as docker_mod
from salt.exceptions import CommandExecutionError, SaltInvocationError
dockerng_mod.__context__ = {'docker.docker_version': ''}
dockerng_mod.__salt__ = {}
dockerng_mod.__opts__ = {}
docker_mod.__context__ = {'docker.docker_version': ''}
docker_mod.__salt__ = {}
docker_mod.__opts__ = {}
def _docker_py_version():
return dockerng_mod.docker.version_info if dockerng_mod.HAS_DOCKER_PY else (0,)
return docker_mod.docker.version_info if docker_mod.HAS_DOCKER_PY else (0,)
@skipIf(NO_MOCK, NO_MOCK_REASON)
class DockerngTestCase(TestCase):
class DockerTestCase(TestCase):
'''
Validate dockerng module
Validate docker module
'''
def test_ps_with_host_true(self):
'''
Check that dockerng.ps called with host is ``True``,
Check that docker.ps called with host is ``True``,
include resutlt of ``network.interfaces`` command in returned result.
'''
network_interfaces = Mock(return_value={'mocked': None})
with patch.dict(dockerng_mod.__salt__,
with patch.dict(docker_mod.__salt__,
{'network.interfaces': network_interfaces}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': MagicMock()}):
ret = dockerng_mod.ps_(host=True)
ret = docker_mod.ps_(host=True)
self.assertEqual(ret,
{'host': {'interfaces': {'mocked': None}}})
def test_ps_with_filters(self):
'''
Check that dockerng.ps accept filters parameter.
Check that docker.ps accept filters parameter.
'''
client = MagicMock()
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.ps_(filters={'label': 'KEY'})
docker_mod.ps_(filters={'label': 'KEY'})
client.containers.assert_called_once_with(
all=True,
filters={'label': 'KEY'})
@skipIf(_docker_py_version() > 0, 'docker-py needs to be installed for this test to run')
@patch.object(dockerng_mod, '_get_exec_driver')
@patch.object(docker_mod, '_get_exec_driver')
def test_check_mine_cache_is_refreshed_on_container_change_event(self, _):
'''
Every command that might modify docker containers state.
@ -85,24 +85,24 @@ class DockerngTestCase(TestCase):
('_script', ('command',)),
):
mine_send = Mock()
command = getattr(dockerng_mod, command_name)
command = getattr(docker_mod, command_name)
docker_client = MagicMock()
docker_client.api_version = '1.12'
with patch.dict(dockerng_mod.__salt__,
with patch.dict(docker_mod.__salt__,
{'mine.send': mine_send,
'container_resource.run': MagicMock(),
'cp.cache_file': MagicMock(return_value=False)}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': docker_client}):
command('container', *args)
mine_send.assert_called_with('dockerng.ps', verbose=True, all=True,
mine_send.assert_called_with('docker.ps', verbose=True, all=True,
host=True)
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_with_arg_cmd(self, *args):
'''
When cmd argument is passed check it is renamed to command.
@ -116,11 +116,11 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create('image', cmd='ls', name='ctn')
docker_mod.create('image', cmd='ls', name='ctn')
client.create_container.assert_called_once_with(
command='ls',
host_config=host_config,
@ -129,9 +129,9 @@ class DockerngTestCase(TestCase):
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_send_host_config(self, *args):
'''
Check host_config object is passed to create_container.
@ -145,11 +145,11 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create('image', name='ctn', publish_all_ports=True)
docker_mod.create('image', name='ctn', publish_all_ports=True)
client.create_container.assert_called_once_with(
host_config=host_config,
image='image',
@ -157,9 +157,9 @@ class DockerngTestCase(TestCase):
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_with_labels_dict(self, *args):
'''
Create container with labels dictionary.
@ -173,11 +173,11 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create(
docker_mod.create(
'image',
name='ctn',
labels={'KEY': 'VALUE'},
@ -192,9 +192,9 @@ class DockerngTestCase(TestCase):
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_with_labels_list(self, *args):
'''
Create container with labels list.
@ -208,11 +208,11 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create(
docker_mod.create(
'image',
name='ctn',
labels=['KEY1', 'KEY2'],
@ -227,9 +227,9 @@ class DockerngTestCase(TestCase):
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_with_labels_error(self, *args):
'''
Create container with invalid labels.
@ -243,12 +243,12 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
self.assertRaises(SaltInvocationError,
dockerng_mod.create,
docker_mod.create,
'image',
name='ctn',
labels=22,
@ -257,9 +257,9 @@ class DockerngTestCase(TestCase):
@skipIf(_docker_py_version() < (1, 4, 0),
'docker module must be installed to run this test or is too old. >=1.4.0')
@patch.object(dockerng_mod, 'images', MagicMock())
@patch.object(dockerng_mod, 'inspect_image')
@patch.object(dockerng_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
@patch.object(docker_mod, 'images', MagicMock())
@patch.object(docker_mod, 'inspect_image')
@patch.object(docker_mod, 'version', Mock(return_value={'ApiVersion': '1.19'}))
def test_create_with_labels_dictlist(self, *args):
'''
Create container with labels dictlist.
@ -273,11 +273,11 @@ class DockerngTestCase(TestCase):
client.api_version = '1.19'
client.create_host_config.return_value = host_config
client.create_container.return_value = {}
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create(
docker_mod.create(
'image',
name='ctn',
labels=[{'KEY1': 'VALUE1'}, {'KEY2': 'VALUE2'}],
@ -303,11 +303,11 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.networks(
docker_mod.networks(
names=['foo'],
ids=['01234'],
)
@ -329,11 +329,11 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create_network(
docker_mod.create_network(
'foo',
driver='bridge',
)
@ -355,11 +355,11 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.remove_network('foo')
docker_mod.remove_network('foo')
client.remove_network.assert_called_once_with('foo')
@skipIf(_docker_py_version() < (1, 5, 0),
@ -375,11 +375,11 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.inspect_network('foo')
docker_mod.inspect_network('foo')
client.inspect_network.assert_called_once_with('foo')
@skipIf(_docker_py_version() < (1, 5, 0),
@ -395,13 +395,16 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
context = {'docker.client': client,
'docker.exec_driver': 'docker-exec'}
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
{'docker.client': client}):
dockerng_mod.connect_container_to_network('container', 'foo')
with patch.dict(docker_mod.__context__, context):
docker_mod.connect_container_to_network('container', 'foo')
client.connect_container_to_network.assert_called_once_with(
'container', 'foo')
'container', 'foo', None)
@skipIf(_docker_py_version() < (1, 5, 0),
'docker module must be installed to run this test or is too old. >=1.5.0')
@ -416,11 +419,11 @@ class DockerngTestCase(TestCase):
host_config = {}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.disconnect_container_from_network('container', 'foo')
docker_mod.disconnect_container_from_network('container', 'foo')
client.disconnect_container_from_network.assert_called_once_with(
'container', 'foo')
@ -436,11 +439,11 @@ class DockerngTestCase(TestCase):
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.volumes(
docker_mod.volumes(
filters={'dangling': [True]},
)
client.volumes.assert_called_once_with(
@ -459,11 +462,11 @@ class DockerngTestCase(TestCase):
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.create_volume(
docker_mod.create_volume(
'foo',
driver='bridge',
driver_opts={},
@ -486,11 +489,11 @@ class DockerngTestCase(TestCase):
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.remove_volume('foo')
docker_mod.remove_volume('foo')
client.remove_volume.assert_called_once_with('foo')
@skipIf(_docker_py_version() < (1, 5, 0),
@ -505,26 +508,26 @@ class DockerngTestCase(TestCase):
}
client = Mock()
client.api_version = '1.21'
with patch.dict(dockerng_mod.__dict__,
with patch.dict(docker_mod.__dict__,
{'__salt__': __salt__}):
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod.inspect_volume('foo')
docker_mod.inspect_volume('foo')
client.inspect_volume.assert_called_once_with('foo')
def test_wait_success(self):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=0)
dockerng_inspect_container = Mock(side_effect=[
docker_inspect_container = Mock(side_effect=[
{'State': {'Running': True}},
{'State': {'Stopped': True}}])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo')
docker_mod._clear_context()
result = docker_mod.wait('foo')
self.assertEqual(result, {'result': True,
'exit_status': 0,
'state': {'new': 'stopped',
@ -534,16 +537,16 @@ class DockerngTestCase(TestCase):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=0)
dockerng_inspect_container = Mock(side_effect=[
docker_inspect_container = Mock(side_effect=[
{'State': {'Stopped': True}},
{'State': {'Stopped': True}},
])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo')
docker_mod._clear_context()
result = docker_mod.wait('foo')
self.assertEqual(result, {'result': False,
'comment': "Container 'foo' already stopped",
'exit_status': 0,
@ -554,16 +557,16 @@ class DockerngTestCase(TestCase):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=0)
dockerng_inspect_container = Mock(side_effect=[
docker_inspect_container = Mock(side_effect=[
{'State': {'Stopped': True}},
{'State': {'Stopped': True}},
])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', ignore_already_stopped=True)
docker_mod._clear_context()
result = docker_mod.wait('foo', ignore_already_stopped=True)
self.assertEqual(result, {'result': True,
'comment': "Container 'foo' already stopped",
'exit_status': 0,
@ -573,13 +576,13 @@ class DockerngTestCase(TestCase):
def test_wait_success_absent_container(self):
client = Mock()
client.api_version = '1.21'
dockerng_inspect_container = Mock(side_effect=CommandExecutionError)
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
docker_inspect_container = Mock(side_effect=CommandExecutionError)
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', ignore_already_stopped=True)
docker_mod._clear_context()
result = docker_mod.wait('foo', ignore_already_stopped=True)
self.assertEqual(result, {'result': True,
'comment': "Container 'foo' absent"})
@ -587,15 +590,15 @@ class DockerngTestCase(TestCase):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=1)
dockerng_inspect_container = Mock(side_effect=[
docker_inspect_container = Mock(side_effect=[
{'State': {'Running': True}},
{'State': {'Stopped': True}}])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo', fail_on_exit_status=True)
docker_mod._clear_context()
result = docker_mod.wait('foo', fail_on_exit_status=True)
self.assertEqual(result, {'result': False,
'exit_status': 1,
'state': {'new': 'stopped',
@ -605,15 +608,15 @@ class DockerngTestCase(TestCase):
client = Mock()
client.api_version = '1.21'
client.wait = Mock(return_value=1)
dockerng_inspect_container = Mock(side_effect=[
docker_inspect_container = Mock(side_effect=[
{'State': {'Stopped': True}},
{'State': {'Stopped': True}}])
with patch.object(dockerng_mod, 'inspect_container',
dockerng_inspect_container):
with patch.dict(dockerng_mod.__context__,
with patch.object(docker_mod, 'inspect_container',
docker_inspect_container):
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.wait('foo',
docker_mod._clear_context()
result = docker_mod.wait('foo',
ignore_already_stopped=True,
fail_on_exit_status=True)
self.assertEqual(result, {'result': False,
@ -659,16 +662,15 @@ class DockerngTestCase(TestCase):
})
ret = None
with patch.dict(dockerng_mod.__salt__, {
'dockerng.start': docker_start_mock,
'dockerng.create': docker_create_mock,
'dockerng.stop': docker_stop_mock,
'dockerng.commit': docker_commit_mock,
'dockerng.sls': docker_sls_mock}):
ret = dockerng_mod.sls_build(
'foo',
mods='foo',
)
with patch.object(docker_mod, 'start', docker_start_mock):
with patch.object(docker_mod, 'create', docker_create_mock):
with patch.object(docker_mod, 'stop', docker_stop_mock):
with patch.object(docker_mod, 'commit', docker_commit_mock):
with patch.object(docker_mod, 'sls', docker_sls_mock):
ret = docker_mod.sls_build(
'foo',
mods='foo',
)
docker_create_mock.assert_called_once_with(
cmd='sleep infinity',
image='opensuse/python', interactive=True, name='foo', tty=True)
@ -716,17 +718,16 @@ class DockerngTestCase(TestCase):
})
ret = None
with patch.dict(dockerng_mod.__salt__, {
'dockerng.start': docker_start_mock,
'dockerng.create': docker_create_mock,
'dockerng.stop': docker_stop_mock,
'dockerng.rm': docker_rm_mock,
'dockerng.sls': docker_sls_mock}):
ret = dockerng_mod.sls_build(
'foo',
mods='foo',
dryrun=True
)
with patch.object(docker_mod, 'start', docker_start_mock):
with patch.object(docker_mod, 'create', docker_create_mock):
with patch.object(docker_mod, 'stop', docker_stop_mock):
with patch.object(docker_mod, 'rm_', docker_rm_mock):
with patch.object(docker_mod, 'sls', docker_sls_mock):
ret = docker_mod.sls_build(
'foo',
mods='foo',
dryrun=True
)
docker_create_mock.assert_called_once_with(
cmd='sleep infinity',
image='opensuse/python', interactive=True, name='foo', tty=True)
@ -778,18 +779,22 @@ class DockerngTestCase(TestCase):
client = Mock()
client.put_archive = Mock()
with patch.dict(dockerng_mod.__opts__, {'cachedir': '/tmp'}):
with patch.dict(dockerng_mod.__salt__, {'dockerng.run_all': docker_run_all_mock,
'dockerng.copy_to': docker_copy_to_mock,
'config.option': docker_config_mock}):
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
# call twice to verify tmp path later
for i in range(2):
ret = dockerng_mod.call(
'ID',
'test.arg',
1, 2,
arg1='val1')
context = {'docker.client': client,
'docker.exec_driver': 'docker-exec'}
salt_dunder = {'config.option': docker_config_mock}
with patch.object(docker_mod, 'run_all', docker_run_all_mock):
with patch.object(docker_mod, 'copy_to', docker_copy_to_mock):
with patch.dict(docker_mod.__opts__, {'cachedir': '/tmp'}):
with patch.dict(docker_mod.__salt__, salt_dunder):
with patch.dict(docker_mod.__context__, context):
# call twice to verify tmp path later
for i in range(2):
ret = docker_mod.call(
'ID',
'test.arg',
1, 2,
arg1='val1')
# Check that the directory is different each time
# [ call(name, [args]), ...
@ -823,14 +828,14 @@ class DockerngTestCase(TestCase):
{'Id': 'sha256:abcdef'},
{'Id': 'sha256:abcdefg',
'RepoTags': ['image:latest']}])
with patch.dict(dockerng_mod.__context__,
with patch.dict(docker_mod.__context__,
{'docker.client': client}):
dockerng_mod._clear_context()
result = dockerng_mod.images()
docker_mod._clear_context()
result = docker_mod.images()
self.assertEqual(result,
{'sha256:abcdefg': {'RepoTags': ['image:latest']}})
if __name__ == '__main__':
from integration import run_tests
run_tests(DockerngTestCase, needs_daemon=False)
run_tests(DockerTestCase, needs_daemon=False)

View File

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Mike Place <mp@saltstack.com>`
'''
# Import python libs
from __future__ import absolute_import
# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
from salt.modules import dockerio
HAS_DOCKER = dockerio.__virtual__()
@skipIf(not HAS_DOCKER, 'The docker execution module must be available to run the DockerIO test case')
class DockerIoTestCase(TestCase):
def test__sizeof_fmt(self):
self.assertEqual('0.0 bytes', dockerio._sizeof_fmt(0))
self.assertEqual('1.0 KB', dockerio._sizeof_fmt(1024))
self.assertEqual('1.0 MB', dockerio._sizeof_fmt(1024**2))
self.assertEqual('1.0 GB', dockerio._sizeof_fmt(1024**3))
self.assertEqual('1.0 TB', dockerio._sizeof_fmt(1024**4))
self.assertEqual('1.0 PB', dockerio._sizeof_fmt(1024**5))
if __name__ == '__main__':
from integration import run_tests
run_tests(DockerIoTestCase, needs_daemon=False)

View File

@ -33,7 +33,7 @@ class MineTestCase(TestCase):
'''
def test_get_docker(self):
'''
Test for Get all mine data for 'dockerng.ps' and run an
Test for Get all mine data for 'docker.ps' and run an
aggregation.
'''
ps_response = {
@ -81,7 +81,7 @@ class MineTestCase(TestCase):
def test_get_docker_with_container_id(self):
'''
Test for Get all mine data for 'dockerng.ps' and run an
Test for Get all mine data for 'docker.ps' and run an
aggregation.
'''
ps_response = {

View File

@ -1,113 +0,0 @@
# -*- coding: utf-8 -*-
# Import Python libs
from __future__ import absolute_import
from contextlib import contextmanager
# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock
@contextmanager
def provision_state(module, fixture):
previous_dict = getattr(module, '__salt__', {}).copy()
try:
module.__dict__.setdefault('__salt__', {}).update(fixture)
yield
finally:
setattr(module, '__salt__', previous_dict)
@skipIf(NO_MOCK, NO_MOCK_REASON)
@skipIf(True, 'Skipped: This module has been deprecated.')
class DockerStateTestCase(TestCase):
def test_docker_run_success(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=0),
'docker.run_all': MagicMock(
return_value={'stdout': '.\n..\n',
'stderr': '',
'status': True,
'comment': 'Success',
'retcode': 0})}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu')
self.assertEqual(result, {'name': 'ls /',
'result': True,
'comment': 'Success',
'changes': {}})
def test_docker_run_failure(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=0),
'docker.run_all': MagicMock(
return_value={'stdout': '',
'stderr': 'Error',
'status': False,
'comment': 'Failure',
'retcode': 1})}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu')
self.assertEqual(result, {'name': 'ls /',
'result': False,
'comment': 'Failure',
'changes': {}})
def test_docker_run_onlyif(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=1),
'docker.run_all': None}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu',
onlyif='ls -l')
self.assertEqual(result, {'name': 'ls /',
'result': True,
'comment': 'onlyif execution failed',
'changes': {}})
def test_docker_run_unless(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=0),
'docker.run_all': None}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu',
unless='ls -l')
self.assertEqual(result, {'name': 'ls /',
'result': True,
'comment': 'unless execution succeeded',
'changes': {}})
def test_docker_run_docked_onlyif(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=1),
'docker.run_all': None}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu',
docked_onlyif='ls -l')
self.assertEqual(result, {'name': 'ls /',
'result': True,
'comment': 'docked_onlyif execution failed',
'changes': {}})
def test_docker_run_docked_unless(self):
from salt.states import dockerio
salt_fixture = {'docker.retcode': MagicMock(return_value=0),
'docker.run_all': None}
with provision_state(dockerio, salt_fixture):
result = dockerio.run('ls /', 'ubuntu',
docked_unless='ls -l')
self.assertEqual(result, {'name': 'ls /',
'result': True,
'comment': ('docked_unless execution'
' succeeded'),
'changes': {}})
if __name__ == '__main__':
from integration import run_tests
run_tests(DockerStateTestCase, needs_daemon=False)