<commit_before>""" Test using root marathon.
    This test suite imports all common tests found in marathon_common.py which are
    to be tested on root marathon and MoM.
    In addition it contains tests which are specific to root marathon, specifically
    tests round dcos services registration and control and security.
"""

import apps
import common
import json
import os
import pytest
import retrying
import shakedown
import time
import uuid

from dcos import marathon, errors
from datetime import timedelta

import dcos_service_marathon_tests
import marathon_auth_common_tests
import marathon_common_tests
import marathon_pods_tests

from shakedown import dcos_version_less_than, marthon_version_less_than, required_masters, required_public_agents # NOQA
from fixtures import wait_for_marathon_and_cleanup, events_to_file, user_billy # NOQA

# the following lines essentially do:
#     from dcos_service_marathon_tests import test_*
for attribute in dir(dcos_service_marathon_tests):
    if attribute.startswith('test_'):
        exec("from dcos_service_marathon_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_auth_common_tests import test_*
for attribute in dir(marathon_auth_common_tests):
    if attribute.startswith('test_'):
        exec("from marathon_auth_common_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_common_tests import test_*
for attribute in dir(marathon_common_tests):
    if attribute.startswith('test_'):
        exec("from marathon_common_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_pods_tests import test_*
for attribute in dir(marathon_pods_tests):
    if attribute.startswith('test_'):
        exec("from marathon_pods_tests import {}".format(attribute))


pytestmark = [pytest.mark.usefixtures('wait_for_marathon_and_cleanup')]


@pytest.fixture(scope="function")
def marathon_service_name():
    return "marathon"


def setup_module(module):
    common.cluster_info()
    common.clean_up_marathon()


def teardown_module(module):
    common.clean_up_marathon()


#################################################
# Root Marathon specific tests
#################################################


@shakedown.masters(3)
def test_marathon_delete_leader(marathon_service_name):
    original_leader = shakedown.marathon_leader_ip()
    print('leader: {}'.format(original_leader))
    common.delete_marathon_path('v2/leader')

    shakedown.wait_for_service_endpoint(marathon_service_name, timedelta(minutes=5).total_seconds())

    common.marathon_leadership_changed(original_leader)

<commit_msg>Introduce wait (and retries) before hitting v2/info MARATHON-7960 (#5822)<commit_after>""" Test using root marathon.
    This test suite imports all common tests found in marathon_common.py which are
    to be tested on root marathon and MoM.
    In addition it contains tests which are specific to root marathon, specifically
    tests round dcos services registration and control and security.
"""

import apps
import common
import json
import os
import pytest
import retrying
import shakedown
import time
import uuid

from dcos import marathon, errors
from datetime import timedelta

import dcos_service_marathon_tests
import marathon_auth_common_tests
import marathon_common_tests
import marathon_pods_tests

from shakedown import dcos_version_less_than, marthon_version_less_than, required_masters, required_public_agents # NOQA
from fixtures import wait_for_marathon_and_cleanup, events_to_file, user_billy # NOQA

# the following lines essentially do:
#     from dcos_service_marathon_tests import test_*
for attribute in dir(dcos_service_marathon_tests):
    if attribute.startswith('test_'):
        exec("from dcos_service_marathon_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_auth_common_tests import test_*
for attribute in dir(marathon_auth_common_tests):
    if attribute.startswith('test_'):
        exec("from marathon_auth_common_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_common_tests import test_*
for attribute in dir(marathon_common_tests):
    if attribute.startswith('test_'):
        exec("from marathon_common_tests import {}".format(attribute))

# the following lines essentially do:
#     from marathon_pods_tests import test_*
for attribute in dir(marathon_pods_tests):
    if attribute.startswith('test_'):
        exec("from marathon_pods_tests import {}".format(attribute))


pytestmark = [pytest.mark.usefixtures('wait_for_marathon_and_cleanup')]


@pytest.fixture(scope="function")
def marathon_service_name():
    return "marathon"


def setup_module(module):
    # When the cluster is starting, it might happen that there is some delay in:
    # - marathon leader registration with mesos
    # - admin router refreshing cache (every 30s)
    # We should not start our tests before marathon is accessible through service endpoint.
    shakedown.wait_for_service_endpoint('marathon', timedelta(minutes=5).total_seconds())

    common.cluster_info()
    common.clean_up_marathon()


def teardown_module(module):
    common.clean_up_marathon()


#################################################
# Root Marathon specific tests
#################################################


@shakedown.masters(3)
def test_marathon_delete_leader(marathon_service_name):
    original_leader = shakedown.marathon_leader_ip()
    print('leader: {}'.format(original_leader))
    common.delete_marathon_path('v2/leader')

    shakedown.wait_for_service_endpoint(marathon_service_name, timedelta(minutes=5).total_seconds())

    common.marathon_leadership_changed(original_leader)


{'fraction_non_alphanumeric': 0.10398613518197573, 'fraction_numerical': 0.003119584055459272, 'mean_word_length': 5.813459268004722, 'pattern_counts': {'":': 0, '<': 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': '6627338', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1607, 'n_words': 450}