<commit_before>import collections
import copy
import logging
import uuid
from contextlib import contextmanager

import requests
import retrying

from test_util.helpers import ApiClientSession, path_join

TEST_APP_NAME_FMT = 'integration-test-{}'
REQUIRED_HEADERS = {'Accept': 'application/json, text/plain, */*'}


def get_test_app(custom_port=False):
    test_uuid = uuid.uuid4().hex
    app = copy.deepcopy({
        'id': TEST_APP_NAME_FMT.format(test_uuid),
        'cpus': 0.1,
        'mem': 32,
        'instances': 1,
        'cmd': '/opt/mesosphere/bin/dcos-shell python '
               '/opt/mesosphere/active/dcos-integration-test/util/python_test_server.py ',
        'env': {
            'DCOS_TEST_UUID': test_uuid,
            # required for python_test_server.py to run as nobody
            'HOME': '/'
        },
        'healthChecks': [
            {
                'protocol': 'MESOS_HTTP',
                'path': '/ping',
                'portIndex': 0,
                'gracePeriodSeconds': 5,
                'intervalSeconds': 10,
                'timeoutSeconds': 10,
                'maxConsecutiveFailures': 3
            }
        ],
    })
    if not custom_port:
        app['cmd'] += '$PORT0'
        app['portDefinitions'] = [{
            "protocol": "tcp",
            "port": 0,
            "name": "test"
        }]
    return app, test_uuid


def get_test_app_in_docker(ip_per_container=False):
    app, test_uuid = get_test_app(custom_port=True)
    assert 'portDefinitions' not in app
    app['cmd'] += '9080'  # Fixed port for inside bridge networking or IP per container
    app['container'] = {
        'type': 'DOCKER',
        'docker': {
            # TODO(cmaloney): Switch to alpine with glibc
            'image': 'debian:jessie',
            'portMappings': [{
                'hostPort': 0,
                'containerPort': 9080,
                'protocol': 'tcp',
                'name': 'test',
                'labels': {}
            }]},
        'volumes': [{
            'containerPath': '/opt/mesosphere',
            'hostPath': '/opt/mesosphere',
            'mode': 'RO'
        }]
    }
    if ip_per_container:
        app['container']['docker']['network'] = 'USER'
        app['ipAddress'] = {'networkName': 'dcos'}
    else:
        app['container']['docker']['network'] = 'BRIDGE'
    return app, test_uuid


def get_test_app_in_ucr(healthcheck='HTTP'):
    app, test_uuid = get_test_app(custom_port=True)
    assert 'portDefinitions' not in app
    # UCR does NOT support portmappings host only.  must use $PORT0
    app['cmd'] = '$PORT0'
    app['container'] = {<commit_msg>adding in the + sign we lost along the merge<commit_after>import collections
import copy
import logging
import uuid
from contextlib import contextmanager

import requests
import retrying

from test_util.helpers import ApiClientSession, path_join

TEST_APP_NAME_FMT = 'integration-test-{}'
REQUIRED_HEADERS = {'Accept': 'application/json, text/plain, */*'}


def get_test_app(custom_port=False):
    test_uuid = uuid.uuid4().hex
    app = copy.deepcopy({
        'id': TEST_APP_NAME_FMT.format(test_uuid),
        'cpus': 0.1,
        'mem': 32,
        'instances': 1,
        'cmd': '/opt/mesosphere/bin/dcos-shell python '
               '/opt/mesosphere/active/dcos-integration-test/util/python_test_server.py ',
        'env': {
            'DCOS_TEST_UUID': test_uuid,
            # required for python_test_server.py to run as nobody
            'HOME': '/'
        },
        'healthChecks': [
            {
                'protocol': 'MESOS_HTTP',
                'path': '/ping',
                'portIndex': 0,
                'gracePeriodSeconds': 5,
                'intervalSeconds': 10,
                'timeoutSeconds': 10,
                'maxConsecutiveFailures': 3
            }
        ],
    })
    if not custom_port:
        app['cmd'] += '$PORT0'
        app['portDefinitions'] = [{
            "protocol": "tcp",
            "port": 0,
            "name": "test"
        }]
    return app, test_uuid


def get_test_app_in_docker(ip_per_container=False):
    app, test_uuid = get_test_app(custom_port=True)
    assert 'portDefinitions' not in app
    app['cmd'] += '9080'  # Fixed port for inside bridge networking or IP per container
    app['container'] = {
        'type': 'DOCKER',
        'docker': {
            # TODO(cmaloney): Switch to alpine with glibc
            'image': 'debian:jessie',
            'portMappings': [{
                'hostPort': 0,
                'containerPort': 9080,
                'protocol': 'tcp',
                'name': 'test',
                'labels': {}
            }]},
        'volumes': [{
            'containerPath': '/opt/mesosphere',
            'hostPath': '/opt/mesosphere',
            'mode': 'RO'
        }]
    }
    if ip_per_container:
        app['container']['docker']['network'] = 'USER'
        app['ipAddress'] = {'networkName': 'dcos'}
    else:
        app['container']['docker']['network'] = 'BRIDGE'
    return app, test_uuid


def get_test_app_in_ucr(healthcheck='HTTP'):
    app, test_uuid = get_test_app(custom_port=True)
    assert 'portDefinitions' not in app
    # UCR does NOT support portmappings host only.  must use $PORT0
    app['cmd'] += '$PORT0'
    app['container'] = {
{'fraction_non_alphanumeric': 0.13641488162344984, 'fraction_numerical': 0.00977076287110109, 'mean_word_length': 2.0486827033218784, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4081976', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1599, 'n_words': 354}