Ejemplo n.º 1
0
def canary_job(request):
    """
    returns a unique job for the test, dumps job stats on test failure
    and restores job's original state after test run
    """
    job = get_unique_job(request)
    job_name = job.get_spec().name
    yield job

    FILE_LOCK.acquire()
    try:
        # Test failed, dump job stats
        if request.node.rep_call.failed:
            log.info("failed test: %s", request.node.name)
            dump_job_stats(job)

        pytest.job_in_use = read_from_file(JOB_IN_USE_FILE)
        del pytest.job_in_use[job_name]
        write_to_file(JOB_IN_USE_FILE, pytest.job_in_use)

        log.info('restore job: %s, job_id: %s, after test: %s', job_name,
                 job.job_id, request.node.name)
        patch_job(job, read_job_spec(job_name + '.yaml'))
    finally:
        FILE_LOCK.release()
Ejemplo n.º 2
0
def test__remove_instances(canary_job):
    spec = canary_job.get_spec()
    old_instance_count = spec.instance_count
    new_instance_count = spec.instance_count - 1
    spec.instance_count = new_instance_count

    log.info("job_name: %s, job_id: %s, reduce instances from %s to %s",
             spec.name, canary_job.get_job_id(), old_instance_count,
             new_instance_count)
    patch_job(canary_job, spec)
    assert new_instance_count == len(canary_job.get_pods())
Ejemplo n.º 3
0
def test__update_resource_spec(canary_job):
    spec = canary_job.get_spec()
    spec.default_spec.containers[0].resource.cpu_limit = 0.7
    spec.default_spec.containers[0].resource.mem_limit_mb = 15
    spec.default_spec.containers[0].resource.disk_limit_mb = 25

    log.info("job_name: %s, job_id: %s, updated_resources: %s", spec.name,
             canary_job.get_job_id(), spec.default_spec.containers[0].resource)
    patch_job(canary_job, spec)
    new_spec = canary_job.get_spec()
    assert new_spec.default_spec.containers[0].resource.cpu_limit == 0.7
    assert new_spec.default_spec.containers[0].resource.mem_limit_mb == 15
    assert new_spec.default_spec.containers[0].resource.disk_limit_mb == 25