Remove dependency on Zun
The tempest tests have some dependencies on some modules on Zun repo, but these modules are no longer available since tempest plugin became a separated repo now. Change-Id: Ic57ded871875c0481fdeedca19db2b61ab8d24c4
This commit is contained in:
parent
ef0fe2f646
commit
34fd39eceb
@ -13,3 +13,4 @@ testtools>=1.4.0 # MIT
|
||||
openstackdocstheme>=1.11.0 # Apache-2.0
|
||||
# releasenotes
|
||||
reno>=1.8.0 # Apache-2.0
|
||||
docker>=2.4.2 # Apache-2.0
|
||||
|
@ -10,10 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import contextlib
|
||||
import sys
|
||||
|
||||
from docker import errors as docker_errors
|
||||
import six
|
||||
import docker
|
||||
from six.moves.urllib import parse
|
||||
from tempest import config
|
||||
from tempest.lib.common import rest_client
|
||||
@ -22,14 +20,11 @@ from tempest.lib.services.network import ports_client
|
||||
from tempest.lib.services.network import security_groups_client
|
||||
from tempest import manager
|
||||
|
||||
from zun.common import exception
|
||||
import zun.conf
|
||||
from zun.container.docker import utils as docker_utils
|
||||
from zun_tempest_plugin.tests.tempest.api.models import container_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import service_model
|
||||
from zun_tempest_plugin.tests.tempest import utils
|
||||
|
||||
ZUN_CONF = zun.conf.CONF
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
@ -211,28 +206,45 @@ class ZunClient(rest_client.RestClient):
|
||||
|
||||
@contextlib.contextmanager
|
||||
def docker_client(docker_auth_url):
|
||||
client_kwargs = dict()
|
||||
if not ZUN_CONF.docker.api_insecure:
|
||||
client_kwargs['ca_cert'] = CONF.docker.ca_file
|
||||
client_kwargs['client_key'] = CONF.docker.key_file
|
||||
client_kwargs['client_cert'] = CONF.docker.key_file
|
||||
yield DockerHTTPClient(
|
||||
docker_auth_url,
|
||||
CONF.docker.docker_remote_api_version,
|
||||
CONF.docker.default_timeout
|
||||
)
|
||||
|
||||
try:
|
||||
yield docker_utils.DockerHTTPClient(
|
||||
docker_auth_url,
|
||||
ZUN_CONF.docker.docker_remote_api_version,
|
||||
ZUN_CONF.docker.default_timeout,
|
||||
**client_kwargs
|
||||
|
||||
class DockerHTTPClient(docker.APIClient):
|
||||
def __init__(self, url=CONF.docker.api_url,
|
||||
ver=CONF.docker.docker_remote_api_version,
|
||||
timeout=CONF.docker.default_timeout):
|
||||
super(DockerHTTPClient, self).__init__(
|
||||
base_url=url,
|
||||
version=ver,
|
||||
timeout=timeout,
|
||||
tls=False
|
||||
)
|
||||
except docker_errors.APIError as e:
|
||||
desired_exc = exception.DockerError(error_msg=six.text_type(e))
|
||||
six.reraise(type(desired_exc), desired_exc, sys.exc_info()[2])
|
||||
|
||||
def list_instances(self, inspect=False):
|
||||
"""List all containers."""
|
||||
res = []
|
||||
for container in self.containers(all=True):
|
||||
info = self.inspect_container(container['Id'])
|
||||
if not info:
|
||||
continue
|
||||
if inspect:
|
||||
res.append(info)
|
||||
else:
|
||||
res.append(info['Config'].get('Hostname'))
|
||||
return res
|
||||
|
||||
def list_containers(self):
|
||||
return self.containers(all=True, filters={'name': 'zun-'})
|
||||
|
||||
|
||||
class DockerClient(object):
|
||||
|
||||
def get_container(self, container_id,
|
||||
docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
for info in docker.list_instances(inspect=True):
|
||||
if container_id in info['Name']:
|
||||
@ -241,7 +253,7 @@ class DockerClient(object):
|
||||
|
||||
def ensure_container_pid_changed(
|
||||
self, container_id, pid,
|
||||
docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
docker_auth_url=CONF.docker.api_url):
|
||||
def is_pid_changed():
|
||||
container = self.get_container(container_id,
|
||||
docker_auth_url=docker_auth_url)
|
||||
@ -254,24 +266,24 @@ class DockerClient(object):
|
||||
|
||||
def pull_image(
|
||||
self, repo, tag=None,
|
||||
docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
docker.pull(repo, tag=tag)
|
||||
|
||||
def get_image(self, name, docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
def get_image(self, name, docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
return docker.get_image(name)
|
||||
|
||||
def delete_image(self, name, docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
def delete_image(self, name, docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
return docker.remove_image(name)
|
||||
|
||||
def list_networks(self, name,
|
||||
docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
return docker.networks(names=[name])
|
||||
|
||||
def remove_network(self, name,
|
||||
docker_auth_url=ZUN_CONF.docker.api_url):
|
||||
docker_auth_url=CONF.docker.api_url):
|
||||
with docker_client(docker_auth_url) as docker:
|
||||
return docker.remove_network(name)
|
||||
|
@ -11,6 +11,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import socket
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
service_option = cfg.BoolOpt("zun",
|
||||
@ -29,3 +31,30 @@ ContainerManagementGroup = [
|
||||
default=60,
|
||||
help="Waiting time for a specific status, in seconds.")
|
||||
]
|
||||
|
||||
docker_group = cfg.OptGroup(name='docker',
|
||||
title='Options for docker')
|
||||
|
||||
docker_opts = [
|
||||
cfg.StrOpt('docker_remote_api_version',
|
||||
default='1.26',
|
||||
help='Docker remote api version. Override it according to '
|
||||
'specific docker api version in your environment.'),
|
||||
cfg.IntOpt('default_timeout',
|
||||
default=60,
|
||||
help='Default timeout in seconds for docker client '
|
||||
'operations.'),
|
||||
cfg.StrOpt('api_url',
|
||||
default='unix:///var/run/docker.sock',
|
||||
help='API endpoint of docker daemon'),
|
||||
cfg.StrOpt('docker_remote_api_url',
|
||||
default='tcp://$docker_remote_api_host:$docker_remote_api_port',
|
||||
help='Remote API endpoint of docker daemon'),
|
||||
cfg.StrOpt('docker_remote_api_host',
|
||||
default=socket.gethostname(),
|
||||
sample_default='localhost',
|
||||
help='Defines the remote api host for the docker daemon.'),
|
||||
cfg.StrOpt('docker_remote_api_port',
|
||||
default='2375',
|
||||
help='Defines the remote api port for the docker daemon.'),
|
||||
]
|
||||
|
@ -34,6 +34,8 @@ class ZunTempestPlugin(plugins.TempestPlugin):
|
||||
conf.register_group(config_zun.container_management_group)
|
||||
conf.register_opts(config_zun.ContainerManagementGroup,
|
||||
group='container_management')
|
||||
conf.register_group(config_zun.docker_group)
|
||||
conf.register_opts(config_zun.docker_opts, group='docker')
|
||||
|
||||
def get_opt_lists(self):
|
||||
return [(config_zun.container_management_group.name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user