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/health/SystemdUnits.cpp b/src/health/SystemdUnits.cpp
index 105c56a..ecb8c61 100644
--- a/src/health/SystemdUnits.cpp
+++ b/src/health/SystemdUnits.cpp
@@ -42,7 +42,7 @@
     // First, fetch all currently loaded units, register to their PropertiesChanged signal and create the alarm-inventory entries in a *single* edit
     m_proxyManager->callMethod("ListUnits").onInterface(managerIface).storeResultsTo(units);
     std::transform(units.begin(), units.end(), std::back_inserter(unitNames), [](const auto& unit) { return unit.template get<0>(); });
-    alarms::pushInventory(m_srSession, ALARM_ID, ALARM_INVENTORY_DESCRIPTION, unitNames, {ALARM_SEVERITY});
+    alarms::pushInventory(m_srSession, {{ALARM_ID, ALARM_INVENTORY_DESCRIPTION, unitNames, {ALARM_SEVERITY}}});
 
     for (const auto& unit : units) {
         registerSystemdUnit(connection, unit.get<0>(), unit.get<6>(), UnitState{unit.get<3>(), unit.get<4>()}, RegisterAlarmInventory::No);
diff --git a/src/ietf-hardware/sysrepo/Sysrepo.cpp b/src/ietf-hardware/sysrepo/Sysrepo.cpp
index 02e6720..7381b70 100644
--- a/src/ietf-hardware/sysrepo/Sysrepo.cpp
+++ b/src/ietf-hardware/sysrepo/Sysrepo.cpp
@@ -95,10 +95,14 @@
         std::map<std::string, State> thresholdsStates;
         std::set<std::pair<std::string, std::string>> activeSideLoadedAlarms;
 
-        alarms::pushInventory(m_session, ALARM_THRESHOLD_CROSSING_LOW, "Sensor value is below the low threshold.", {});
-        alarms::pushInventory(m_session, ALARM_THRESHOLD_CROSSING_HIGH, "Sensor value is above the high threshold.", {});
-        alarms::pushInventory(m_session, ALARM_SENSOR_MISSING, "Sensor is missing.", {});
-        alarms::pushInventory(m_session, ALARM_SENSOR_NONOPERATIONAL, "Sensor is flagged as nonoperational.", {});
+        alarms::pushInventory(
+            m_session,
+            {
+                {ALARM_THRESHOLD_CROSSING_LOW, "Sensor value is below the low threshold."},
+                {ALARM_THRESHOLD_CROSSING_HIGH, "Sensor value is above the high threshold."},
+                {ALARM_SENSOR_MISSING, "Sensor is missing."},
+                {ALARM_SENSOR_NONOPERATIONAL, "Sensor is flagged as nonoperational."},
+            });
 
         while (!m_quit) {
             m_log->trace("IetfHardware poll");
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)
+{
+}
 }
diff --git a/src/utils/alarms.h b/src/utils/alarms.h
index 9f5cbbc..1531695 100644
--- a/src/utils/alarms.h
+++ b/src/utils/alarms.h
@@ -15,7 +15,17 @@
     Yes,
 };
 
+struct AlarmInventoryEntry {
+    std::string alarmType;
+    std::string description;
+    std::vector<std::string> resources;
+    std::vector<std::string> severities;
+    WillClear willClear;
+
+    AlarmInventoryEntry(const std::string& alarmType, const std::string& description, const std::vector<std::string>& resources = {}, const std::vector<std::string>& severities = {}, WillClear willClear = WillClear::Yes);
+};
+
 void push(sysrepo::Session session, const std::string& alarmId, const std::string& alarmResource, const std::string& severity, const std::string& alarmText);
-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 = WillClear::Yes);
+void pushInventory(sysrepo::Session session, const std::vector<AlarmInventoryEntry>& alarms);
 void addResourcesToInventory(sysrepo::Session session, const std::map<std::string, std::vector<std::string>>& resourcesPerAlarm);
 }