Exemplo n.º 1
0
def test_create_jobdefinition_and_add_component(runner, dci_context,
                                                components, test_id, topic_id):
    create_jobdefinition_and_add_component(dci_context, components, test_id,
                                           topic_id, jobdef_name='Test suite')

    team_id = team.list(dci_context).json()['teams'][0]['id']
    topic.attach_team(dci_context, topic_id, team_id)
    jdefs = jobdefinition.list(dci_context, topic_id).json()['jobdefinitions']
    jdef_names = [jdef['name'] for jdef in jdefs]

    jd_id = [jdef['id'] for jdef in jdefs if jdef['name'] == 'Test suite'][0]

    assert 'Test suite' in jdef_names

    jdef_cmpt = jobdefinition.get_components(dci_context, jd_id).json()
    jdef_cmpt = jdef_cmpt['components']

    assert 'component1' == jdef_cmpt[0]['name']
    assert 'component2' == jdef_cmpt[1]['name']
Exemplo n.º 2
0
def list(context, args):
    params = {
        k: getattr(args, k)
        for k in ["sort", "limit", "offset", "where"]
    }
    return team.list(context, **params)
Exemplo n.º 3
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            state=dict(default='present',
                       choices=['present', 'absent'],
                       type='str'),
            # Authentication related parameters
            #
            dci_login=dict(required=False, type='str'),
            dci_password=dict(required=False, type='str'),
            dci_cs_url=dict(required=False, type='str'),
            # Resource related parameters
            #
            id=dict(type='str'),
            name=dict(type='str'),
            country=dict(type='str'),
            email=dict(type='str'),
            notification=dict(type='bool'),
        ), )

    if not dciclient_found:
        module.fail_json(msg='The python dciclient module is required')

    login, password, url = get_details(module)
    if not login or not password:
        module.fail_json(msg='login and/or password have not been specified')

    ctx = dci_context.build_dci_context(url, login, password, 'Ansible')

    # Action required: List all teams
    # Endpoint called: /teams GET via dci_team.list()
    #
    # List all teams
    if module_params_empty(module.params):
        res = dci_team.list(ctx)

    # Action required: Delete the team matching team id
    # Endpoint called: /teams/<team_id> DELETE via dci_team.delete()
    #
    # If the team exists and it has been succesfully deleted the changed is
    # set to true, else if the team does not exist changed is set to False
    elif module.params['state'] == 'absent':
        if not module.params['id']:
            module.fail_json(msg='id parameter is required')
        res = dci_team.get(ctx, module.params['id'])
        if res.status_code not in [400, 401, 404, 409]:
            kwargs = {
                'id': module.params['id'],
                'etag': res.json()['team']['etag']
            }
            res = dci_team.delete(ctx, **kwargs)

    # Action required: Retrieve team informations
    # Endpoint called: /teams/<team_id> GET via dci_team.get()
    #
    # Get team informations
    elif module.params['id'] and not module.params[
            'name'] and not module.params['country'] and not module.params[
                'email'] and module.params['notification'] is None:
        res = dci_team.get(ctx, module.params['id'])

    # Action required: Update an existing team
    # Endpoint called: /teams/<team_id> PUT via dci_team.update()
    #
    # Update the team with the specified characteristics.
    elif module.params['id']:
        res = dci_team.get(ctx, module.params['id'])
        if res.status_code not in [400, 401, 404, 409]:
            kwargs = {
                'id': module.params['id'],
                'etag': res.json()['team']['etag']
            }
            if module.params['name']:
                kwargs['name'] = module.params['name']
            if module.params['country']:
                kwargs['country'] = module.params['country']
            if module.params['email']:
                kwargs['email'] = module.params['email']
            if module.params['notification'] is not None:
                kwargs['notification'] = module.params['notification']
            res = dci_team.update(ctx, **kwargs)

    # Action required: Creat a team with the specified content
    # Endpoint called: /teams POST via dci_team.create()
    #
    # Create the new team.
    else:
        if not module.params['name']:
            module.fail_json(msg='name parameter must be specified')

        kwargs = {'name': module.params['name']}
        if module.params['country']:
            kwargs['country'] = module.params['country']
        if module.params['email']:
            kwargs['email'] = module.params['email']
        if module.params['notification'] is not None:
            kwargs['notification'] = module.params['notification']

        res = dci_team.create(ctx, **kwargs)

    try:
        result = res.json()
        if res.status_code == 404:
            module.fail_json(msg='The resource does not exist')
        if res.status_code == 409:
            result['changed'] = False
        else:
            result['changed'] = True
    except:
        result = {}
        result['changed'] = True

    module.exit_json(**result)
Exemplo n.º 4
0
def team_user_id(dci_context):
    user = api_team.list(dci_context, where="name:user")
    return user.json()["teams"][0]["id"]
Exemplo n.º 5
0
def team_admin_id(dci_context):
    return api_team.list(dci_context,
                         where="name:admin").json()["teams"][0]["id"]
Exemplo n.º 6
0
                         sort='-created_at',
                         embed='components,jobdefinition',
                         limit=128)
]

# get all topics to get the association topic_id -> topic_name
# which will be used below
print("[*] Get all topics")
ltopics = topic.list(gcontext).json()['topics']
topicids_to_name = {}
for current_topic in ltopics:
    topicids_to_name[current_topic['id']] = current_topic['name']

# get all teams to get association team_id -> team_name
print("[*] Get all teams")
lteams = team.list(gcontext).json()['teams']
teams_to_name = {}
for current_team in lteams:
    teams_to_name[current_team['id']] = current_team['name']

# get all remotecis to get the association remoteci_id -> remoteci_name
# which will be used below
print("[*] Get all remotecis")
lremotecis = remoteci.list(gcontext).json()['remotecis']
remotecis_to_name = {}
for current_remoteci in lremotecis:
    remoteci_team_id = current_remoteci['team_id']
    remoteci_team_name = teams_to_name[remoteci_team_id]
    remotecis_to_name[current_remoteci['id']] = (current_remoteci['name'],
                                                 remoteci_team_name)
Exemplo n.º 7
0
def list(context):
    result = team.list(context)
    utils.format_output(result.json(), context.format,
                        team.RESOURCE, team.TABLE_HEADERS)