cooling-type: Use lookupAndCallMethod

Have phosphor-cooling-type fail with a DBusMethodError exception when a
failure occurs on updating inventory.

Resolves: openbmc/openbmc#2628

Tested:
    Cooling type properties still set correctly

Change-Id: Ia7e3379fc7d75c70e9c71d4f940f9da84b9f5774
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/cooling-type/cooling_type.cpp b/cooling-type/cooling_type.cpp
index 3cb19ab..a1c4748 100644
--- a/cooling-type/cooling_type.cpp
+++ b/cooling-type/cooling_type.cpp
@@ -8,6 +8,7 @@
 #include <libevdev/libevdev.h>
 #include "utility.hpp"
 #include "cooling_type.hpp"
+#include "sdbusplus.hpp"
 
 namespace phosphor
 {
@@ -94,27 +95,17 @@
 
 void CoolingType::updateInventory(const std::string& objpath)
 {
-    using namespace phosphor::logging;
+    using namespace phosphor::fan;
 
     ObjectMap invObj = getObjectMap(objpath);
 
-    std::string invService;
-
-    invService = phosphor::fan::util::getInvService(bus);
-
     // Update inventory
-    auto invMsg = bus.new_method_call(invService.c_str(),
-                                      INVENTORY_PATH,
-                                      INVENTORY_INTF,
-                                      "Notify");
-    invMsg.append(std::move(invObj));
-    auto invMgrResponseMsg = bus.call(invMsg);
-    if (invMgrResponseMsg.is_method_error())
-    {
-        log<level::ERR>(
-            "Error in inventory manager call to update inventory");
-        elog<InternalFailure>();
-    }
+    auto invMgrResponseMsg = util::SDBusPlus::lookupAndCallMethod(
+            bus,
+            util::INVENTORY_PATH,
+            util::INVENTORY_INTF,
+            "Notify",
+            std::move(invObj));
 }
 
 }
diff --git a/cooling-type/cooling_type.hpp b/cooling-type/cooling_type.hpp
index aa02bfa..88e1335 100644
--- a/cooling-type/cooling_type.hpp
+++ b/cooling-type/cooling_type.hpp
@@ -9,9 +9,6 @@
 namespace type
 {
 
-constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
-constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
-
 struct FreeEvDev
 {
     void operator()(struct libevdev* device) const
diff --git a/cooling-type/main.cpp b/cooling-type/main.cpp
index 288f1b9..f690f80 100644
--- a/cooling-type/main.cpp
+++ b/cooling-type/main.cpp
@@ -4,6 +4,7 @@
 #include <phosphor-logging/log.hpp>
 #include "argument.hpp"
 #include "cooling_type.hpp"
+#include "sdbusplus.hpp"
 
 using namespace phosphor::cooling::type;
 using namespace phosphor::fan::util;
@@ -63,7 +64,15 @@
             coolingType.updateInventory(objpath);
             rc = 0;
         }
-
+        catch (DBusMethodError& dme)
+        {
+            rc = -1;
+            log<level::ERR>("Uncaught DBus method failure exception",
+                    entry("BUSNAME=%s", dme.busName.c_str()),
+                    entry("PATH=%s", dme.path.c_str()),
+                    entry("INTERFACE=%s", dme.interface.c_str()),
+                    entry("METHOD=%s", dme.method.c_str()));
+        }
         catch (std::exception& err)
         {
             rc = -1;