Fix crashes on leafref value printing

Okay. Right. Yeah. So...

Look at the test change: what I'm doing is retrieving
"/example-schema:bossPerson". Okay, so bossPerson is a leafref. Alright.

Now, let's look at how impl_lyNodesToTree worked before this patch.
It takes leaf.value() and leaf.value_type->base() and tries to convert
that into leaf_data_. Now, let's say `leaf` in this case is our
bossPerson. So we take its value() and leaf_type.base().
leaf_type.base() always tells the underlying type even through leafrefs
and union so in this case it is STRING, because bossPerson person points
to "/example-schema:person/name" and that is a string. Everything is
fine until now.

What I've found is, that there are (at least) two ways to store values,
which are leafrefs. The first one is straightforward - you use
value().leafref() to get the data node our node points to, and then you
can go all the way, until you find something that is not leafref.  Query
that node's value and bam, you have your value (which would be of type
STRING in the case of bossPerson).

However, something is kind of weird: if that is how I'm supposed to
retrieve leafref values, how come I never call this leafref() method in
`leafValueFromValue`? When I added the test I was surprised that when
dealing with bossPerson, the function worked fine. How? Well...

There is apparently another way to store leafref values and that is
DIRECTLY under the base type inside the leafref you have at the start.
That's the reason the netconf test worked just like that. I suppose if
you're retrieving just bossPerson and the other stuff, there's nothing
to point to and libyang just stores the string.

However, when using YangAccess, I do have access to the pointed-to
leafs. So in that case, the value isn't stored directly, but inside the
pointed-to leafs (because they are available). This is where the bug
came from: the libyang::Value class stored, but I pass a STRING base
type to `leafValueFromValue`. Libyang finds this mismatch and throws. So
how do I check what exactly am I dealing with?

Welp, the internal type can be queried by
Data_Node_Leaf_List::value_type, so pass that instead of the base type.

Some more info: https://github.com/CESNET/libyang/issues/1135

Change-Id: I46043e101a47fd8b11b8e2121fdf21fd73ce7cdc
2 files changed
tree: 3abad35b8399db95a570852d03f0142cf6734f85
  1. .clang-format
  2. .gitmodules
  3. .zuul.CzechLight-internal.yaml
  4. .zuul.public.yaml
  5. CMakeLists.txt
  6. Doxyfile.in
  7. LICENSE
  8. LICENSE.md
  9. README.md
  10. ci/
  11. cmake/
  12. docs/
  13. src/
  14. submodules/
  15. tests/
README.md

Console interface to NETCONF servers

This program provides an interactive console for working with YANG data. It can connect to NETCONF servers, and also talk to sysrepo locally.

Installation

For building, one needs:

Use an exact commit of any dependencies as specified in submodules/dependencies/*.

The build process uses CMake. A quick-and-dirty build with no fancy options can be as simple as mkdir build && cd build && cmake .. && make && make install.

Bug Reporting

Issue reporting and feature requests are welcome via Taiga.io.

Development

We are using Gerrit for patch submission, code review and Continuous Integration (CI). Development roadmap and planning happens over Taiga.io.

Credits

Copyright © CESNET, https://www.cesnet.cz/ . Portions copyright © Faculty of Information Technology, Czech Technical University in Prague, https://fit.cvut.cz/ . Most of the code was written by Václav Kubernát (CESNET, formerly FIT ČVUT) and Jan Kundrát (CESNET). The project is distributed under the terms of the Apache 2.0 license.