示例#1
0
def _create_service_accounts_stage(
    masters, min_index, max_index, batch_size, security_mode
) -> Set[str]:
    failure_set = set()
    current = 0
    end = max_index - min_index
    for current in range(0, end, batch_size):

        log.info(
            "Re-authenticating current batch load of jenkins{} - jenkins{} "
            "to prevent auth-timeouts on scale cluster.".format(
                current, current + batch_size
            )
        )
        dcos_login.login_session()

        batched_masters = masters[current : current + batch_size]
        service_account_threads = _spawn_threads(
            batched_masters,
            _create_service_accounts,
            security=security_mode,
            event="serviceaccounts",
        )
        thread_failures = _wait_and_get_failures(
            service_account_threads, timeout=SERVICE_ACCOUNT_TIMEOUT
        )
        current = current + batch_size
        failure_set |= thread_failures
    return failure_set
def _create_jobs_stage(
    masters,
    min_index,
    max_index,
    batch_size,
    security_mode,
    marathon_client,
    external_volume,
    mom,
    job_count,
    single_use,
    run_delay,
    work_duration,
    scenario,
    mesos_agent_label,
) -> Set[str]:
    failure_set = set()
    current = 0
    end = max_index - min_index
    for current in range(0, end, batch_size):

        log.info(
            "Re-authenticating current batch load of jenkins{} - jenkins{} "
            "to prevent auth-timeouts on scale cluster.".format(
                current, current + batch_size))
        dcos_login.login_session()

        batched_masters = masters[current:current + batch_size]

        # the rest of the commands require a running Jenkins instance
        job_threads = _spawn_threads(
            batched_masters,
            _create_jobs,
            jobs=job_count,
            single=single_use,
            delay=run_delay,
            duration=work_duration,
            scenario=scenario,
            event="createjobs",
            label=mesos_agent_label,
        )
        thread_failures = _wait_and_get_failures(job_threads,
                                                 timeout=JOB_RUN_TIMEOUT)
        failure_set |= thread_failures
        current = current + batch_size
    return failure_set
def _install_jenkins_stage(
    masters,
    min_index,
    max_index,
    batch_size,
    security_mode,
    marathon_client,
    external_volume,
    mom,
    containerizer,
    service_user,
    agent_user,
) -> Set[str]:
    failure_set = set()
    current = 0
    end = max_index - min_index
    for current in range(0, end, batch_size):

        log.info(
            "Re-authenticating current batch load of jenkins{} - jenkins{} "
            "to prevent auth-timeouts on scale cluster.".format(
                current, current + batch_size))
        dcos_login.login_session()

        batched_masters = masters[current:current + batch_size]
        install_threads = _spawn_threads(
            batched_masters,
            _install_jenkins,
            event="deployments",
            client=marathon_client,
            external_volume=external_volume,
            security=security_mode,
            daemon=True,
            mom=mom,
            containerizer=containerizer,
            service_user=service_user,
            agent_user=agent_user,
        )
        thread_failures = _wait_and_get_failures(install_threads,
                                                 timeout=DEPLOY_TIMEOUT)
        current = current + batch_size
        failure_set |= thread_failures
    return failure_set
示例#4
0
def test_scaling_load(master_count, job_count, single_use: bool, run_delay,
                      cpu_quota, work_duration, mom, external_volume: bool,
                      scenario, min_index, max_index, batch_size) -> None:
    """Launch a load test scenario. This does not verify the results
    of the test, but does ensure the instances and jobs were created.

    The installation is run in threads, but the job creation and
    launch is then done serially after all Jenkins instances have
    completed installation.

    Args:
        master_count: Number of Jenkins masters or instances
        job_count: Number of Jobs on each Jenkins master
        single_use: Mesos Single-Use Agent on (true) or off (false)
        run_delay: Jobs should run every X minute(s)
        cpu_quota: CPU quota (0.0 to disable)
        work_duration: Time, in seconds, for generated jobs to sleep
        mom: Marathon on Marathon instance name
        external_volume: External volume on rexray (true) or local volume (false)
        min_index: minimum index to begin jenkins suffixes at
        max_index: maximum index to end jenkins suffixes at
        batch_size: batch size to deploy jenkins instances in
    """
    security_mode = sdk_dcos.get_security_mode()
    if mom and cpu_quota != 0.0:
        with shakedown.marathon_on_marathon(mom):
            _setup_quota(SHARED_ROLE, cpu_quota)

    # create marathon client
    if mom:
        with shakedown.marathon_on_marathon(mom):
            marathon_client = shakedown.marathon.create_client()
    else:
        marathon_client = shakedown.marathon.create_client()

    masters = []
    if min_index == -1 or max_index == -1:
        masters = [
            "jenkins{}".format(sdk_utils.random_string())
            for _ in range(0, int(master_count))
        ]
    else:
        #max and min indexes are specified
        #NOTE: using min/max will override master count
        masters = [
            "jenkins{}".format(index) for index in range(min_index, max_index)
        ]
    # create service accounts in parallel
    sdk_security.install_enterprise_cli()
    service_account_threads = _spawn_threads(masters,
                                             _create_service_accounts,
                                             security=security_mode)

    thread_failures = _wait_and_get_failures(service_account_threads,
                                             timeout=SERVICE_ACCOUNT_TIMEOUT)
    # launch Jenkins services
    current = 0
    end = max_index - min_index
    while current + batch_size <= end:

        log.info(
            "Re-authenticating current batch load of jenkins{} - jenkins{} "
            "to prevent auth-timeouts on scale cluster.".format(
                current, current + batch_size))
        dcos_login.login_session()

        batched_masters = masters[current:current + batch_size]
        install_threads = _spawn_threads(batched_masters,
                                         _install_jenkins,
                                         event='deployments',
                                         client=marathon_client,
                                         external_volume=external_volume,
                                         security=security_mode,
                                         daemon=True,
                                         mom=mom)
        thread_failures = _wait_and_get_failures(install_threads,
                                                 timeout=DEPLOY_TIMEOUT)
        thread_names = [x.name for x in thread_failures]

        # the rest of the commands require a running Jenkins instance
        deployed_masters = [
            x for x in batched_masters if x not in thread_names
        ]
        job_threads = _spawn_threads(deployed_masters,
                                     _create_jobs,
                                     jobs=job_count,
                                     single=single_use,
                                     delay=run_delay,
                                     duration=work_duration,
                                     scenario=scenario)
        _wait_on_threads(job_threads, JOB_RUN_TIMEOUT)
        r = json.dumps(TIMINGS)
        print(r)
        current = current + batch_size