Пример #1
0
def cluster(user):
    assert 'DCOS_DNS_ADDRESS' in os.environ
    assert 'MASTER_HOSTS' in os.environ
    assert 'PUBLIC_MASTER_HOSTS' in os.environ
    assert 'SLAVE_HOSTS' in os.environ
    assert 'PUBLIC_SLAVE_HOSTS' in os.environ
    assert 'DNS_SEARCH' in os.environ
    assert 'DCOS_PROVIDER' in os.environ

    # dns_search must be true or false (prevents misspellings)
    assert os.environ['DNS_SEARCH'] in ['true', 'false']

    assert os.environ['DCOS_PROVIDER'] in ['onprem', 'aws', 'azure']

    cluster_api = ClusterApi(
        dcos_uri=os.environ['DCOS_DNS_ADDRESS'],
        masters=os.environ['MASTER_HOSTS'].split(','),
        public_masters=os.environ['PUBLIC_MASTER_HOSTS'].split(','),
        slaves=os.environ['SLAVE_HOSTS'].split(','),
        public_slaves=os.environ['PUBLIC_SLAVE_HOSTS'].split(','),
        dns_search_set=os.environ['DNS_SEARCH'],
        provider=os.environ['DCOS_PROVIDER'],
        auth_enabled=os.getenv('DCOS_AUTH_ENABLED', 'true') == 'true',
        web_auth_default_user=user,
        default_os_user=os.getenv('DCOS_DEFAULT_OS_USER', 'root'))
    cluster_api.wait_for_dcos()
    return cluster_api
Пример #2
0
def cluster(user):
    assert 'DCOS_DNS_ADDRESS' in os.environ
    assert 'MASTER_HOSTS' in os.environ
    assert 'PUBLIC_MASTER_HOSTS' in os.environ
    assert 'SLAVE_HOSTS' in os.environ
    assert 'PUBLIC_SLAVE_HOSTS' in os.environ
    assert 'DNS_SEARCH' in os.environ
    assert 'DCOS_PROVIDER' in os.environ

    # dns_search must be true or false (prevents misspellings)
    assert os.environ['DNS_SEARCH'] in ['true', 'false']

    assert os.environ['DCOS_PROVIDER'] in ['onprem', 'aws', 'azure']

    logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', level=LOG_LEVEL)
    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("botocore").setLevel(logging.WARNING)

    cluster_api = ClusterApi(
        dcos_uri=os.environ['DCOS_DNS_ADDRESS'],
        masters=os.environ['MASTER_HOSTS'].split(','),
        public_masters=os.environ['PUBLIC_MASTER_HOSTS'].split(','),
        slaves=os.environ['SLAVE_HOSTS'].split(','),
        public_slaves=os.environ['PUBLIC_SLAVE_HOSTS'].split(','),
        dns_search_set=os.environ['DNS_SEARCH'],
        provider=os.environ['DCOS_PROVIDER'],
        auth_enabled=os.getenv('DCOS_AUTH_ENABLED', 'true') == 'true',
        web_auth_default_user=user,
        default_os_user=os.getenv('DCOS_DEFAULT_OS_USER', 'root'))
    cluster_api.wait_for_dcos()
    return cluster_api
Пример #3
0
def make_cluster_fixture():
    # token valid until 2036 for user [email protected]
    # {
    #   "email": "*****@*****.**",
    #   "email_verified": true,
    #   "iss": "https://dcos.auth0.com/",
    #   "sub": "google-oauth2|109964499011108905050",
    #   "aud": "3yF5TOSzdlI45Q1xspxzeoGBe9fNxm9m",
    #   "exp": 2090884974,
    #   "iat": 1460164974
    # }
    auth_json = {'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik9UQkVOakZFTWtWQ09VRTRPRVpGTlRNMFJrWXlRa015Tnprd1JrSkVRemRCTWpBM1FqYzVOZyJ9.eyJlbWFpbCI6ImFsYmVydEBiZWtzdGlsLm5ldCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczovL2Rjb3MuYXV0aDAuY29tLyIsInN1YiI6Imdvb2dsZS1vYXV0aDJ8MTA5OTY0NDk5MDExMTA4OTA1MDUwIiwiYXVkIjoiM3lGNVRPU3pkbEk0NVExeHNweHplb0dCZTlmTnhtOW0iLCJleHAiOjIwOTA4ODQ5NzQsImlhdCI6MTQ2MDE2NDk3NH0.OxcoJJp06L1z2_41_p65FriEGkPzwFB_0pA9ULCvwvzJ8pJXw9hLbmsx-23aY2f-ydwJ7LSibL9i5NbQSR2riJWTcW4N7tLLCCMeFXKEK4hErN2hyxz71Fl765EjQSO5KD1A-HsOPr3ZZPoGTBjE0-EFtmXkSlHb1T2zd0Z8T5Z2-q96WkFoT6PiEdbrDA-e47LKtRmqsddnPZnp0xmMQdTr2MjpVgvqG7TlRvxDcYc-62rkwQXDNSWsW61FcKfQ-TRIZSf2GS9F9esDF4b5tRtrXcBNaorYa9ql0XAWH5W_ct4ylRNl3vwkYKWa4cmPvOqT5Wlj9Tf0af4lNO40PQ'}  # noqa
    if 'DCOS_AUTH_JSON_PATH' in os.environ:
        auth_json = load_json(os.environ['DCOS_AUTH_JSON_PATH'])
    args = get_args_from_env()
    args['web_auth_default_user'] = DcosUser(auth_json)
    cluster_api = ClusterApi(**args)
    cluster_api.wait_for_dcos()
    return cluster_api
