CESNET / libnetconf

C NETCONF library
Other
113 stars 83 forks source link

Method "merge" only appends the value when the value type is CDATA #256

Closed miaofenk closed 7 years ago

miaofenk commented 7 years ago

Hi,

When I try to update a parameter value using "merge" method, I found the value just append after the orig value rather than replace it. After a few trails, I found the issue was caused by the value type is "CDATA". If the value type is "text", "merge" method works correct.

Orig data:

    <cfgPATH>system_key</cfgPATH>
    <vnfcname>vnfc_name</vnfcname>
    <cfgvalue><![CDATA[{{getv "/<system_key>"}}]]></cfgvalue>

Merge "CDATA" data:

    <cfgPATH>system_key</cfgPATH>
    <vnfcname>vnfc_name</vnfcname>
    <cfgvalue><![CDATA[{{getv "/<system_key>"}}<new_data>]]></cfgvalue>

Merge "text" data:

    <cfgPATH>system_key</cfgPATH>
    <vnfcname>new_vnfc_name</vnfcname>
    <cfgvalue><![CDATA[{{getv "/<system_key>"}}<new_data>]]></cfgvalue>

Is that a issue? Hope to get your response. Thanks a lot!

rkrejci commented 7 years ago

I'm afraid that YANG does not allow to encode a value as CDATA. What is the YANG schema for your example?

miaofenk commented 7 years ago

The YANG schema is as follow:

    list configkey {
        key "cfgPATH";
        leaf cfgPATH {
            description "The system level path in etcd for a configuration key";
            type string;
        }
        leaf vnfcname {
            description "The vnfc name";
            type string;
            mandatory true;
        }
        leaf cfgvalue {
            description "The value stored in etcd for a configuration key";
            type string;
            default "NA";
        }
    }

Although YANG doesn't support CDATA type it should be treated as a normal text. The whole text should be replaced by the new value in "merge" method.

rkrejci commented 7 years ago

This use case is not implemented in libnetconf (nor libyang/libnetconf2), you are supposed to provide the final data where the CDATA are already instantiated.