Add FRU device presence check

Resolves: openbmc/openbmc#3287

Check the FRU device's Present property upon a
FRU device info reading request.
Return 0xCB completion code for missing devices.

Tested:
Verified using ipmitool commands.

Test case 1, request info about existing FRU device:
Command: ipmitool -I lanplus -U root -P <password> -H
            <ip_addr> fru print <fru_id>
Response:    //Success, FRU data

Test case 2, request info about missing FRU device:
Command: ipmitool -I lanplus -U root -P <password> -H
            <ip_addr> fru print <fru_id>
Response: Device not present (Requested sensor, data, or record not found)

Change-Id: Iaf20f616858d5954ed2c5f5fe96363383aa943be
Signed-off-by: Kirill Pakhomov <k.pakhomov@yadro.com>
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 5b9726a..905d0b7 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -619,6 +619,19 @@
     return ipmi::responseSuccess(recordID);
 }
 
+bool isFruPresent(const std::string& fruPath)
+{
+    using namespace ipmi::fru;
+
+    sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+
+    auto propValue =
+        ipmi::getDbusProperty(bus, invMgrInterface, invObjPath + fruPath,
+                              invItemInterface, itemPresentProp);
+
+    return std::get<bool>(propValue);
+}
+
 /** @brief implements the get FRU Inventory Area Info command
  *
  *  @returns IPMI completion code plus response data
@@ -637,6 +650,12 @@
         return ipmi::responseSensorInvalid();
     }
 
+    auto path = iter->second[0].path;
+    if (!isFruPresent(path))
+    {
+        return ipmi::responseSensorInvalid();
+    }
+
     try
     {
         return ipmi::responseSuccess(