CESNET / netopeer

NETCONF Protocol Toolset
118 stars 65 forks source link

File callback RPC not updating the running config #153

Open Jojosep opened 7 years ago

Jojosep commented 7 years ago

Hello, i've been struggling with this issue for a couple of days.

I have a custom yang model with the following structure:

container box {
    leaf boxId {
        type string;
        config true;
        description
            "Box identifier"
    }
}

The box-state container (defined in the same yang file) has the same structure with the "-state" suffix.

I can edit config this data from other netopeer clients but the problems appears when I try to set this data from a file callback I created. The code for this callback is:

int boxid_callback(const char *filepath, xmlDocPtr *edit_config, int *exec) {
    FILE *fp = NULL;
    char *line = NULL;
    size_t len;
    xmlDocPtr doc = NULL;
    xmlNsPtr ns = NULL;
    xmlNodePtr root = NULL;

    fp = fopen(filepath, "r");
    if(fp != NULL){
        getline(&line, &len, fp);
        fclose(fp);
    }

    if(line != NULL && len > 0){
        deleteNewLineChar(line);
        nc_verb_warning("The new boxId is %s", line);
        if (boxGetBoxId() == NULL || strcmp(boxGetBoxId(), line) != 0){
            setBoxId(line); // here I set the boxId on my private structures
           //transapi_init(edit_config); <-- Pay attention to this line; I'll come here in a minute
            *exec = 1;

            doc = xmlNewDoc(BAD_CAST "1.0");
            xmlDocSetRootElement(doc, root = xmlNewDocNode(doc, NULL, BAD_CAST "box", NULL));
            ns = xmlNewNs(root, BAD_CAST "myCompanyDomain.com", NULL);
            xmlSetNs(root, ns);
            xmlNewChild(root, root->ns, BAD_CAST "boxId", BAD_CAST line);
            *edit_config = doc;
            free(line);
            line = NULL;
        }
    }

    return 0;
}

I created a box-init.c file which creates the startup config and uses the transapi_init function in my code. The transapi_init function seems to be working when executed from box-init.c but it's not creating any structure when executed from the file callback.

Whenever this function is executed (because the file gets modified) I get the following output in the netopeer server's output (executed with -v5 --I know there's only 3 levels but...):

netopeer-server[17724]: The new boxId is blackUnicorn01
netopeer-server[17724]: unknown element boxId!
netopeer-server[17724]: Merging the node boxId (src/datastore/edit_config.c:2330)
netopeer-server[17724]: Creating the node boxId (src/datastore/edit_config.c:1492)
netopeer-server[17724]: Deleting the node boxId (src/datastore/edit_config.c:1008)
netopeer-server[17724]: RelaxNG validation on subdatastore 1681692778
netopeer-server[17724]: subdatastore 1681692778 fails to validate
netopeer-server[17724]: FMON: Performing edit-config RPC failed.

I'm don't know if it's actually a bug or if there is something missing in my code; could you please help me out?

Thanks for your help.