<commit_before># Copyright ClusterHQ Inc.  See LICENSE file for details.

"""
Tests for the Flocker Docker plugin.
"""

import ssl
from twisted.trial.unittest import TestCase

from docker import Client
from docker.tls import TLSConfig
from docker.utils import create_host_config

from ...testtools import random_name
from ..testtools import (
    require_cluster, post_http_server, assert_http_server,
)
from ..scripts import SCRIPTS

DOCKER_PORT = 2376


class DockerPluginTests(TestCase):
    """
    Tests for the Docker plugin.
    """
    def run_python_container(self, cluster, address, docker_arguments, script,
                             script_arguments):
        """
        Run a Python script as a Docker container with the Flocker volume
        driver.

        This is a blocking call.

        :param Cluster cluster: Description of the cluster we're talking to.
        :param bytes address: The public IP of the node where it will run.
        :param dict docker_arguments: Additional arguments to pass to
            Docker run call.
        :param FilePath script: The script to run.
        :param list script_arguments: Additional arguments to pass to the
            script.

        :return: When Docker container has started.
        """
        def get_path(name):
            return cluster.certificates_path.child(name).path

        tls = TLSConfig(
            client_cert=(get_path(b"user.crt"), get_path(b"user.key")),
            # Blows up if not set
            # (https://github.com/shazow/urllib3/issues/695):
            ssl_version=ssl.PROTOCOL_TLSv1,
            # Don't validate hostname, we don't generate it correctly, but
            # do verify certificate authority signed the server certificate:
            assert_hostname=False,
            verify=get_path(b"cluster.crt"))
        client = Client(base_url="https://{}:{}".format(address, DOCKER_PORT),
                        tls=tls)

        # Remove all existing containers on the node, in case they're left
        # over from previous test:<commit_msg>Increase timeout just in case that's the problem.<commit_after># Copyright ClusterHQ Inc.  See LICENSE file for details.

"""
Tests for the Flocker Docker plugin.
"""

import ssl
from twisted.trial.unittest import TestCase

from docker import Client
from docker.tls import TLSConfig
from docker.utils import create_host_config

from ...testtools import random_name
from ..testtools import (
    require_cluster, post_http_server, assert_http_server,
)
from ..scripts import SCRIPTS

DOCKER_PORT = 2376


class DockerPluginTests(TestCase):
    """
    Tests for the Docker plugin.
    """
    def run_python_container(self, cluster, address, docker_arguments, script,
                             script_arguments):
        """
        Run a Python script as a Docker container with the Flocker volume
        driver.

        This is a blocking call.

        :param Cluster cluster: Description of the cluster we're talking to.
        :param bytes address: The public IP of the node where it will run.
        :param dict docker_arguments: Additional arguments to pass to
            Docker run call.
        :param FilePath script: The script to run.
        :param list script_arguments: Additional arguments to pass to the
            script.

        :return: When Docker container has started.
        """
        def get_path(name):
            return cluster.certificates_path.child(name).path

        tls = TLSConfig(
            client_cert=(get_path(b"user.crt"), get_path(b"user.key")),
            # Blows up if not set
            # (https://github.com/shazow/urllib3/issues/695):
            ssl_version=ssl.PROTOCOL_TLSv1,
            # Don't validate hostname, we don't generate it correctly, but
            # do verify certificate authority signed the server certificate:
            assert_hostname=False,
            verify=get_path(b"cluster.crt"))
        client = Client(base_url="https://{}:{}".format(address, DOCKER_PORT),
                        tls=tls, timeout=100)

        # Remove all existing containers on the node, in case they're left
        # over from previous test:
{'fraction_non_alphanumeric': 0.07631389488840892, 'fraction_numerical': 0.005039596832253419, 'mean_word_length': 2.4849498327759196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1880905', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1075, 'n_words': 389}