Fix if_runtime_available decorator

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-01-04 12:45:31 -08:00
parent f22a1b6a2e
commit 74f616f208
2 changed files with 15 additions and 22 deletions

View File

@ -834,11 +834,11 @@ class ProjectTest(DockerClientTestCase):
service_container = project.get_service('web').containers()[0]
IPAMConfig = (service_container.inspect().get('NetworkSettings', {}).
get('Networks', {}).get('composetest_static_test', {}).
get('IPAMConfig', {}))
assert IPAMConfig.get('IPv4Address') == '172.16.100.100'
assert IPAMConfig.get('IPv6Address') == 'fe80::1001:102'
ipam_config = (service_container.inspect().get('NetworkSettings', {}).
get('Networks', {}).get('composetest_static_test', {}).
get('IPAMConfig', {}))
assert ipam_config.get('IPv4Address') == '172.16.100.100'
assert ipam_config.get('IPv6Address') == 'fe80::1001:102'
@v2_1_only()
def test_up_with_enable_ipv6(self):
@ -1032,6 +1032,7 @@ class ProjectTest(DockerClientTestCase):
project.up()
@v2_3_only()
@if_runtime_available('runc')
def test_up_with_runtime(self):
self.require_api_version('1.30')
config_data = build_config(

View File

@ -5,7 +5,6 @@ import functools
import os
import pytest
import six
from docker.errors import APIError
from docker.utils import version_lt
@ -157,22 +156,15 @@ class DockerClientTestCase(unittest.TestCase):
def if_runtime_available(runtime):
if runtime == 'nvidia':
command = 'nvidia-container-runtime'
if six.PY3:
import shutil
return pytest.mark.skipif(
shutil.which(command) is None,
reason="Nvida runtime not exists"
)
return pytest.mark.skipif(
any(
os.access(os.path.join(path, command), os.X_OK)
for path in os.environ["PATH"].split(os.pathsep)
) is False,
reason="Nvida runtime not exists"
)
return pytest.skip("Runtime %s not exists", runtime)
def decorator(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
if runtime not in self.client.info().get('Runtimes', {}):
return pytest.skip("This daemon does not support the '{}'' runtime".format(runtime))
return f(self, *args, **kwargs)
return wrapper
return decorator
def is_cluster(client):