hardware: push alarm-inventory alarms in one batch
This reduces the first initial push to alarm-inventory from 4 edits to
1.
What a simple diff in src/ and what a mess under tests/.
Change-Id: I07f38e529341f2bcdcc51e2e9562b641971c553e
diff --git a/src/utils/alarms.cpp b/src/utils/alarms.cpp
index f079f8d..67d57b6 100644
--- a/src/utils/alarms.cpp
+++ b/src/utils/alarms.cpp
@@ -30,21 +30,23 @@
session.sendRPC(inputNode);
}
-void pushInventory(sysrepo::Session session, const std::string& alarmId, const std::string& description, const std::vector<std::string>& resources, const std::vector<std::string>& severities, WillClear willClear)
+void pushInventory(sysrepo::Session session, const std::vector<AlarmInventoryEntry>& entries)
{
- const auto prefix = alarmInventory + "/alarm-type[alarm-type-id='" + alarmId + "'][alarm-type-qualifier='']";
-
utils::ScopedDatastoreSwitch s(session, sysrepo::Datastore::Operational);
- session.setItem(prefix + "/will-clear", willClear == WillClear::Yes ? "true" : "false");
- session.setItem(prefix + "/description", description);
+ for (const auto& entry: entries) {
+ const auto prefix = alarmInventory + "/alarm-type[alarm-type-id='" + entry.alarmType + "'][alarm-type-qualifier='']";
- for (const auto& severity : severities) {
- session.setItem(prefix + "/severity-level", severity);
- }
+ session.setItem(prefix + "/will-clear", entry.willClear == WillClear::Yes ? "true" : "false");
+ session.setItem(prefix + "/description", entry.description);
- for (const auto& resource : resources) {
- session.setItem(prefix + "/resource", resource);
+ for (const auto& severity : entry.severities) {
+ session.setItem(prefix + "/severity-level", severity);
+ }
+
+ for (const auto& resource : entry.resources) {
+ session.setItem(prefix + "/resource", resource);
+ }
}
session.applyChanges();
@@ -63,4 +65,13 @@
}
session.applyChanges();
}
+
+AlarmInventoryEntry::AlarmInventoryEntry(const std::string& alarmType, const std::string& description, const std::vector<std::string>& resources, const std::vector<std::string>& severities, WillClear willClear)
+ : alarmType(alarmType)
+ , description(description)
+ , resources(resources)
+ , severities(severities)
+ , willClear(willClear)
+{
+}
}