Tag v2-only tests
- Don't run them against Engine < 1.10 - Set the API version appropriately for the Engine version, so all tests use API version 1.22 against Engine 1.10 Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
abd031cb3d
commit
406b6b28f4
3 changed files with 49 additions and 1 deletions
|
|
@ -14,6 +14,7 @@ from compose.const import LABEL_PROJECT
|
|||
from compose.container import Container
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
from tests.integration.testcases import v2_only
|
||||
|
||||
|
||||
def build_service_dicts(service_config):
|
||||
|
|
@ -482,6 +483,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
service = project.get_service('web')
|
||||
self.assertEqual(len(service.containers()), 1)
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_networks(self):
|
||||
config_data = config.Config(
|
||||
version=2,
|
||||
|
|
@ -514,6 +516,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
foo_data = self.client.inspect_network('composetest_foo')
|
||||
self.assertEqual(foo_data['Driver'], 'bridge')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_volumes(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
|
@ -539,6 +542,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_logging_with_multiple_files(self):
|
||||
base_file = config.ConfigFile(
|
||||
'base.yml',
|
||||
|
|
@ -590,6 +594,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertTrue(log_config)
|
||||
self.assertEqual(log_config.get('Type'), 'none')
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
|
@ -614,6 +619,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_implicit_volume_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
|
@ -638,6 +644,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
self.assertEqual(volume_data['Name'], full_vol_name)
|
||||
self.assertEqual(volume_data['Driver'], 'local')
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_invalid_volume_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
||||
|
|
@ -659,6 +666,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
with self.assertRaises(config.ConfigurationError):
|
||||
project.initialize_volumes()
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_updated_driver(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
full_vol_name = 'composetest_{0}'.format(vol_name)
|
||||
|
|
@ -696,6 +704,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
vol_name
|
||||
) in str(e.exception)
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_external_volumes(self):
|
||||
# Use composetest_ prefix so it gets garbage-collected in tearDown()
|
||||
vol_name = 'composetest_{0:x}'.format(random.getrandbits(32))
|
||||
|
|
@ -722,6 +731,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
with self.assertRaises(NotFound):
|
||||
self.client.inspect_volume(full_vol_name)
|
||||
|
||||
@v2_only()
|
||||
def test_initialize_volumes_inexistent_external_volume(self):
|
||||
vol_name = '{0:x}'.format(random.getrandbits(32))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import os
|
||||
|
||||
from docker.utils import version_lt
|
||||
from pytest import skip
|
||||
|
||||
from .. import unittest
|
||||
from compose.cli.docker_client import docker_client
|
||||
from compose.config.config import resolve_environment
|
||||
from compose.const import API_VERSIONS
|
||||
from compose.const import LABEL_PROJECT
|
||||
from compose.progress_stream import stream_output
|
||||
from compose.service import Service
|
||||
|
|
@ -26,10 +30,35 @@ def get_links(container):
|
|||
return [format_link(link) for link in links]
|
||||
|
||||
|
||||
def engine_version_too_low_for_v2():
|
||||
if 'DOCKER_VERSION' not in os.environ:
|
||||
return False
|
||||
version = os.environ['DOCKER_VERSION'].partition('-')[0]
|
||||
return version_lt(version, '1.10')
|
||||
|
||||
|
||||
def v2_only():
|
||||
def decorator(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if engine_version_too_low_for_v2():
|
||||
skip("Engine version is too low")
|
||||
return
|
||||
return f(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class DockerClientTestCase(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.client = docker_client()
|
||||
if engine_version_too_low_for_v2():
|
||||
version = API_VERSIONS[1]
|
||||
else:
|
||||
version = API_VERSIONS[2]
|
||||
|
||||
cls.client = docker_client(version)
|
||||
|
||||
def tearDown(self):
|
||||
for c in self.client.containers(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue