コード例 #1
0
ファイル: common_test.c プロジェクト: yunyuaner/sysrepo
static int
logging_setup(void **state)
{
    sr_logger_init("common_test");
    sr_log_stderr(SR_LL_DBG);

    return 0;
}
コード例 #2
0
ファイル: rp_dt_xpath_test.c プロジェクト: fanchanghu/sysrepo
int main(){
    sr_log_stderr(SR_LL_ERR);

    const struct CMUnitTest tests[] = {
            cmocka_unit_test_setup_teardown(rp_dt_validate_ok, setup, teardown),
            cmocka_unit_test_setup_teardown(rp_dt_validate_fail, setup, teardown),
            cmocka_unit_test_setup_teardown(check_error_reporting, setup, teardown),
    };
    return cmocka_run_group_tests(tests, NULL, NULL);
}
コード例 #3
0
ファイル: cm_sm_test.c プロジェクト: eqvinox/sysrepo
static int
setup(void **state) {
    sm_ctx_t *ctx = NULL;

    sr_logger_init("sm_test");
    sr_log_stderr(SR_LL_DBG);

    sm_init(NULL, NULL, &ctx);
    *state = ctx;

    return 0;
}
コード例 #4
0
int main(int argc, char **argv) {

   int rc = SR_ERR_OK;
   sr_conn_ctx_t *conn = NULL;
   sr_session_ctx_t *sess = NULL;
   sr_val_t val =  {0};

   sr_log_stderr(SR_LL_DBG);

   rc = sr_connect("push kea config", SR_CONN_DEFAULT, &conn);
   CHECK_RC(rc, cleanup);

   rc = sr_session_start(conn, SR_DS_STARTUP, SR_SESS_DEFAULT, &sess);
   CHECK_RC(rc, cleanup);

   /* socket type */
   val.xpath = "/ietf-kea-dhcpv6:server/serv-attributes/control-socket/socket-type";
   val.type = SR_STRING_T;
   val.data.string_val = "unix";

   rc = sr_set_item(sess, val.xpath, &val, SR_EDIT_DEFAULT);
   CHECK_RC(rc, cleanup);

   /* socket name */
   val.xpath = "/ietf-kea-dhcpv6:server/serv-attributes/control-socket/socket-name";
   val.type = SR_STRING_T;
   val.data.string_val = "/tmp/kea-dhcp6-ctrl.sock";

   rc = sr_set_item(sess, val.xpath, &val, SR_EDIT_DEFAULT);
   CHECK_RC(rc, cleanup);

   rc = sr_commit(sess);


   /* retrieve field */
   sr_val_t* val2 = 0;

   rc = sr_get_item(sess, val.xpath, &val2);
   printf("Retrieved: [%s]\n", val.data.string_val);

   sr_free_val(val2);

   CHECK_RC(rc, cleanup);

cleanup:
   sr_session_stop(sess);
   sr_disconnect(conn);
}
コード例 #5
0
ファイル: rp_test.c プロジェクト: yunyuaner/sysrepo
static int
rp_setup(void **state)
{
    rp_ctx_t *rp_ctx = NULL;
    int rc = 0;

    sr_logger_init("rp_test");
    sr_log_stderr(SR_LL_DBG);

    rc = rp_init(NULL, &rp_ctx);
    assert_int_equal(rc, SR_ERR_OK);
    assert_non_null(rp_ctx);

    *state = rp_ctx;
    return 0;
}
コード例 #6
0
ファイル: np_test.c プロジェクト: fanchanghu/sysrepo
static int
test_setup(void **state)
{
    test_ctx_t *test_ctx = NULL;

    sr_logger_init("np_test");
    sr_log_stderr(SR_LL_DBG);

    test_ctx = calloc(1, sizeof(*test_ctx));
    assert_non_null(test_ctx);

    test_rp_ctx_create(&test_ctx->rp_ctx);
    test_rp_sesssion_create(test_ctx->rp_ctx, SR_DS_RUNNING, &test_ctx->rp_session_ctx);

    *state = test_ctx;
    return 0;
}
コード例 #7
0
ファイル: cl_fd_watcher_test.c プロジェクト: sartura/sysrepo
static int
sysrepo_setup(void **state)
{
    createDataTreeExampleModule();
    createDataTreeTestModule();
    sr_conn_ctx_t *conn = NULL;
    int rc = SR_ERR_OK;

    sr_log_stderr(SR_LL_DBG);

    /* connect to sysrepo */
    rc = sr_connect("fd_watcher_test", SR_CONN_DEFAULT, &conn);
    assert_int_equal(rc, SR_ERR_OK);

    *state = (void*)conn;
    return 0;
}
コード例 #8
0
ファイル: perf_test.c プロジェクト: eqvinox/sysrepo
static int
sysrepo_setup(void **state)
{
    createDataTreeExampleModule();
    sr_conn_ctx_t *conn = NULL;
    int rc = SR_ERR_OK;

    /* turn off all logging */
    sr_log_stderr(SR_LL_NONE);
    sr_log_syslog(SR_LL_NONE);

    /* connect to sysrepo */
    rc = sr_connect("perf_test", SR_CONN_DEFAULT, &conn);
    assert_int_equal(rc, SR_ERR_OK);

    *state = (void*)conn;
    return 0;
}
コード例 #9
0
ファイル: cm_test.c プロジェクト: qmm161/sysrepo
static int
cm_setup(void **state)
{
    createDataTreeExampleModule();
    cm_ctx_t *ctx = NULL;
    int rc = 0;

    sr_logger_init("cm_test");
    sr_log_stderr(SR_LL_ERR); /* log only errors to stderr */

    rc = cm_init(CM_MODE_LOCAL, CM_AF_SOCKET_PATH, &ctx);
    assert_int_equal(rc, SR_ERR_OK);
    assert_non_null(ctx);
    *state = ctx;

    rc = cm_start(ctx);
    assert_int_equal(rc, SR_ERR_OK);

    return 0;
}
コード例 #10
0
int main(int argc, char **argv){
   sigset_t mask, oldmask;
   /* Set up the mask of signals to temporarily block. */
   sigemptyset (&mask);
   sigaddset (&mask, SIGUSR1);
   sigprocmask (SIG_BLOCK, &mask, &oldmask);
   printf("Pid: %d\n", getpid());
   signal(SIGUSR1, sig_handler);

    
   sr_conn_ctx_t *connection = NULL;
   sr_session_ctx_t *session = NULL;
   sr_subscription_ctx_t *subscription = NULL;
   int rc = SR_ERR_OK;

   sr_log_stderr(SR_LL_DBG);

   /* connect to sysrepo */
   rc = sr_connect("example_application", SR_CONN_DEFAULT, &connection);
   if (SR_ERR_OK != rc) {
       goto cleanup;
   }

   /* start session */
   rc = sr_session_start(connection, SR_DS_STARTUP, SR_SESS_DEFAULT, &session);
   if (SR_ERR_OK != rc) {
       goto cleanup;
   }

   /* read startup config */
   printf("\n\n ========== READING STARTUP CONFIG: ==========\n\n");

   /* subscribe for changes in running config */
   rc = sr_module_change_subscribe(session, "ietf-interfaces", module_change_cb, NULL,
           0, SR_SUBSCR_DEFAULT, &subscription);
   if (SR_ERR_OK != rc) {
       goto cleanup;
   }

   printf("\n\n ========== STARTUP CONFIG APPLIED AS RUNNING ==========\n\n");

   /* Wait for a signal to arrive. */
   while (!usr_interrupt) {
      sigsuspend (&oldmask);
   }  

   sigprocmask (SIG_UNBLOCK, &mask, NULL);
   printf("Signal received\n");

cleanup:
    if (NULL != subscription) {
        sr_unsubscribe(session, subscription);
    }
    if (NULL != session) {
        sr_session_stop(session);
    }
    if (NULL != connection) {
        sr_disconnect(connection);
    }
    return rc;
   
}
コード例 #11
0
ファイル: sysrepocfg.c プロジェクト: eqvinox/sysrepo
/**
 * @brief Main routine of the sysrepo configuration tool.
 */
