浏览代码

Fix if_runtime_available decorator

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 7 年之前
父节点
当前提交
74f616f208
共有 2 个文件被更改,包括 15 次插入22 次删除
  1. 6 5
      tests/integration/project_test.py
  2. 9 17
      tests/integration/testcases.py

+ 6 - 5
tests/integration/project_test.py

@@ -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(

+ 9 - 17
tests/integration/testcases.py

@@ -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):