Commit a6f23c22 authored by Samuel GAIST's avatar Samuel GAIST

[test] Add test enabler for network related tests

This by default disable tests that requires the capabilities
to create new docker network on the fly.
parent 9161d67b
......@@ -35,7 +35,6 @@ import shutil
import tempfile
import pkg_resources
import logging
import docker
if sys.platform == 'darwin':
tmp_prefix = tempfile.mkdtemp(prefix=__name__,
......@@ -52,6 +51,8 @@ else:
prefix = os.path.join(prefix_folder, 'prefix')
DOCKER_NETWORK_TEST_ENABLED = os.environ.get('DOCKER_NETWORK_TEST_ENABLED', False) == 'True'
network_name = os.environ.get('DOCKER_TEST_NETWORK', 'beat_core_test_network')
network = None
......@@ -82,20 +83,22 @@ def setup_package():
for path in prefixes:
subprocess.check_call(['rsync', '-arz', path, prefix_folder])
client = docker.from_env()
try:
network = client.networks.get(network_name)
except docker.errors.NotFound:
subnet = os.environ.get('DOCKER_TEST_SUBNET', '193.169.0.0/24')
gateway = os.environ.get('DOCKER_TEST_GATEWAY', '193.169.0.254')
ipam_pool = docker.types.IPAMPool(subnet=subnet,
gateway=gateway)
if DOCKER_NETWORK_TEST_ENABLED:
import docker
client = docker.from_env()
try:
network = client.networks.get(network_name)
except docker.errors.NotFound:
subnet = os.environ.get('DOCKER_TEST_SUBNET', '193.169.0.0/24')
gateway = os.environ.get('DOCKER_TEST_GATEWAY', '193.169.0.254')
ipam_pool = docker.types.IPAMPool(subnet=subnet,
gateway=gateway)
ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool])
ipam_config = docker.types.IPAMConfig(pool_configs=[ipam_pool])
network = client.networks.create(network_name,
driver="bridge",
ipam=ipam_config)
network = client.networks.create(network_name,
driver="bridge",
ipam=ipam_config)
def teardown_package():
if os.path.exists(tmp_prefix):
......@@ -103,5 +106,6 @@ def teardown_package():
shutil.rmtree(prefix_folder)
if network:
network.remove()
if DOCKER_NETWORK_TEST_ENABLED:
if network:
network.remove()
......@@ -42,7 +42,10 @@ import nose
from ..dock import Host
from . import tmp_prefix
from .utils import slow
from .utils import skipif
from . import network_name
from . import DOCKER_NETWORK_TEST_ENABLED
class NoDiscoveryTests(unittest.TestCase):
"""Test cases that don't require the discovery of database and runtime
......@@ -67,6 +70,7 @@ class NoDiscoveryTests(unittest.TestCase):
class NetworkTest(NoDiscoveryTests):
@slow
@skipif(not DOCKER_NETWORK_TEST_ENABLED, "Network test disabled")
def test_network(self):
string = "hello world"
container = self.host.create_container('debian:8.4', ["echo", string])
......@@ -84,6 +88,7 @@ class NetworkTest(NoDiscoveryTests):
@slow
@skipif(not DOCKER_NETWORK_TEST_ENABLED, "Network test disabled")
def test_non_existing_network(self):
string = "hello world"
......
......@@ -33,10 +33,12 @@ from ..execution import DockerExecutor
from .utils import cleanup
from .utils import slow
from .utils import skipif
from .test_execution import BaseExecutionMixIn
from . import network_name
from . import DOCKER_NETWORK_TEST_ENABLED
#----------------------------------------------------------
......@@ -64,6 +66,7 @@ class TestDockerExecution(BaseExecutionMixIn):
dataformat_cache, database_cache, algorithm_cache)
@slow
@skipif(not DOCKER_NETWORK_TEST_ENABLED, "Network test disabled")
def test_custom_network(self):
result = self.execute('user/user/integers_addition/1/integers_addition',
[{'sum': 495, 'nb': 9}], network_name=network_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment