Add info about config false leafs to describe
Change-Id: Ie256f11617a48ec6dfa913cae1484550e9ec8664
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 22c1824..f3fde9e 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -127,6 +127,11 @@
ss << "list";
break;
}
+
+ if (!m_datastore.schema()->isConfig(path)) {
+ ss << " (ro)";
+ }
+
return ss.str();
}
diff --git a/src/schema.hpp b/src/schema.hpp
index 8cdffa1..b8baf34 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -54,6 +54,7 @@
virtual bool isModule(const std::string& name) const = 0;
virtual bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const = 0;
virtual bool leafIsKey(const std::string& leafPath) const = 0;
+ virtual bool isConfig(const std::string& path) const = 0;
virtual const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const = 0;
virtual yang::TypeInfo leafType(const std::string& path) const = 0;
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 6815015..50a6370 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -216,3 +216,8 @@
{
throw std::runtime_error{"Internal error: StaticSchema::leafTypeName(std::string) not implemented. The tests should not have called this overload."};
}
+
+bool StaticSchema::isConfig([[maybe_unused]] const std::string& leafPath) const
+{
+ throw std::runtime_error{"Internal error: StaticSchema::isConfigLeaf(std::string) not implemented. The tests should not have called this overload."};
+}
diff --git a/src/static_schema.hpp b/src/static_schema.hpp
index 8b160b0..554d83a 100644
--- a/src/static_schema.hpp
+++ b/src/static_schema.hpp
@@ -50,6 +50,7 @@
bool isModule(const std::string& name) const override;
bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
bool leafIsKey(const std::string& leafPath) const override;
+ bool isConfig(const std::string& leafPath) const override;
const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const std::string& path) const override;
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 2719bc6..046bfcd 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -455,3 +455,8 @@
auto node = getSchemaNode(path.c_str());
return node->dsc() ? std::optional{node->dsc()} : std::nullopt;
}
+
+bool YangSchema::isConfig(const std::string& path) const
+{
+ return getSchemaNode(path.c_str())->flags() & LYS_CONFIG_W;
+}
diff --git a/src/yang_schema.hpp b/src/yang_schema.hpp
index a2981ed..a1b7832 100644
--- a/src/yang_schema.hpp
+++ b/src/yang_schema.hpp
@@ -36,6 +36,7 @@
bool isModule(const std::string& name) const override;
bool listHasKey(const schemaPath_& location, const ModuleNodePair& node, const std::string& key) const override;
bool leafIsKey(const std::string& leafPath) const override;
+ bool isConfig(const std::string& path) const override;
const std::set<std::string> listKeys(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const schemaPath_& location, const ModuleNodePair& node) const override;
yang::TypeInfo leafType(const std::string& path) const override;
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 941586d..0f8dc8f 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -354,6 +354,18 @@
}
}
+ leaf clockSpeed {
+ type int64;
+ config false;
+ }
+
+ container systemStats {
+ config false;
+ leaf upTime {
+ type uint64;
+ }
+ }
+
})";
namespace std {
@@ -762,7 +774,9 @@
"example-schema:portSettings",
"example-schema:portMapping",
"example-schema:activeMappedPort",
- "example-schema:activePort"};
+ "example-schema:activePort",
+ "example-schema:clockSpeed",
+ "example-schema:systemStats"};
}
SECTION("example-schema:a")
@@ -916,6 +930,14 @@
{
REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
}
+
+ SECTION("isConfig")
+ {
+ REQUIRE(ys.isConfig("/example-schema:leafInt32"));
+ REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
+ REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
+ REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
+ }
}
SECTION("negative")