Esempio n. 1
0
def _launch_jobs(
    service_name: str,
    jobs: int = 1,
    single: bool = False,
    delay: int = 3,
    duration: int = 600,
    label: str = None,
    scenario: str = None,
):
    """Create configured number of jobs with given config on Jenkins
    instance identified by `service_name`.

    Args:
        service_name: Jenkins service name
        jobs: Number of jobs to create and run
        single: Single Use Mesos agent on (true) or off
        delay: A job should run every X minute(s)
        duration: Time, in seconds, for the job to sleep
        label: Mesos label for jobs to use
    """
    job_name = "generator-job"
    single_use_str = "100" if single else "0"

    seed_config_xml = jenkins._get_job_fixture("gen-job.xml")
    seed_config_str = ElementTree.tostring(
        seed_config_xml.getroot(), encoding="utf8", method="xml"
    )
    jenkins.create_seed_job(service_name, job_name, seed_config_str)
    log.info(
        "Launching {} jobs every {} minutes with single-use "
        "({}).".format(jobs, delay, single)
    )

    jenkins.run_job(
        service_name,
        job_name,
        timeout_seconds=600,
        **{
            "JOBCOUNT": str(jobs),
            "AGENT_LABEL": label,
            "SINGLE_USE": single_use_str,
            "EVERY_XMIN": str(delay),
            "SLEEP_DURATION": str(duration),
            "SCENARIO": scenario,
        }
    )
Esempio n. 2
0
def _launch_jobs(service_name: str,
                 jobs: int = 1,
                 single: bool = False,
                 delay: int = 3,
                 duration: int = 600,
                 label: str = None,
                 scenario: str = None):
    """Create configured number of jobs with given config on Jenkins
    instance identified by `service_name`.

    Args:
        service_name: Jenkins service name
        jobs: Number of jobs to create and run
        single: Single Use Mesos agent on (true) or off
        delay: A job should run every X minute(s)
        duration: Time, in seconds, for the job to sleep
        label: Mesos label for jobs to use
    """
    job_name = 'generator-job'
    single_use_str = '100' if single else '0'

    seed_config_xml = jenkins._get_job_fixture('gen-job.xml')
    seed_config_str = ElementTree.tostring(seed_config_xml.getroot(),
                                           encoding='utf8',
                                           method='xml')
    jenkins.create_seed_job(service_name, job_name, seed_config_str)
    log.info("Launching {} jobs every {} minutes with single-use "
             "({}).".format(jobs, delay, single))

    jenkins.run_job(
        service_name, job_name, **{
            'JOBCOUNT': str(jobs),
            'AGENT_LABEL': label,
            'SINGLE_USE': single_use_str,
            'EVERY_XMIN': str(delay),
            'SLEEP_DURATION': str(duration),
            'SCENARIO': scenario
        })