Migrate to libyang2
Explanation of some of the changes:
1) New libyang produces different schema paths, that don't include
choice/case nodes. This can be seen in Firewall.cpp.
2) New sysrepo does not use <map>, so it has to be included at multiple
places.
3) getUniqueSubtree is now just one line of code. Another commit can get
rid of it.
4) dataFromSysrepo sometimes gives less and sometimes more data. This is
because it now uses libyang instead of sr_val_t
- When it gives more data it's usually just lists or empty containers,
sr_val_t didn't give those.
- When it gives less data it's also just empty containers. This can
be seen with "sensor-data" in hardware_ietf-hardware.cpp.
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/dependencies/+/5171
Change-Id: I388536269e790b8b74ea7791c79b180adc5d80a6
Co-authored-by: Jan Kundrát <jan.kundrat@cesnet.cz>
diff --git a/tests/mock/sysrepo/events.cpp b/tests/mock/sysrepo/events.cpp
index 7ce2eba..bc654f5 100644
--- a/tests/mock/sysrepo/events.cpp
+++ b/tests/mock/sysrepo/events.cpp
@@ -8,20 +8,11 @@
#include "events.h"
namespace {
-std::string sr_ev_notif_type_to_string(const sr_ev_notif_type_t notif_type)
+std::string sr_ev_notif_type_to_string(const sysrepo::NotificationType notif_type)
{
- switch (notif_type) {
- case SR_EV_NOTIF_REALTIME:
- return "SR_EV_NOTIF_REALTIME";
- case SR_EV_NOTIF_REPLAY:
- return "SR_EV_NOTIF_REPLAY";
- case SR_EV_NOTIF_REPLAY_COMPLETE:
- return "SR_EV_NOTIF_REPLAY_COMPLETE";
- case SR_EV_NOTIF_STOP:
- return "SR_EV_NOTIF_STOP";
- default:
- return "[unknown event type]";
- }
+ std::ostringstream oss;
+ oss << notif_type;
+ return oss.str();
}
}
@@ -35,24 +26,31 @@
}
void EventWatcher::operator()(
- [[maybe_unused]] ::sysrepo::S_Session session,
- const sr_ev_notif_type_t notif_type,
- const char* xpath,
- const ::sysrepo::S_Vals vals,
- time_t timestamp)
+ sysrepo::Session,
+ uint32_t ,
+ const sysrepo::NotificationType type,
+ const std::optional<libyang::DataNode> notificationTree,
+ const sysrepo::NotificationTimeStamp timestamp)
{
Event e;
- e.xPath = xpath;
+ e.xPath = std::string{notificationTree ? std::string{notificationTree->path()} : "<no-xpath>"};
e.received = std::chrono::steady_clock::now();
-
auto log = spdlog::get("main");
- log->info("SR event {} {} {}", sr_ev_notif_type_to_string(notif_type), timestamp, xpath);
+ log->info("SR event {} {} {}", sr_ev_notif_type_to_string(type), timestamp.time_since_epoch().count(), e.xPath);
- for (size_t i = 0; i < vals->val_cnt(); ++i) {
- const auto& v = vals->val(i);
- auto s = v->val_to_string();
- log->debug(" {}: {}", v->xpath(), s);
- e.data[v->xpath()] = s;
+ if (notificationTree) {
+ for (const auto& node : notificationTree->childrenDfs()) {
+ auto path = std::string{node.path()};
+ auto val = [&] {
+ if (node.schema().nodeType() == libyang::NodeType::Leaf) {
+ return std::string{node.asTerm().valueStr()};
+ }
+
+ return std::string{""};
+ }();
+ e.data[path] = val;
+ log->debug(" {}: {}", path, val);
+ }
}
{
@@ -60,7 +58,19 @@
events->push_back(e);
}
- notifRecvCb(e);
+ switch (type) {
+ case sysrepo::NotificationType::Realtime:
+ case sysrepo::NotificationType::Replay:
+ notifRecvCb(e);
+ break;
+ case sysrepo::NotificationType::ReplayComplete:
+ case sysrepo::NotificationType::Terminated:
+ case sysrepo::NotificationType::Modified:
+ case sysrepo::NotificationType::Suspended:
+ case sysrepo::NotificationType::Resumed:
+ break;
+ }
+
}
std::vector<EventWatcher::Event>::size_type EventWatcher::count() const