Пример #4
0
def main():
    num_masters = int(os.getenv('MASTERS', '3'))
    num_agents = int(os.getenv('AGENTS', '2'))
    num_public_agents = int(os.getenv('PUBLIC_AGENTS', '1'))
    stack_name = 'upgrade-test-' + ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(10))

    test_cmd = os.getenv('DCOS_PYTEST_CMD',
                         'py.test -vv -s -rs ' + os.getenv('CI_FLAGS', ''))

    stable_installer_url = os.environ['STABLE_INSTALLER_URL']
    installer_url = os.environ['INSTALLER_URL']

    vpc, ssh_info = test_util.aws.VpcCfStack.create(
        stack_name=stack_name,
        instance_type='m4.xlarge',
        instance_os='cent-os-7-dcos-prereqs',
        # An instance for each cluster node plus the bootstrap.
        instance_count=(num_masters + num_agents + num_public_agents + 1),
        admin_location='0.0.0.0/0',
        key_pair_name='default',
        boto_wrapper=test_util.aws.BotoWrapper(
            region=os.getenv('DEFAULT_AWS_REGION', 'eu-central-1'),
            aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
            aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'),
        ),
    )
    vpc.wait_for_stack_creation()
    cluster = test_util.cluster.Cluster.from_vpc(
        vpc,
        ssh_info,
        ssh_key=load_string(os.getenv('DCOS_SSH_KEY_PATH', 'default_ssh_key')),
        num_masters=num_masters,
        num_agents=num_agents,
        num_public_agents=num_public_agents,
    )

    # Use the CLI installer to set exhibitor_storage_backend = zookeeper.
    test_util.cluster.install_dcos(cluster, stable_installer_url, api=False)

    master_list = [h.private_ip for h in cluster.masters]

    cluster_api = ClusterApi(
        'http://{ip}'.format(ip=cluster.masters[0].public_ip),
        master_list,
        master_list,
        [h.private_ip for h in cluster.agents],
        [h.private_ip for h in cluster.public_agents],
        "root",  # default_os_user
        web_auth_default_user=DcosUser(CI_AUTH_JSON),
        ca_cert_path=None)

    cluster_api.wait_for_dcos()

    # Deploy an app
    cluster_api.marathon.deploy_app(get_test_app())

    task_info_before_upgrade = get_task_info(
        cluster_api.marathon.get('v2/apps').json(),
        cluster_api.marathon.get('v2/tasks').json())

    assert task_info_before_upgrade is not None, "Unable to get task details of the cluster."
    assert task_info_before_upgrade.state == "TASK_RUNNING", "Task is not in the running state."

    with cluster.ssher.tunnel(cluster.bootstrap_host) as bootstrap_host_tunnel:
        bootstrap_host_tunnel.remote_cmd(
            ['sudo', 'rm', '-rf', cluster.ssher.home_dir + '/*'])

    test_util.cluster.upgrade_dcos(cluster, installer_url)

    task_info_after_upgrade = get_task_info(
        cluster_api.marathon.get('v2/apps').json(),
        cluster_api.marathon.get('v2/tasks').json())

    assert task_info_after_upgrade is not None, "Unable to get the tasks details of the cluster."
    assert task_info_after_upgrade.state == "TASK_RUNNING", "Task is not in the running state."

    assert task_info_before_upgrade.id == task_info_after_upgrade.id, \
        "Task ID before and after the upgrade did not match."

    # There has happened at least one health-check in the new cluster since the last health-check in the old cluster.
    assert (task_info_after_upgrade.last_success_time >
            task_info_before_upgrade.last_success_time + task_info_before_upgrade.health_check_interval), \
        "Invalid health-check for the task in the upgraded cluster."

    result = test_util.cluster.run_integration_tests(cluster,
                                                     test_cmd=test_cmd)

    if result == 0:
        log.info("Test successsful! Deleting VPC if provided in this run...")
        vpc.delete()
    else:
        log.info(
            "Test failed! VPC cluster will remain available for debugging for 2 hour after instantiation."
        )
    sys.exit(result)
