示例#1
0
END_TEST

START_TEST(pack_1702_account_rec)
{
	int rc;

	slurmdb_account_rec_t *pack_ar = xmalloc(sizeof(slurmdb_account_rec_t));
	pack_ar->description           = xstrdup("default_acct");
	pack_ar->name                  = xstrdup("default_name");
	pack_ar->organization          = xstrdup("default_organization");
	pack_ar->assoc_list            = list_create(slurmdb_destroy_assoc_rec);
	pack_ar->coordinators          = list_create(slurmdb_destroy_coord_rec);
	slurmdb_coord_rec_t * j = xmalloc(sizeof(slurmdb_coord_rec_t));
	slurmdb_assoc_rec_t * k = xmalloc(sizeof(slurmdb_assoc_rec_t));

	k->lft    = 88;
	j->name   = xstrdup("Bertrand Russell");
	j->direct = 5;

	list_append(pack_ar->coordinators, (void *)j);
	list_append(pack_ar->assoc_list,   (void *)k);

	Buf buf = init_buf(1024);
	slurmdb_pack_account_rec(pack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_account_rec_t *unpack_ar;
	rc = slurmdb_unpack_account_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                              == SLURM_SUCCESS);
	ck_assert_str_eq(pack_ar->description ,      unpack_ar->description);
	ck_assert_str_eq(pack_ar->name        ,      unpack_ar->name);
	ck_assert_str_eq(pack_ar->organization,      unpack_ar->organization);
	ck_assert(list_count(pack_ar->assoc_list) == list_count(unpack_ar->assoc_list));

	slurmdb_assoc_rec_t bar          = *(slurmdb_assoc_rec_t *)list_peek(pack_ar->assoc_list);
	slurmdb_assoc_rec_t aar          = *(slurmdb_assoc_rec_t *)list_peek(unpack_ar->assoc_list);
	slurmdb_coord_rec_t bc           = *(slurmdb_coord_rec_t *)list_peek(pack_ar->coordinators);
	slurmdb_coord_rec_t ac           = *(slurmdb_coord_rec_t *)list_peek(unpack_ar->coordinators);

	ck_assert_str_eq(bc.name,            ac.name);
	ck_assert(bc.direct              == ac.direct);
	ck_assert(bar.lft                == aar.lft);

	free_buf(buf);
	slurmdb_destroy_account_rec(pack_ar);
	slurmdb_destroy_account_rec(unpack_ar);
}
示例#2
0
END_TEST

