Refactor NETCONF code after migrating to sysrepo2
Issue 2311 migrated the code to sysrepo2, but did a minimum amount of changes required to do so. Because of that, there are some parts of the code that are not completely adjusted to the new dependencies. Here are some of the proposed changes that would make the code more cohesive or that would just refactor the code for improved readability:
- The basic translators might not be able to translate all data types. The migration was done in a best-effort approach to apease the unit tests. But there is a noticeable lack of tests for unions and leafrefs for example.
keatest-module
has unions, but only one variant of it is tested. There is this discussion in the MR from 2311 that details one test case. - Consider removing the
LeafBaseType
argument fromTranslatorBasic::value()
. The information available in the givenElementPtr
might be enough to do the translation. - Rename
s_val
todata_node
where appropriate. The data type was changed fromS_Value
toDataNode
, but the variable name was left the same to minimize changes. They are not equivalent. The former represents the value of a leaf or leaf-list member. The latter can represent an entire tree of data. - Have references with meaningful names to
service_pair.first
andservice_pair.second
insrc/bin/netconf
. It's confusing what is one and what is the other. The first one is the module name, and the other is the kea-netconf configuration, I think. - Rename
SysrepoError
toNetconfError
. Errors can come from both libyang and sysrepo, so let's be inclusive. - Consider changing
ConstElementPtr
s toElementPtr
s insrc/lib/yang
andsrc/bin/netconf
and, with this, remove the need forconst_pointer_cast
. I like to squabble about the undefined behavior that these present, and if we're not removing them from everywhere, I would like to have it removed at least in the code that I am responsible for. - Consider renaming methods in
TranslatorBasic
. I think their names can be more representative of what they do, especially after the migration. - Solve doxygen warnings about functions with the same name in
src/lib/yang
. - Use
checkAndGetLeaf
andcheckAndSetLeaf
where possible in translators. -
decode64
andencode64
are free-standing functions intranslator.cc
, but they can just as well be private methods insideTranslatorBasic
. - Consider doing something about
NETCONF_SUBSCRIBE_NOTIFICATIONS_FAILED
. It's an error message that shows up for the Kea modules because they don't have any notification nodes. kea-netconf continues regardless. We could at least turn it into a warning message. - Solve the few TODOs in
src/lib/yang
. - Replace
EXPECT_NO_THROW
withEXPECT_NO_THROW_LOG
insrc/lib/yang
andsrc/bin/netconf
for more insight when tests fail. - Replace
EXPECT_THROW
withEXPECT_THROW_MSG
insrc/lib/yang
andsrc/bin/netconf
for stricter checking.
Edited by Andrei Pavel