Esempio n. 1
0
static void
test_nc_rpc_act_generic_xml(void **state)
{
    (void)state;
    struct nc_rpc *rpc = NULL;
    struct nc_rpc_act_generic *generic_rpc = NULL;

    /* create generic rpc with NC_PARAMTYPE_CONST */
    rpc = nc_rpc_act_generic_xml("xml", NC_PARAMTYPE_CONST);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC);
    generic_rpc = (struct nc_rpc_act_generic *)rpc;
    assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC);
    assert_int_equal(generic_rpc->has_data, 0);
    assert_string_equal(generic_rpc->content.xml_str, "xml");
    nc_rpc_free(rpc);

    /* create generic rpc with NC_PARAMTYPE_FREE */
    char *str = strdup("str");
    rpc = nc_rpc_act_generic_xml(str, NC_PARAMTYPE_FREE);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC);
    generic_rpc = (struct nc_rpc_act_generic *)rpc;
    assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC);
    assert_int_equal(generic_rpc->has_data, 0);
    assert_string_equal(generic_rpc->content.xml_str, str);
    nc_rpc_free(rpc);

    /* create generic rpc with NC_PARAMTYPE_DUP_AND_FREE */
    rpc = nc_rpc_act_generic_xml("xml", NC_PARAMTYPE_DUP_AND_FREE);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC);
    generic_rpc = (struct nc_rpc_act_generic *)rpc;
    assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC);
    assert_int_equal(generic_rpc->has_data, 0);
    assert_string_equal(generic_rpc->content.xml_str, "xml");
    nc_rpc_free(rpc);
}
Esempio n. 2
0
/* function to check if values of cancel rpc are set correctly */
void
check_cancel_rpc(struct nc_rpc *rpc, const char *persist_id)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_CANCEL);
    struct nc_rpc_cancel *cancel_rpc = (struct nc_rpc_cancel *)rpc;

    assert_int_equal(cancel_rpc->type, NC_RPC_CANCEL);
    assert_string_equal(cancel_rpc->persist_id, persist_id);
}
Esempio n. 3
0
/* function to check if values of validate rpc are set correctly */
void
check_validate_rpc(struct nc_rpc *rpc, NC_DATASTORE source, const char *url_or_config)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_VALIDATE);
    struct nc_rpc_validate *validate_rpc = (struct nc_rpc_validate *)rpc;

    assert_int_equal(validate_rpc->type, NC_RPC_VALIDATE);
    assert_int_equal(validate_rpc->source, source);
    assert_string_equal(validate_rpc->url_config_src, url_or_config);
}
Esempio n. 4
0
/* function to check if values of get rpc are set correctly */
void
check_get_rpc(struct nc_rpc *rpc, const char *filter, NC_WD_MODE wd_mode)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GET);
    struct nc_rpc_get *get_rpc = (struct nc_rpc_get *)rpc;

    assert_int_equal(get_rpc->type, NC_RPC_GET);
    assert_string_equal(get_rpc->filter, filter);
    assert_int_equal(get_rpc->wd_mode, wd_mode);
}
Esempio n. 5
0
/* function to check if values of delete rpc are set correctly */
void
check_delete(struct nc_rpc *rpc, NC_DATASTORE target, const char *url)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_DELETE);
    struct nc_rpc_delete *delete_rpc = (struct nc_rpc_delete *)rpc;

    assert_int_equal(delete_rpc->type, NC_RPC_DELETE);
    assert_int_equal(delete_rpc->target, target);
    assert_string_equal(delete_rpc->url, url);
}
Esempio n. 6
0
/* function to check if values of getconfig rpc are set correctly */
void
check_getconfig(struct nc_rpc *rpc, enum NC_DATASTORE_TYPE source, char *filter, NC_WD_MODE wd_mode)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GETCONFIG);
    struct nc_rpc_getconfig *getconfig_rpc = (struct nc_rpc_getconfig *)rpc;

    assert_int_equal(getconfig_rpc->type, NC_RPC_GETCONFIG);
    assert_int_equal(getconfig_rpc->source, source);
    assert_string_equal(getconfig_rpc->filter, filter);
    assert_int_equal(getconfig_rpc->wd_mode, wd_mode);
}
Esempio n. 7
0
/* function to check if values of getschema rpc are set correctly */
void
check_getschema_rpc(struct nc_rpc *rpc, const char *identifier, const char *version, const char *format)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_GETSCHEMA);
    struct nc_rpc_getschema *getchema_rpc = (struct nc_rpc_getschema *)rpc;

    assert_int_equal(getchema_rpc->type, NC_RPC_GETSCHEMA);
    assert_string_equal(getchema_rpc->identifier, identifier);
    assert_string_equal(getchema_rpc->version, version);
    assert_string_equal(getchema_rpc->format, format);
}
Esempio n. 8
0
static void
test_nc_rpc_discard(void **state)
{
    (void)state;
    struct nc_rpc *rpc = NULL;

    rpc = nc_rpc_discard();
    assert_non_null(rpc);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_DISCARD);

    nc_rpc_free(rpc);
}
Esempio n. 9
0
/* function to check if values of commit rpc are set correctly */
void
check_commit_rpc(struct nc_rpc *rpc, int confirmed, uint32_t confirm_timeout, const char *persist, const char *persist_id)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_COMMIT);
    struct nc_rpc_commit *commit_rpc = (struct nc_rpc_commit *)rpc;

    assert_int_equal(commit_rpc->type, NC_RPC_COMMIT);
    assert_int_equal(commit_rpc->confirmed, confirmed);
    assert_int_equal(commit_rpc->confirm_timeout, confirm_timeout);
    assert_string_equal(commit_rpc->persist, persist);
    assert_string_equal(commit_rpc->persist_id, persist_id);
}
Esempio n. 10
0
/* function to check if values of subscribe rpc are set correctly */
void
check_subscribe_rpc(struct nc_rpc *rpc, const char *stream_name, const char *filter,
                    const char *start_time, const char *stop_time)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_SUBSCRIBE);
    struct nc_rpc_subscribe *subscribe_rpc = (struct nc_rpc_subscribe *)rpc;

    assert_int_equal(subscribe_rpc->type, NC_RPC_SUBSCRIBE);
    assert_string_equal(subscribe_rpc->stream, stream_name);
    assert_string_equal(subscribe_rpc->filter, filter);
    assert_string_equal(subscribe_rpc->start, start_time);
    assert_string_equal(subscribe_rpc->stop, stop_time);
}
Esempio n. 11
0
/* function to check if values of copy rpc are set correctly */
void
check_copy(struct nc_rpc *rpc, NC_DATASTORE target, const char *url_trg, NC_DATASTORE source,
           const char *url_or_config_src, NC_WD_MODE wd_mode)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_COPY);
    struct nc_rpc_copy *copy_rpc = (struct nc_rpc_copy *)rpc;

    assert_int_equal(copy_rpc->type, NC_RPC_COPY);
    assert_int_equal(copy_rpc->target, target);
    assert_string_equal(copy_rpc->url_trg, url_trg);
    assert_int_equal(copy_rpc->source, source);
    assert_string_equal(copy_rpc->url_config_src, url_or_config_src);
    assert_int_equal(copy_rpc->wd_mode, wd_mode);
}
Esempio n. 12
0
/* function to check if values of edit rpc are set correctly */
void
check_edit(struct nc_rpc *rpc, NC_DATASTORE target, NC_RPC_EDIT_DFLTOP default_op, NC_RPC_EDIT_TESTOPT test_opt,
            NC_RPC_EDIT_ERROPT error_opt, const char *edit_content)
{
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_EDIT);
    struct nc_rpc_edit *edit_rpc = (struct nc_rpc_edit *)rpc;

    assert_int_equal(edit_rpc->type, NC_RPC_EDIT);
    assert_int_equal(edit_rpc->target, target);
    assert_int_equal(edit_rpc->default_op, default_op);
    assert_int_equal(edit_rpc->test_opt, test_opt);
    assert_int_equal(edit_rpc->error_opt, error_opt);
    assert_string_equal(edit_rpc->edit_cont, edit_content);
}
Esempio n. 13
0
static void
test_nc_rpc_unlock(void **state)
{
    (void)state;
    struct nc_rpc *rpc = NULL;
    struct nc_rpc_lock *unlock_rpc = NULL;

    rpc = nc_rpc_unlock(NC_DATASTORE_RUNNING);
    assert_non_null(rpc);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_UNLOCK);

    unlock_rpc = (struct nc_rpc_lock *)rpc;
    assert_int_equal(unlock_rpc->type, NC_RPC_UNLOCK);
    assert_int_equal(unlock_rpc->target, NC_DATASTORE_RUNNING);
    nc_rpc_free(rpc);
}
Esempio n. 14
0
static void
test_nc_rpc_kill(void **state)
{
    (void)state;
    struct nc_rpc *rpc = NULL;
    struct nc_rpc_kill *kill_rpc = NULL;

    rpc = nc_rpc_kill(10);
    assert_non_null(rpc);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_KILL);

    kill_rpc = (struct nc_rpc_kill *)rpc;
    assert_int_equal(kill_rpc->type, NC_RPC_KILL);
    assert_int_equal(kill_rpc->sid, 10);

    nc_rpc_free(rpc);
}
Esempio n. 15
0
static void
test_nc_rpc_act_generic(void **state)
{
    (void)state;
    struct nc_rpc *rpc = NULL;
    struct nc_rpc_act_generic *generic_rpc = NULL;
    struct lyd_node node;
    node.next = NULL;
    node.prev = &node;

    rpc = nc_rpc_act_generic(&node, NC_PARAMTYPE_CONST);
    assert_non_null(rpc);
    assert_int_equal(nc_rpc_get_type(rpc), NC_RPC_ACT_GENERIC);
    generic_rpc = (struct nc_rpc_act_generic *)rpc;
    assert_int_equal(generic_rpc->type, NC_RPC_ACT_GENERIC);
    assert_int_equal(generic_rpc->has_data, 1);
    assert_ptr_equal(generic_rpc->content.data, &node);
    nc_rpc_free(rpc);
}
Esempio n. 16
0
static PyObject *ncProcessRPC(ncSessionObject *self)
{
	NC_MSG_TYPE ret;
	NC_RPC_TYPE req_type;
	NC_OP req_op;
	nc_rpc *rpc = NULL;
	nc_reply *reply = NULL;
	struct nc_err* e = NULL;

	SESSION_CHECK(self);

	/* receive incoming message */
	ret = nc_session_recv_rpc(self->session, -1, &rpc);
	if (ret != NC_MSG_RPC) {
		if (nc_session_get_status(self->session) != NC_SESSION_STATUS_WORKING) {
			/* something really bad happend, and communication is not possible anymore */
			nc_session_free(self->session);
			self->session = NULL;
		}
		Py_RETURN_NONE;
	}

	/* process it */
	req_type = nc_rpc_get_type(rpc);
	req_op = nc_rpc_get_op(rpc);
	if (req_type == NC_RPC_SESSION) {
		/* process operations affectinf session */
		switch(req_op) {
		case NC_OP_CLOSESESSION:
			/* exit the event loop immediately without processing any following request */
			reply = nc_reply_ok();
			break;
		case NC_OP_KILLSESSION:
			/* todo: kill the requested session */
			reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED));
			break;
		default:
			reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED));
			break;
		}
	} else if (req_type == NC_RPC_DATASTORE_READ) {
		/* process operations reading datastore */
		switch (req_op) {
		case NC_OP_GET:
		case NC_OP_GETCONFIG:
			reply = ncds_apply_rpc2all(self->session, rpc,  NULL);
			break;
		default:
			reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED));
			break;
		}
	} else if (req_type == NC_RPC_DATASTORE_WRITE) {
		/* process operations affecting datastore */
		switch (req_op) {
		case NC_OP_LOCK:
		case NC_OP_UNLOCK:
		case NC_OP_COPYCONFIG:
		case NC_OP_DELETECONFIG:
		case NC_OP_EDITCONFIG:
			reply = ncds_apply_rpc2all(self->session, rpc, NULL);
			break;
		default:
			reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED));
			break;
		}
	} else {
		/* process other operations */
		reply = ncds_apply_rpc2all(self->session, rpc, NULL);
	}

	/* create reply */
	if (reply == NULL) {
		reply = nc_reply_error(nc_err_new(NC_ERR_OP_FAILED));
	} else if (reply == NCDS_RPC_NOT_APPLICABLE) {
		e = nc_err_new(NC_ERR_OP_FAILED);
		nc_err_set(e, NC_ERR_PARAM_MSG, "Requested operation cannot be performed on the managed datastore.");
		reply = nc_reply_error(e);
	}

	/* and send the reply to the client */
	nc_session_send_reply(self->session, rpc, reply);
	nc_rpc_free(rpc);
	nc_reply_free(reply);

	if (req_op == NC_OP_CLOSESESSION) {
		/* free the Session */
		nc_session_free(self->session);
		self->session = NULL;
	}

	Py_RETURN_NONE;
}