START_TEST(pack_1702_null_account_rec)
{
	int rc;
	Buf buf = init_buf(1024);
	slurmdb_account_rec_t pack_ar = {0};

	slurmdb_pack_account_rec(NULL, SLURM_MIN_PROTOCOL_VERSION, buf);

	set_buf_offset(buf, 0);

	slurmdb_account_rec_t *unpack_ar;
	rc = slurmdb_unpack_account_rec((void **)&unpack_ar, SLURM_MIN_PROTOCOL_VERSION, buf);
	ck_assert(rc                    == SLURM_SUCCESS);
	ck_assert(pack_ar.assoc_list    == unpack_ar->assoc_list);
	ck_assert(pack_ar.coordinators  == unpack_ar->coordinators);
	ck_assert(pack_ar.description   == unpack_ar->description);
	ck_assert(pack_ar.name          == unpack_ar->name);
	ck_assert(pack_ar.organization  == unpack_ar->organization);

	free_buf(buf);
	slurmdb_destroy_account_rec(unpack_ar);
}
示例#3
0
extern int sacctmgr_modify_account(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    slurmdb_account_cond_t *acct_cond =
        xmalloc(sizeof(slurmdb_account_cond_t));
    slurmdb_account_rec_t *acct = xmalloc(sizeof(slurmdb_account_rec_t));
    slurmdb_association_rec_t *assoc =
        xmalloc(sizeof(slurmdb_association_rec_t));

    int i=0;
    int cond_set = 0, prev_set = 0, rec_set = 0, set = 0;
    List ret_list = NULL;

    slurmdb_init_association_rec(assoc, 0);

    for (i=0; i<argc; i++) {
        int command_len = strlen(argv[i]);
        if (!strncasecmp(argv[i], "Where", MAX(command_len, 5))) {
            i++;
            prev_set = _set_cond(&i, argc, argv, acct_cond, NULL);
            cond_set |= prev_set;
        } else if (!strncasecmp(argv[i], "Set", MAX(command_len, 3))) {
            i++;
            prev_set = _set_rec(&i, argc, argv, NULL, NULL,
                                acct, assoc);
            rec_set |= prev_set;
        } else {
            prev_set = _set_cond(&i, argc, argv, acct_cond, NULL);
            cond_set |= prev_set;
        }
    }

    if (exit_code) {
        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return SLURM_ERROR;
    } else if (!rec_set) {
        exit_code=1;
        fprintf(stderr, " You didn't give me anything to set\n");
        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return SLURM_ERROR;
    } else if (!cond_set) {
        if (!commit_check("You didn't set any conditions with 'WHERE'.\n"
                          "Are you sure you want to continue?")) {
            printf("Aborted\n");
            slurmdb_destroy_account_cond(acct_cond);
            slurmdb_destroy_account_rec(acct);
            slurmdb_destroy_association_rec(assoc);
            return SLURM_SUCCESS;
        }
    }

    // Special case:  reset raw usage only
    if (assoc->usage) {
        rc = SLURM_ERROR;
        if (assoc->usage->usage_raw == 0.0)
            rc = sacctmgr_remove_assoc_usage(acct_cond->assoc_cond);
        else
            error("Raw usage can only be set to 0 (zero)");

        slurmdb_destroy_account_cond(acct_cond);
        slurmdb_destroy_account_rec(acct);
        slurmdb_destroy_association_rec(assoc);
        return rc;
    }

    notice_thread_init();
    if (rec_set & 1) { // process the account changes
        if (cond_set == 2) {
            exit_code=1;
            fprintf(stderr,
                    " There was a problem with your "
                    "'where' options.\n");
            rc = SLURM_ERROR;
            goto assoc_start;
        }
        ret_list = acct_storage_g_modify_accounts(
                       db_conn, my_uid, acct_cond, acct);
        if (ret_list && list_count(ret_list)) {
            char *object = NULL;
            ListIterator itr = list_iterator_create(ret_list);
            printf(" Modified accounts...\n");
            while((object = list_next(itr))) {
                printf("  %s\n", object);
            }
            list_iterator_destroy(itr);
            set = 1;
        } else if (ret_list) {
            printf(" Nothing modified\n");
            rc = SLURM_ERROR;
        } else {
            exit_code=1;
            fprintf(stderr, " Error with request: %s\n",
                    slurm_strerror(errno));

            rc = SLURM_ERROR;
        }

        if (ret_list)
            list_destroy(ret_list);
    }

assoc_start:
    if (rec_set == 3 || rec_set == 2) { // process the association changes
        if (cond_set == 1 && !acct_cond->assoc_cond->acct_list) {
            rc = SLURM_ERROR;
            exit_code=1;
            fprintf(stderr,
                    " There was a problem with your "
                    "'where' options.\n");
            goto assoc_end;
        }

        if (assoc->parent_acct) {
            slurmdb_account_rec_t *acct_rec =
                sacctmgr_find_account(assoc->parent_acct);
            if (!acct_rec) {
                exit_code=1;
                fprintf(stderr,
                        " Parent Account %s doesn't exist.\n",
                        assoc->parent_acct);
                rc = SLURM_ERROR;
                goto assoc_end;
            }
        }

        ret_list = acct_storage_g_modify_associations(
                       db_conn, my_uid, acct_cond->assoc_cond, assoc);

        if (ret_list && list_count(ret_list)) {
            set = 1;
            if (assoc->def_qos_id != NO_VAL)
                set = sacctmgr_check_default_qos(
                          assoc->def_qos_id,
                          acct_cond->assoc_cond);
            else if (assoc->qos_list)
                set = sacctmgr_check_default_qos(
                          -1, acct_cond->assoc_cond);

            if (set) {
                char *object = NULL;
                ListIterator itr = list_iterator_create(
                                       ret_list);
                printf(" Modified account associations...\n");
                while((object = list_next(itr))) {
                    printf("  %s\n", object);
                }
                list_iterator_destroy(itr);
                set = 1;
            }
        } else if (ret_list) {
            printf(" Nothing modified\n");
            rc = SLURM_ERROR;
        } else {
            exit_code=1;
            fprintf(stderr, " Error with request: %s\n",
                    slurm_strerror(errno));

            rc = SLURM_ERROR;
        }

        if (ret_list)
            list_destroy(ret_list);
    }

assoc_end:

    notice_thread_fini();
    if (set) {
        if (commit_check("Would you like to commit changes?"))
            acct_storage_g_commit(db_conn, 1);
        else {
            printf(" Changes Discarded\n");
            acct_storage_g_commit(db_conn, 0);
        }
    }
    slurmdb_destroy_account_cond(acct_cond);
    slurmdb_destroy_account_rec(acct);
    slurmdb_destroy_association_rec(assoc);

    return rc;
}
示例#4
0
extern int sacctmgr_add_account(int argc, char *argv[])
{
    int rc = SLURM_SUCCESS;
    int i=0;
    ListIterator itr = NULL, itr_c = NULL;
    slurmdb_account_rec_t *acct = NULL;
    slurmdb_association_rec_t *assoc = NULL;
    slurmdb_association_cond_t assoc_cond;
    List name_list = list_create(slurm_destroy_char);
    List cluster_list = list_create(slurm_destroy_char);
    char *cluster = NULL;
    char *name = NULL;
    List acct_list = NULL;
    List assoc_list = NULL;
    List local_assoc_list = NULL;
    List local_account_list = NULL;
    char *acct_str = NULL;
    char *assoc_str = NULL;
    int limit_set = 0;
    slurmdb_account_rec_t *start_acct =
        xmalloc(sizeof(slurmdb_account_rec_t));
    slurmdb_association_rec_t *start_assoc =
        xmalloc(sizeof(slurmdb_association_rec_t));

    slurmdb_init_association_rec(start_assoc, 0);

    for (i=0; i<argc; i++) {
        int command_len = strlen(argv[i]);
        if (!strncasecmp(argv[i], "Where", MAX(command_len, 5))
                || !strncasecmp(argv[i], "Set", MAX(command_len, 3)))
            i++;
        limit_set += _set_rec(&i, argc, argv, name_list, cluster_list,
                              start_acct, start_assoc);
    }
    if (exit_code)
        return SLURM_ERROR;

    if (!name_list || !list_count(name_list)) {
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        exit_code=1;
        fprintf(stderr, " Need name of account to add.\n");
        return SLURM_SUCCESS;
    } else {
        slurmdb_account_cond_t account_cond;
        memset(&account_cond, 0, sizeof(slurmdb_account_cond_t));
        memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));

        assoc_cond.acct_list = name_list;
        account_cond.assoc_cond = &assoc_cond;

        local_account_list = acct_storage_g_get_accounts(
                                 db_conn, my_uid, &account_cond);
    }

    if (!local_account_list) {
        exit_code=1;
        fprintf(stderr, " Problem getting accounts from database.  "
                "Contact your admin.\n");
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        return SLURM_ERROR;
    }

    if (!start_assoc->parent_acct)
        start_assoc->parent_acct = xstrdup("root");

    if (!cluster_list || !list_count(cluster_list)) {
        slurmdb_cluster_rec_t *cluster_rec = NULL;
        List tmp_list =
            acct_storage_g_get_clusters(db_conn, my_uid, NULL);
        if (!tmp_list) {
            exit_code=1;
            fprintf(stderr,
                    " Problem getting clusters from database.  "
                    "Contact your admin.\n");
            list_destroy(name_list);
            list_destroy(cluster_list);
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }

        if (!list_count(tmp_list)) {
            exit_code=1;
            fprintf(stderr,
                    "  Can't add accounts, no cluster "
                    "defined yet.\n"
                    " Please contact your administrator.\n");
            list_destroy(name_list);
            list_destroy(cluster_list);
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }
        if (!cluster_list)
            list_create(slurm_destroy_char);
        else
            list_flush(cluster_list);

        itr_c = list_iterator_create(tmp_list);
        while((cluster_rec = list_next(itr_c))) {
            list_append(cluster_list, xstrdup(cluster_rec->name));
        }
        list_iterator_destroy(itr_c);
        list_destroy(tmp_list);
    } else {
        List temp_list = NULL;
        slurmdb_cluster_cond_t cluster_cond;

        slurmdb_init_cluster_cond(&cluster_cond, 0);
        cluster_cond.cluster_list = cluster_list;

        temp_list = acct_storage_g_get_clusters(db_conn, my_uid,
                                                &cluster_cond);

        itr_c = list_iterator_create(cluster_list);
        itr = list_iterator_create(temp_list);
        while((cluster = list_next(itr_c))) {
            slurmdb_cluster_rec_t *cluster_rec = NULL;

            list_iterator_reset(itr);
            while((cluster_rec = list_next(itr))) {
                if (!strcasecmp(cluster_rec->name, cluster))
                    break;
            }
            if (!cluster_rec) {
                exit_code=1;
                fprintf(stderr, " This cluster '%s' "
                        "doesn't exist.\n"
                        "        Contact your admin "
                        "to add it to accounting.\n",
                        cluster);
                list_delete_item(itr_c);
            }
        }
        list_iterator_destroy(itr);
        list_iterator_destroy(itr_c);
        list_destroy(temp_list);

        if (!list_count(cluster_list)) {
            slurmdb_destroy_association_rec(start_assoc);
            slurmdb_destroy_account_rec(start_acct);
            list_destroy(local_account_list);
            return SLURM_ERROR;
        }
    }


    acct_list = list_create(slurmdb_destroy_account_rec);
    assoc_list = list_create(slurmdb_destroy_association_rec);

    memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));

    assoc_cond.acct_list = list_create(NULL);
    itr = list_iterator_create(name_list);
    while((name = list_next(itr)))
        list_append(assoc_cond.acct_list, name);
    list_iterator_destroy(itr);
    list_append(assoc_cond.acct_list, start_assoc->parent_acct);

    assoc_cond.cluster_list = cluster_list;
    local_assoc_list = acct_storage_g_get_associations(
                           db_conn, my_uid, &assoc_cond);
    list_destroy(assoc_cond.acct_list);
    if (!local_assoc_list) {
        exit_code=1;
        fprintf(stderr, " Problem getting associations from database.  "
                "Contact your admin.\n");
        list_destroy(name_list);
        list_destroy(cluster_list);
        slurmdb_destroy_association_rec(start_assoc);
        slurmdb_destroy_account_rec(start_acct);
        list_destroy(local_account_list);
        return SLURM_ERROR;
    }

    itr = list_iterator_create(name_list);
    while((name = list_next(itr))) {
        if (!name[0]) {
            exit_code=1;
            fprintf(stderr, " No blank names are "
                    "allowed when adding.\n");
            rc = SLURM_ERROR;
            continue;
        }

        acct = NULL;
        if (!sacctmgr_find_account_from_list(local_account_list, name)) {
            acct = xmalloc(sizeof(slurmdb_account_rec_t));
            acct->assoc_list =
                list_create(slurmdb_destroy_association_rec);
            acct->name = xstrdup(name);
            if (start_acct->description)
                acct->description =
                    xstrdup(start_acct->description);
            else
                acct->description = xstrdup(name);

            if (start_acct->organization)
                acct->organization =
                    xstrdup(start_acct->organization);
            else if (strcmp(start_assoc->parent_acct, "root"))
                acct->organization =
                    xstrdup(start_assoc->parent_acct);
            else
                acct->organization = xstrdup(name);

            xstrfmtcat(acct_str, "  %s\n", name);
            list_append(acct_list, acct);
        }

        itr_c = list_iterator_create(cluster_list);
        while((cluster = list_next(itr_c))) {
            if (sacctmgr_find_account_base_assoc_from_list(
                        local_assoc_list, name, cluster)) {
                //printf(" already have this assoc\n");
                continue;
            }
            if (!sacctmgr_find_account_base_assoc_from_list(
                        local_assoc_list, start_assoc->parent_acct,
                        cluster)) {
                exit_code=1;
                fprintf(stderr, " Parent account '%s' "
                        "doesn't exist on "
                        "cluster %s\n"
                        "        Contact your admin "
                        "to add this account.\n",
                        start_assoc->parent_acct, cluster);
                continue;
            }

            assoc = xmalloc(sizeof(slurmdb_association_rec_t));
            slurmdb_init_association_rec(assoc, 0);
            assoc->acct = xstrdup(name);
            assoc->cluster = xstrdup(cluster);
            assoc->def_qos_id = start_assoc->def_qos_id;
            assoc->parent_acct = xstrdup(start_assoc->parent_acct);
            assoc->shares_raw = start_assoc->shares_raw;

            assoc->grp_cpu_mins = start_assoc->grp_cpu_mins;
            assoc->grp_cpu_run_mins = start_assoc->grp_cpu_run_mins;
            assoc->grp_cpus = start_assoc->grp_cpus;
            assoc->grp_jobs = start_assoc->grp_jobs;
            assoc->grp_mem = start_assoc->grp_mem;
            assoc->grp_nodes = start_assoc->grp_nodes;
            assoc->grp_submit_jobs = start_assoc->grp_submit_jobs;
            assoc->grp_wall = start_assoc->grp_wall;

            assoc->max_cpu_mins_pj = start_assoc->max_cpu_mins_pj;
            assoc->max_cpus_pj = start_assoc->max_cpus_pj;
            assoc->max_jobs = start_assoc->max_jobs;
            assoc->max_nodes_pj = start_assoc->max_nodes_pj;
            assoc->max_submit_jobs = start_assoc->max_submit_jobs;
            assoc->max_wall_pj = start_assoc->max_wall_pj;

            assoc->qos_list = copy_char_list(start_assoc->qos_list);

            if (acct)
                list_append(acct->assoc_list, assoc);
            else
                list_append(assoc_list, assoc);
            xstrfmtcat(assoc_str,
                       "  A = %-10.10s"
                       " C = %-10.10s\n",
                       assoc->acct,
                       assoc->cluster);

        }
        list_iterator_destroy(itr_c);
    }
    list_iterator_destroy(itr);
    list_destroy(local_account_list);
    list_destroy(local_assoc_list);


    if (!list_count(acct_list) && !list_count(assoc_list)) {
        printf(" Nothing new added.\n");
        rc = SLURM_ERROR;
        goto end_it;
    } else if (!assoc_str) {
        exit_code=1;
        fprintf(stderr, " No associations created.\n");
        goto end_it;
    }

    if (acct_str) {
        printf(" Adding Account(s)\n%s", acct_str);
        printf(" Settings\n");
        if (start_acct->description)
            printf("  Description     = %s\n",
                   start_acct->description);
        else
            printf("  Description     = %s\n", "Account Name");

        if (start_acct->organization)
            printf("  Organization    = %s\n",
                   start_acct->organization);
        else
            printf("  Organization    = %s\n",
                   "Parent/Account Name");

        xfree(acct_str);
    }

    if (assoc_str) {
        printf(" Associations\n%s", assoc_str);
        xfree(assoc_str);
    }

    if (limit_set) {
        printf(" Settings\n");
        sacctmgr_print_assoc_limits(start_assoc);
    }

    notice_thread_init();
    if (list_count(acct_list))
        rc = acct_storage_g_add_accounts(db_conn, my_uid, acct_list);


    if (rc == SLURM_SUCCESS) {
        if (list_count(assoc_list))
            rc = acct_storage_g_add_associations(db_conn, my_uid,
                                                 assoc_list);
    } else {
        exit_code=1;
        fprintf(stderr, " Problem adding accounts: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
        notice_thread_fini();
        goto end_it;
    }
    notice_thread_fini();

    if (rc == SLURM_SUCCESS) {
        if (commit_check("Would you like to commit changes?")) {
            acct_storage_g_commit(db_conn, 1);
        } else {
            printf(" Changes Discarded\n");
            acct_storage_g_commit(db_conn, 0);
        }
    } else {
        exit_code=1;
        fprintf(stderr,
                " error: Problem adding account associations: %s\n",
                slurm_strerror(rc));
        rc = SLURM_ERROR;
    }

end_it:
    list_destroy(name_list);
    list_destroy(cluster_list);
    list_destroy(acct_list);
    list_destroy(assoc_list);

    slurmdb_destroy_association_rec(start_assoc);
    slurmdb_destroy_account_rec(start_acct);
    return rc;
}