mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Mock out the get_client_args mocks in the dockerng module tests more aggressively
The tests pass fine when run independently, but when the full unit test suite runs, the dockerng state tests are setting global values. This change makes the module tests avoid those problem by relying on its own mocks.
This commit is contained in:
parent
f1352fe253
commit
0f263a52e0
1 changed files with 64 additions and 43 deletions
|
@ -38,6 +38,32 @@ class DockerngTestCase(TestCase):
|
|||
'''
|
||||
|
||||
docker_version = dockerng_mod.docker.version_info
|
||||
client_args_mock = MagicMock(return_value={
|
||||
'create_container': [
|
||||
'image', 'command', 'hostname', 'user', 'detach', 'stdin_open',
|
||||
'tty', 'ports', 'environment', 'volumes', 'network_disabled',
|
||||
'name', 'entrypoint', 'working_dir', 'domainname', 'cpuset',
|
||||
'host_config', 'mac_address', 'labels', 'volume_driver',
|
||||
'stop_signal', 'networking_config', 'healthcheck',
|
||||
'stop_timeout'],
|
||||
'host_config': [
|
||||
'binds', 'port_bindings', 'lxc_conf', 'publish_all_ports',
|
||||
'links', 'privileged', 'dns', 'dns_search', 'volumes_from',
|
||||
'network_mode', 'restart_policy', 'cap_add', 'cap_drop',
|
||||
'devices', 'extra_hosts', 'read_only', 'pid_mode', 'ipc_mode',
|
||||
'security_opt', 'ulimits', 'log_config', 'mem_limit',
|
||||
'memswap_limit', 'mem_reservation', 'kernel_memory',
|
||||
'mem_swappiness', 'cgroup_parent', 'group_add', 'cpu_quota',
|
||||
'cpu_period', 'blkio_weight', 'blkio_weight_device',
|
||||
'device_read_bps', 'device_write_bps', 'device_read_iops',
|
||||
'device_write_iops', 'oom_kill_disable', 'shm_size', 'sysctls',
|
||||
'tmpfs', 'oom_score_adj', 'dns_opt', 'cpu_shares',
|
||||
'cpuset_cpus', 'userns_mode', 'pids_limit', 'isolation',
|
||||
'auto_remove', 'storage_opt'],
|
||||
'networking_config': [
|
||||
'aliases', 'links', 'ipv4_address', 'ipv6_address',
|
||||
'link_local_ips'],
|
||||
})
|
||||
|
||||
def test_ps_with_host_true(self):
|
||||
'''
|
||||
|
@ -91,9 +117,9 @@ class DockerngTestCase(TestCase):
|
|||
{'mine.send': mine_send,
|
||||
'container_resource.run': MagicMock(),
|
||||
'cp.cache_file': MagicMock(return_value=False)}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': docker_client}):
|
||||
command('container', *args)
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': docker_client}):
|
||||
command('container', *args)
|
||||
mine_send.assert_called_with('dockerng.ps', verbose=True, all=True,
|
||||
host=True)
|
||||
|
||||
|
@ -115,11 +141,10 @@ 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__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create('image', cmd='ls', name='ctn')
|
||||
with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}):
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
|
||||
dockerng_mod.create('image', cmd='ls', name='ctn')
|
||||
client.create_container.assert_called_once_with(
|
||||
command='ls',
|
||||
host_config=host_config,
|
||||
|
@ -144,11 +169,10 @@ 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__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create('image', name='ctn', publish_all_ports=True)
|
||||
with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}):
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
|
||||
dockerng_mod.create('image', name='ctn', publish_all_ports=True)
|
||||
client.create_container.assert_called_once_with(
|
||||
host_config=host_config,
|
||||
image='image',
|
||||
|
@ -173,16 +197,15 @@ 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__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels={'KEY': 'VALUE'},
|
||||
validate_input=True,
|
||||
)
|
||||
with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}):
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels={'KEY': 'VALUE'},
|
||||
validate_input=True,
|
||||
)
|
||||
client.create_container.assert_called_once_with(
|
||||
labels={'KEY': 'VALUE'},
|
||||
host_config=host_config,
|
||||
|
@ -209,16 +232,15 @@ 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__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels=['KEY1', 'KEY2'],
|
||||
validate_input=True,
|
||||
)
|
||||
with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}):
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels=['KEY1', 'KEY2'],
|
||||
validate_input=True,
|
||||
)
|
||||
client.create_container.assert_called_once_with(
|
||||
labels=['KEY1', 'KEY2'],
|
||||
host_config=host_config,
|
||||
|
@ -276,16 +298,15 @@ 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__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels=[{'KEY1': 'VALUE1'}, {'KEY2': 'VALUE2'}],
|
||||
validate_input=True,
|
||||
)
|
||||
with patch.dict(dockerng_mod.__dict__, {'__salt__': __salt__}):
|
||||
with patch.object(dockerng_mod, 'get_client_args', self.client_args_mock):
|
||||
with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
|
||||
dockerng_mod.create(
|
||||
'image',
|
||||
name='ctn',
|
||||
labels=[{'KEY1': 'VALUE1'}, {'KEY2': 'VALUE2'}],
|
||||
validate_input=True,
|
||||
)
|
||||
client.create_container.assert_called_once_with(
|
||||
labels={'KEY1': 'VALUE1', 'KEY2': 'VALUE2'},
|
||||
host_config=host_config,
|
||||
|
|
Loading…
Add table
Reference in a new issue