Get rid of sr_val in SysrepoAccess::execute
This means that NetconfAccess and SysrepoAccess work the same, so the
ifdef can go.
Change-Id: I70b91c31e1391de5db602553b83e98f16c939364
diff --git a/src/sysrepo_access.cpp b/src/sysrepo_access.cpp
index 21eca7e..a75c5e8 100644
--- a/src/sysrepo_access.cpp
+++ b/src/sysrepo_access.cpp
@@ -304,36 +304,18 @@
}
}
-namespace {
-std::shared_ptr<sysrepo::Vals> toSrVals(const std::string& path, const DatastoreAccess::Tree& input)
-{
- auto res = std::make_shared<sysrepo::Vals>(input.size());
- {
- size_t i = 0;
- for (const auto& [k, v] : input) {
- boost::apply_visitor(updateSrValFromValue(joinPaths(path, k), res->val(i)), v);
- ++i;
- }
- }
- return res;
-}
-
-DatastoreAccess::Tree toTree(const std::string& path, const std::shared_ptr<sysrepo::Vals>& output)
-{
- DatastoreAccess::Tree res;
- for (size_t i = 0; i < output->val_cnt(); ++i) {
- const auto& v = output->val(i);
- res.emplace_back(std::string(v->xpath()).substr(joinPaths(path, "/").size()), leafValueFromVal(v));
- }
- return res;
-}
-}
-
DatastoreAccess::Tree SysrepoAccess::execute(const std::string& path, const Tree& input)
{
- auto srInput = toSrVals(path, input);
- auto output = m_session->rpc_send(path.c_str(), srInput);
- return toTree(path, output);
+ auto inputNode = m_schema->dataNodeFromPath(path);
+ for (const auto& [k, v] : input) {
+ auto node = m_schema->dataNodeFromPath(joinPaths(path, k), leafDataToString(v));
+ inputNode->merge(node, 0);
+ }
+
+ auto output = m_session->rpc_send(inputNode);
+ DatastoreAccess::Tree resTree;
+ lyNodesToTree(resTree, {output}, joinPaths(path, "/"));
+ return resTree;
}
void SysrepoAccess::copyConfig(const Datastore source, const Datastore destination)
diff --git a/tests/datastore_access.cpp b/tests/datastore_access.cpp
index 9eeed2a..6c640fd 100644
--- a/tests/datastore_access.cpp
+++ b/tests/datastore_access.cpp
@@ -16,7 +16,7 @@
using OnInvalidSchemaPathCreate = DatastoreException;
using OnInvalidSchemaPathDelete = DatastoreException;
using OnInvalidSchemaPathMove = sysrepo::sysrepo_exception;
-using OnInvalidRpcPath = sysrepo::sysrepo_exception;
+using OnInvalidRpcPath = std::runtime_error;
using OnInvalidRpcInput = sysrepo::sysrepo_exception;
using OnKeyNotFound = void;
using OnExec = void;
@@ -1042,10 +1042,8 @@
DatastoreAccess::Tree input, output;
output = {
-#ifdef netconf_BACKEND
{"/example-schema:ports[name='A']", special_{SpecialValue::List}},
{"/example-schema:ports[name='A']/name", enum_{"A"}},
-#endif
{"success", true}
};
datastore->createItem("/example-schema:ports[name='A']");