Beispiel #1
0
def create_jobdefinition(dci_context, components, test_ids,
                         topic_id, jobdef_name=None):
    # If at least one component doesn't exist in the database then a new
    # jobdefinition must be created.
    at_least_one = False
    component_ids = []
    names = []
    for cmpt in components:
        names.append(cmpt['name'])
        created_cmpt = component.create(dci_context, **cmpt)
        if created_cmpt.status_code == 201:
            at_least_one = True
        elif created_cmpt.status_code == 422:
            created_cmpt = component.get(dci_context, cmpt['name'])
        created_cmpt_name = created_cmpt.json()['component']['name']
        component_ids.append(created_cmpt.json()['component']['id'])

    if at_least_one:
        if jobdef_name is None:
            jobdef_name = created_cmpt_name
        jobdef = jobdefinition.create(dci_context, jobdef_name, topic_id)
        if jobdef.status_code == 201:
            jobdef_id = jobdef.json()['jobdefinition']['id']
            for cmpt_id in component_ids:
                jobdefinition.add_component(dci_context, jobdef_id, cmpt_id)
            for test_id in test_ids:
                jobdefinition.add_test(dci_context, jobdef_id, test_id)
            print("Jobdefinition '%s' created." % jobdef_name)
        else:
            print("Error on jobdefinition creation: '%s'", jobdef.json())
    else:
        print("No jobdefinition created.")
def test_job_list(runner, dci_context, team_id, topic_id,
                  remoteci_id, component_id):
    kwargs = {'name': 'tname', 'topic_id': topic_id,
              'component_types': ['git_review']}
    jd = jobdefinition.create(dci_context, **kwargs).json()
    jobdefinition_id = jd['jobdefinition']['id']

    kwargs = {'name': 'test_jobdefinition', 'team_id': team_id}
    test_id = test.create(dci_context, **kwargs).json()['test']['id']
    jobdefinition.add_test(dci_context, jobdefinition_id, test_id)
    kwargs = {'name': 'test_remoteci', 'team_id': team_id}
    test_id = test.create(dci_context, **kwargs).json()['test']['id']
    remoteci.add_test(dci_context, remoteci_id, test_id)

    job_id = job.schedule(
        dci_context, remoteci_id, topic_id).json()['job']['id']
    result = runner.invoke(['job-list-test', job_id])
    assert len(result['tests']) == 2
    assert result['tests'][0]['name'] == 'test_jobdefinition'
    assert result['tests'][1]['name'] == 'test_remoteci'
def attach_test(context, id, test_id):
    """attach_test(context, id, test_id)

    Attach a test to a jobdefinition.

    >>> dcictl jobdefinition-attach-test [OPTIONS]

    :param string id: ID of the jobdefinition to attach the test to [required]
    :param string test_id: ID of the test to attach [required]
    """
    result = jobdefinition.add_test(context, id=id,
                                    test_id=test_id)
    utils.format_output(result, context.format,
                        None, ['jobdefinition_id', 'test_id'])