2017-02-16 00:27:52 -08:00
|
|
|
#!/usr/bin/env python
|
2016-02-29 17:13:33 +05:30
|
|
|
|
|
|
|
# Copyright 2016 NEC Corporation
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2019-07-12 17:15:42 +02:00
|
|
|
# FIXME(yoctozepto): tests do not imitate how ansible would handle module args
|
|
|
|
|
2016-02-29 17:13:33 +05:30
|
|
|
import imp
|
|
|
|
import os
|
|
|
|
import sys
|
2020-04-02 18:12:37 +02:00
|
|
|
from unittest import mock
|
2016-02-29 17:13:33 +05:30
|
|
|
|
|
|
|
from oslotest import base
|
|
|
|
|
|
|
|
this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
2021-11-12 11:03:49 +01:00
|
|
|
ansible_dir = os.path.join(this_dir, '..', 'ansible')
|
|
|
|
kolla_docker_file = os.path.join(ansible_dir,
|
2016-02-29 17:13:33 +05:30
|
|
|
'library', 'kolla_docker.py')
|
2021-11-12 11:03:49 +01:00
|
|
|
docker_worker_file = os.path.join(ansible_dir,
|
|
|
|
'module_utils', 'kolla_docker_worker.py')
|
2016-02-29 17:13:33 +05:30
|
|
|
kd = imp.load_source('kolla_docker', kolla_docker_file)
|
2021-11-12 11:03:49 +01:00
|
|
|
dwm = imp.load_source('kolla_docker_worker', docker_worker_file)
|
2016-02-29 17:13:33 +05:30
|
|
|
|
|
|
|
|
|
|
|
class ModuleArgsTest(base.BaseTestCase):
|
|
|
|
|
|
|
|
def test_module_args(self):
|
|
|
|
argument_spec = dict(
|
|
|
|
common_options=dict(required=False, type='dict', default=dict()),
|
|
|
|
action=dict(
|
2016-09-25 20:13:54 +08:00
|
|
|
required=True, type='str',
|
2019-08-14 14:06:09 +00:00
|
|
|
choices=['compare_container',
|
|
|
|
'compare_image',
|
|
|
|
'create_volume',
|
|
|
|
'ensure_image',
|
|
|
|
'get_container_env',
|
|
|
|
'get_container_state',
|
|
|
|
'pull_image',
|
|
|
|
'recreate_or_restart_container',
|
|
|
|
'remove_container',
|
|
|
|
'remove_image',
|
|
|
|
'remove_volume',
|
|
|
|
'restart_container',
|
|
|
|
'start_container',
|
|
|
|
'stop_container',
|
|
|
|
'stop_and_remove_container']),
|
2023-01-17 13:26:24 +01:00
|
|
|
api_version=dict(required=False, type='str'),
|
2016-02-29 17:13:33 +05:30
|
|
|
auth_email=dict(required=False, type='str'),
|
2017-07-13 22:25:19 +02:00
|
|
|
auth_password=dict(required=False, type='str', no_log=True),
|
2016-02-29 17:13:33 +05:30
|
|
|
auth_registry=dict(required=False, type='str'),
|
|
|
|
auth_username=dict(required=False, type='str'),
|
2018-12-14 12:01:05 +00:00
|
|
|
command=dict(required=False, type='str'),
|
2016-02-29 17:13:33 +05:30
|
|
|
detach=dict(required=False, type='bool', default=True),
|
|
|
|
labels=dict(required=False, type='dict', default=dict()),
|
|
|
|
name=dict(required=False, type='str'),
|
|
|
|
environment=dict(required=False, type='dict'),
|
|
|
|
image=dict(required=False, type='str'),
|
2018-02-06 02:31:10 -05:00
|
|
|
ipc_mode=dict(required=False, type='str', choices=['',
|
|
|
|
'host',
|
|
|
|
'private',
|
|
|
|
'shareable']),
|
2016-02-29 17:13:33 +05:30
|
|
|
cap_add=dict(required=False, type='list', default=list()),
|
|
|
|
security_opt=dict(required=False, type='list', default=list()),
|
2022-11-02 16:54:33 +01:00
|
|
|
pid_mode=dict(required=False, type='str', choices=['',
|
|
|
|
'host',
|
|
|
|
'private']),
|
2021-05-11 12:04:25 +00:00
|
|
|
cgroupns_mode=dict(required=False, type='str',
|
|
|
|
choices=['private', 'host']),
|
2016-02-29 17:13:33 +05:30
|
|
|
privileged=dict(required=False, type='bool', default=False),
|
2023-01-17 13:26:24 +01:00
|
|
|
graceful_timeout=dict(required=False, type='int'),
|
2016-02-29 17:13:33 +05:30
|
|
|
remove_on_exit=dict(required=False, type='bool', default=True),
|
|
|
|
restart_policy=dict(
|
|
|
|
required=False, type='str', choices=['no',
|
|
|
|
'on-failure',
|
2016-09-23 02:25:23 -04:00
|
|
|
'always',
|
|
|
|
'unless-stopped']),
|
2023-01-17 13:26:24 +01:00
|
|
|
restart_retries=dict(required=False, type='int'),
|
2017-08-30 17:38:36 +02:00
|
|
|
state=dict(required=False, type='str', default='running',
|
|
|
|
choices=['running',
|
|
|
|
'exited',
|
|
|
|
'paused']),
|
2016-02-29 17:13:33 +05:30
|
|
|
tls_verify=dict(required=False, type='bool', default=False),
|
|
|
|
tls_cert=dict(required=False, type='str'),
|
|
|
|
tls_key=dict(required=False, type='str'),
|
|
|
|
tls_cacert=dict(required=False, type='str'),
|
2020-09-25 09:49:50 +00:00
|
|
|
tmpfs=dict(required=False, type='list'),
|
2016-02-29 17:13:33 +05:30
|
|
|
volumes=dict(required=False, type='list'),
|
2018-04-25 14:19:07 +05:30
|
|
|
volumes_from=dict(required=False, type='list'),
|
2018-12-05 10:04:52 +01:00
|
|
|
dimensions=dict(required=False, type='dict', default=dict()),
|
|
|
|
tty=dict(required=False, type='bool', default=False),
|
2023-01-17 13:26:24 +01:00
|
|
|
client_timeout=dict(required=False, type='int'),
|
2020-07-30 13:55:17 +02:00
|
|
|
healthcheck=dict(required=False, type='dict'),
|
2020-04-27 10:40:15 +02:00
|
|
|
ignore_missing=dict(required=False, type='bool', default=False),
|
2020-04-03 22:07:16 +02:00
|
|
|
)
|
2017-01-22 17:52:10 +08:00
|
|
|
required_if = [
|
|
|
|
['action', 'pull_image', ['image']],
|
|
|
|
['action', 'start_container', ['image', 'name']],
|
|
|
|
['action', 'compare_container', ['name']],
|
|
|
|
['action', 'compare_image', ['name']],
|
|
|
|
['action', 'create_volume', ['name']],
|
2019-08-14 14:06:09 +00:00
|
|
|
['action', 'ensure_image', ['image']],
|
2017-01-22 17:52:10 +08:00
|
|
|
['action', 'get_container_env', ['name']],
|
|
|
|
['action', 'get_container_state', ['name']],
|
|
|
|
['action', 'recreate_or_restart_container', ['name']],
|
|
|
|
['action', 'remove_container', ['name']],
|
2018-08-09 17:05:38 +02:00
|
|
|
['action', 'remove_image', ['image']],
|
2017-01-22 17:52:10 +08:00
|
|
|
['action', 'remove_volume', ['name']],
|
|
|
|
['action', 'restart_container', ['name']],
|
2019-06-07 13:48:36 +01:00
|
|
|
['action', 'stop_container', ['name']],
|
|
|
|
['action', 'stop_and_remove_container', ['name']],
|
2016-02-29 17:13:33 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
kd.AnsibleModule = mock.MagicMock()
|
|
|
|
kd.generate_module()
|
|
|
|
kd.AnsibleModule.assert_called_with(
|
|
|
|
argument_spec=argument_spec,
|
2017-01-22 17:52:10 +08:00
|
|
|
required_if=required_if,
|
|
|
|
bypass_checks=False
|
2016-02-29 17:13:33 +05:30
|
|
|
)
|