int
main(int argc, char* argv[])
{
    int c = 0;
    srcfg_operation_t operation = SRCFG_OP_EDIT;
    char *module_name = NULL, *datastore_name = "running";
    char *format_name = "xml", *editor = NULL;
    char *filepath = NULL;
    srcfg_datastore_t datastore = SRCFG_STORE_RUNNING;
    LYD_FORMAT format = LYD_XML;
    bool enabled = false, keep = false, permanent = false;
    int log_level = -1;
    char local_schema_search_dir[PATH_MAX] = { 0, };
    int rc = SR_ERR_OK;

    struct option longopts[] = {
       { "help",      no_argument,       NULL, 'h' },
       { "version",   no_argument,       NULL, 'v' },
       { "datastore", required_argument, NULL, 'd' },
       { "format",    required_argument, NULL, 'f' },
       { "editor",    required_argument, NULL, 'e' },
       { "import",    optional_argument, NULL, 'i' },
       { "export",    optional_argument, NULL, 'x' },
       { "keep",      no_argument,       NULL, 'k' },
       { "permanent", no_argument,       NULL, 'p' },
       { "level",     required_argument, NULL, 'l' },
       { 0, 0, 0, 0 }
    };

    /* read mandatory <module_name> argument */
    if (1 < argc && '-' != argv[argc-1][0]) {
        module_name = argv[argc-1];
        --argc;
    }

    /* parse options */
    while ((c = getopt_long(argc, argv, ":hvd:f:e:i:x:kpl:0:", longopts, NULL)) != -1) {
        switch (c) {
            case 'h':
                srcfg_print_help();
                goto terminate;
                break;
            case 'v':
                srcfg_print_version();
                goto terminate;
                break;
            case 'd':
                if (NULL != optarg) {
                    datastore_name = optarg;
                }
                break;
            case 'f':
                if (NULL != optarg) {
                    format_name = optarg;
                }
                break;
            case 'e':
                editor = optarg;
                break;
            case 'i':
                operation = SRCFG_OP_IMPORT;
                if (NULL != optarg && 0 != strcmp("-", optarg)) {
                    filepath = optarg;
                }
                break;
            case 'x':
                operation = SRCFG_OP_EXPORT;
                if (NULL != optarg && 0 != strcmp("-", optarg)) {
                    filepath = optarg;
                }
                break;
            case 'k':
                keep = true;
                break;
            case 'p':
                permanent = true;
                break;
            case 'l':
                log_level = atoi(optarg);
                break;
            case '0':
                /* 'hidden' option - custom repository location */
                if (NULL != optarg) {
                    strncpy(local_schema_search_dir, optarg, PATH_MAX - 6);
                    strcat(local_schema_search_dir, "/yang/");
                    srcfg_schema_search_dir = local_schema_search_dir;
                    srcfg_custom_repository = true;
                }
                break;
            case ':':
                /* missing option argument */
                switch (optopt) {
                    case 'i':
                        operation = SRCFG_OP_IMPORT;
                        break;
                    case 'x':
                        operation = SRCFG_OP_EXPORT;
                        break;
                    default:
                        fprintf(stderr, "%s: option `-%c' requires an argument\n", argv[0], optopt);
                        rc = SR_ERR_INVAL_ARG;
                        goto terminate;
                }
                break;
            case '?':
            default:
                /* invalid option */
                fprintf(stderr, "%s: option `-%c' is invalid. Exiting.\n", argv[0], optopt);
                rc = SR_ERR_INVAL_ARG;
                goto terminate;
        }
    }

    /* check argument values */
    /*  -> module */
    if (NULL == module_name) {
        fprintf(stderr, "%s: Module name is not specified.\n", argv[0]);
        rc = SR_ERR_INVAL_ARG;
        goto terminate;
    }
    /*  -> format */
    if (strcasecmp("xml", format_name) == 0) {
        format = LYD_XML;
    } else if (strcasecmp("json", format_name) == 0) {
        format = LYD_JSON;
    } else {
        fprintf(stderr, "%s: Unsupported data format (xml and json are supported).\n", argv[0]);
        rc = SR_ERR_INVAL_ARG;
        goto terminate;
    }
    /*  -> datastore */
    if (strcasecmp("startup", datastore_name) == 0) {
        datastore = SRCFG_STORE_STARTUP;
    } else if (strcasecmp("running", datastore_name) == 0) {
        datastore = SRCFG_STORE_RUNNING;
    } else {
        fprintf(stderr, "%s: Invalid datastore specified (select either \"running\" or \"startup\").\n", argv[0]);
        rc = SR_ERR_INVAL_ARG;
        goto terminate;
    }
    /*  -> find default editor if none specified */
    if (NULL == editor && SRCFG_OP_EDIT == operation) {
        editor = getenv("VISUAL");
        if (NULL == editor) {
            editor = getenv("EDITOR");
        }
        if (NULL == editor) {
            fprintf(stderr, "%s: Preferred text editor is not specified (select using the -e/--editor option).\n", argv[0]);
            rc = SR_ERR_INVAL_ARG;
            goto terminate;
        }
    }

    /* set log levels */
    sr_log_stderr(SR_LL_ERR);
    sr_log_syslog(SR_LL_NONE);
    if ((log_level >= SR_LL_NONE) && (log_level <= SR_LL_DBG)) {
        sr_log_stderr(log_level);
    }

    /* connect to sysrepo */
    rc = sr_connect("sysrepocfg", SR_CONN_DEFAULT, &srcfg_connection);
    if (SR_ERR_OK == rc) {
        rc = sr_session_start(srcfg_connection, datastore == SRCFG_STORE_RUNNING ? SR_DS_RUNNING : SR_DS_STARTUP,
                              SR_SESS_DEFAULT, &srcfg_session);
    }
    if (SRCFG_STORE_RUNNING == datastore) {
        rc = sr_check_enabled_running(srcfg_session, module_name, &enabled);
        if (SR_ERR_OK == rc && !enabled) {
            printf("Cannot operate on the running datastore as there are no active subscriptions.\n"
                   "Cancelling the operation.\n");
            rc = SR_ERR_INTERNAL;
            goto terminate;
        }
    }
    if (SR_ERR_OK != rc) {
        srcfg_report_error(rc);
        printf("Unable to connect to sysrepo. Cancelling the operation.\n");
        goto terminate;
    }

    /* call selected operation */
    switch (operation) {
        case SRCFG_OP_EDIT:
            rc = srcfg_edit_operation(module_name, datastore, format, editor, keep, permanent);
            break;
        case SRCFG_OP_IMPORT:
            rc = srcfg_import_operation(module_name, datastore, filepath, format, permanent);
            break;
        case SRCFG_OP_EXPORT:
            rc = srcfg_export_operation(module_name, filepath, format);
            break;
    }

terminate:
    if (NULL != srcfg_session) {
        sr_session_stop(srcfg_session);
    }
    if (NULL != srcfg_connection) {
        sr_disconnect(srcfg_connection);
    }

    return (SR_ERR_OK == rc) ? EXIT_SUCCESS : EXIT_FAILURE;
}