Skip to content

validation of non present obsolete container #2370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeremie6wind opened this issue Mar 25, 2025 · 0 comments
Open

validation of non present obsolete container #2370

jeremie6wind opened this issue Mar 25, 2025 · 0 comments
Labels
is:enhancement Request for adding new feature or enahncing functionality. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)

Comments

@jeremie6wind
Copy link

Hi,
Parsing a data tree with obsolete container in the schema gives a warning
even if the container is not present in the data tree.
Is it expected ?
Should we look inside the container if something is present before returning the warning?
This is an example:

#include <libyang.h>
#include <stdio.h>
#include <stdlib.h>

/* gcc -o libyang_test libyang_test.c -I /usr/local/include/libyang -lyang */

#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
    ly_in_new_memory(DATA, &in); \
    { \
        LY_ERR __r = lys_parse(ctx, in, FORMAT, FEATURES, MOD); \
        if (__r != LY_SUCCESS) { \
            printf("[  MSG     ] Module parsing failed:\n"); \
            for (const struct ly_err_item *e = ly_err_first(ctx); e; e = e->next) { \
                printf("[  MSG     ] \t%s Schema path %s\n", e->msg, e->schema_path); \
            } \
            exit(-1); \
        } \
    } \
    ly_in_free(in, 0); \
    in = NULL

#define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, RET, OUT_NODE) \
    { \
        LY_ERR _r = lyd_parse_data_mem(ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE); \
        if (_r != RET) { \
            if (_r) { \
                printf("%s != 0x%d; MSG: %s", #RET, _r, ly_err_last(ctx)->msg); \
            } else { \
                printf("%s != 0x%d", #RET, _r); \
            } \
        } \
    }

#define LYD_TREE_CREATE(INPUT, MODEL) \
                CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)

int main(int argc, char *argv[])
{
    struct lyd_node *tree;
    struct ly_ctx *ctx;  /**< libyang context */
    struct ly_in *in;    /**< Input handler */

    const char *schema =
            "module a {\n"
            "    namespace urn:tests:a;\n"
            "    prefix a;\n"
            "    yang-version 1.1;\n"
            "\n"
            "    container cont {\n"
            "        leaf a {\n"
            "            type string;\n"
            "        }\n"
            "        leaf b {\n"
            "            type string;\n"
            "        }\n"
	    "        container cont2 {\n"
            "          leaf b {\n"
            "            type string;\n"
            "          }\n"
            "          status obsolete;\n"
	    "        }\n"
            "    }\n"
            "}";
    ly_ctx_new(NULL, 0, &ctx);

    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
    LYD_TREE_CREATE("<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont>", tree);
    lyd_free_all(tree);
}

It gives:

"Obsolete schema node "cont2" instantiated in data."

Whereas cont2 is not in the data tree.
Thank you.
Best regards.

jeremie6wind added a commit to jeremie6wind/libyang that referenced this issue Mar 25, 2025
jeremie6wind added a commit to jeremie6wind/libyang that referenced this issue Mar 25, 2025
jeremie6wind added a commit to jeremie6wind/libyang that referenced this issue Apr 2, 2025
@michalvasko michalvasko added is:enhancement Request for adding new feature or enahncing functionality. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...) labels Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:enhancement Request for adding new feature or enahncing functionality. status:completed From the developer perspective, the issue was solved (bug fixed, question answered,...)
Projects
None yet
Development

No branches or pull requests

2 participants