Exemple #1
0
    def create_command(self, jobstep, **kwargs):
        kwargs.setdefault('label', 'a command')
        kwargs.setdefault('script', 'echo 1')

        command = Command(jobstep=jobstep, **kwargs)
        db.session.add(command)
        db.session.commit()

        return command
Exemple #2
0
    def test_simple(self):
        project = self.create_project()
        build = self.create_build(project)
        job = self.create_job(build)
        jobphase = self.create_jobphase(job)
        jobstep = self.create_jobstep(jobphase)
        command = Command(
            label='echo 1',
            jobstep_id=jobstep.id,
            cwd='/home/foobar',
            env={'foo': 'bar'},
            script='echo 1',
            date_created=datetime(2013, 9, 19, 22, 15, 22),
            artifacts=['junit.xml'],
        )
        db.session.add(command)
        db.session.flush()

        result = serialize(command)
        assert result['id'] == command.id.hex
        assert result['dateCreated'] == '2013-09-19T22:15:22'
        assert result['cwd'] == command.cwd
        assert result['env'] == {'foo': 'bar'}
        assert result['script'] == command.script
Exemple #3
0
def job(build, change=None, **kwargs):
    kwargs.setdefault('project', build.project)
    kwargs.setdefault('label', get_sentences(1)[0][:128])
    kwargs.setdefault('status', Status.finished)
    kwargs.setdefault('result', Result.passed)
    kwargs.setdefault('duration', random.randint(10000, 100000))
    kwargs['source'] = build.source

    kwargs['source_id'] = kwargs['source'].id
    kwargs['project_id'] = kwargs['project'].id
    kwargs['build_id'] = build.id
    if change:
        kwargs['change_id'] = change.id

    job = Job(
        build=build,
        change=change,
        **kwargs
    )
    db.session.add(job)

    node, created = get_or_create(Node, where={
        'label': get_sentences(1)[0][:32],
    })

    if created:
        cluster, _ = get_or_create(Cluster, where={
            'label': get_sentences(1)[0][:32],
        })

        clusternode = ClusterNode(cluster=cluster, node=node)
        db.session.add(clusternode)

    jobplan = JobPlan.build_jobplan(plan(build.project), job)
    db.session.add(jobplan)

    phase1_setup = JobPhase(
        project=job.project, job=job,
        date_started=job.date_started,
        date_finished=job.date_finished,
        status=Status.finished, result=Result.passed, label='Setup',
    )
    db.session.add(phase1_setup)

    phase1_compile = JobPhase(
        project=job.project, job=job,
        date_started=job.date_started,
        date_finished=job.date_finished,
        status=Status.finished, result=Result.passed, label='Compile',
    )
    db.session.add(phase1_compile)

    phase1_test = JobPhase(
        project=job.project, job=job,
        date_started=job.date_started,
        date_finished=job.date_finished,
        status=kwargs['status'], result=kwargs['result'], label='Test',
    )
    db.session.add(phase1_test)

    step = JobStep(
        project=job.project, job=job,
        phase=phase1_setup, status=phase1_setup.status, result=phase1_setup.result,
        label='Setup', node=node,
    )
    db.session.add(step)
    command = Command(
        jobstep=step,
        script="echo 1",
        label="echo 1",
    )
    db.session.add(command)

    step = JobStep(
        project=job.project, job=job,
        phase=phase1_compile, status=phase1_compile.status, result=phase1_compile.result,
        label='Compile', node=node,
    )
    db.session.add(step)
    command = Command(
        jobstep=step,
        script="echo 2",
        label="echo 2",
    )
    db.session.add(command)

    step = JobStep(
        project=job.project, job=job,
        phase=phase1_test, status=phase1_test.status, result=phase1_test.result,
        label=TEST_STEP_LABELS.next(), node=node,
    )
    db.session.add(step)
    command = Command(
        jobstep=step,
        script="echo 3",
        label="echo 3",
    )
    db.session.add(command)

    step = JobStep(
        project=job.project, job=job,
        phase=phase1_test, status=phase1_test.status, result=phase1_test.result,
        label=TEST_STEP_LABELS.next(), node=node,
    )
    db.session.add(step)
    command = Command(
        jobstep=step,
        script="echo 4",
        label="echo 4",
    )
    db.session.add(command)

    if phase1_test.result == Result.failed:
        db.session.add(FailureReason(
            reason='test_failures',
            build_id=build.id,
            job_id=job.id,
            step_id=step.id,
            project_id=job.project_id
        ))

    return job