Пример #5
0
def main():
    num_masters = int(os.getenv('MASTERS', '3'))
    num_agents = int(os.getenv('AGENTS', '2'))
    num_public_agents = int(os.getenv('PUBLIC_AGENTS', '1'))
    stack_name = 'upgrade-test-' + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))

    test_cmd = os.getenv('DCOS_PYTEST_CMD', 'py.test -vv -s -rs ' + os.getenv('CI_FLAGS', ''))

    stable_installer_url = os.environ['STABLE_INSTALLER_URL']
    installer_url = os.environ['INSTALLER_URL']

    vpc, ssh_info = test_util.aws.VpcCfStack.create(
        stack_name=stack_name,
        instance_type='m4.xlarge',
        instance_os='cent-os-7-dcos-prereqs',
        # An instance for each cluster node plus the bootstrap.
        instance_count=(num_masters + num_agents + num_public_agents + 1),
        admin_location='0.0.0.0/0',
        key_pair_name='default',
        boto_wrapper=test_util.aws.BotoWrapper(
            region=os.getenv('DEFAULT_AWS_REGION', 'eu-central-1'),
            aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
            aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'),
        ),
    )
    vpc.wait_for_stack_creation()
    cluster = test_util.cluster.Cluster.from_vpc(
        vpc,
        ssh_info,
        ssh_key=load_string(os.getenv('DCOS_SSH_KEY_PATH', 'default_ssh_key')),
        num_masters=num_masters,
        num_agents=num_agents,
        num_public_agents=num_public_agents,
    )

    # Use the CLI installer to set exhibitor_storage_backend = zookeeper.
    test_util.cluster.install_dcos(cluster, stable_installer_url, api=False)

    master_list = [h.private_ip for h in cluster.masters]

    cluster_api = ClusterApi(
        'http://{ip}'.format(ip=cluster.masters[0].public_ip),
        master_list,
        master_list,
        [h.private_ip for h in cluster.agents],
        [h.private_ip for h in cluster.public_agents],
        "root",             # default_os_user
        web_auth_default_user=DcosUser(CI_AUTH_JSON),
        ca_cert_path=None)

    cluster_api.wait_for_dcos()

    # Deploy an app
    cluster_api.marathon.deploy_app(get_test_app())

    task_info_before_upgrade = get_task_info(cluster_api.marathon.get('v2/apps').json(),
                                             cluster_api.marathon.get('v2/tasks').json())

    assert task_info_before_upgrade is not None, "Unable to get task details of the cluster."
    assert task_info_before_upgrade.state == "TASK_RUNNING", "Task is not in the running state."

    with cluster.ssher.tunnel(cluster.bootstrap_host) as bootstrap_host_tunnel:
        bootstrap_host_tunnel.remote_cmd(['sudo', 'rm', '-rf', cluster.ssher.home_dir + '/*'])

    test_util.cluster.upgrade_dcos(cluster, installer_url)

    task_info_after_upgrade = get_task_info(cluster_api.marathon.get('v2/apps').json(),
                                            cluster_api.marathon.get('v2/tasks').json())

    assert task_info_after_upgrade is not None, "Unable to get the tasks details of the cluster."
    assert task_info_after_upgrade.state == "TASK_RUNNING", "Task is not in the running state."

    assert task_info_before_upgrade.id == task_info_after_upgrade.id, \
        "Task ID before and after the upgrade did not match."

    # There has happened at least one health-check in the new cluster since the last health-check in the old cluster.
    assert (task_info_after_upgrade.last_success_time >
            task_info_before_upgrade.last_success_time + task_info_before_upgrade.health_check_interval), \
        "Invalid health-check for the task in the upgraded cluster."

    result = test_util.cluster.run_integration_tests(cluster, test_cmd=test_cmd)

    if result == 0:
        log.info("Test successsful! Deleting VPC if provided in this run...")
        vpc.delete()
    else:
        log.info("Test failed! VPC cluster will remain available for debugging for 2 hour after instantiation.")
    sys.exit(result)
Пример #6
0
def make_cluster_fixture():
    args = get_args_from_env()
    args['web_auth_default_user'] = DcosUser(CI_AUTH_JSON)
    cluster_api = ClusterApi(**args)
    cluster_api.wait_for_dcos()
    return cluster_api
Пример #7
0
def make_cluster_fixture():
    args = get_args_from_env()
    args['web_auth_default_user'] = DcosUser(CI_AUTH_JSON)
    cluster_api = ClusterApi(**args)
    cluster_api.wait_for_dcos()
    return cluster_api