Add the Drives Interface to eStorageD

This new interface will be able to send machine health information from
eStorageD to clients on dbus using phosphor dbus interfaces.

$ busctl call -j xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetSubTree  sias "/xyz/openbmc_project/inventory" 0 1 "xyz.openbmc_project.Inventory.Item.Drive"

$ curl -u root:0penBmc -X GET "http://localbmc/redfish/v1/Systems/system/Storage/1/Drives/mmcblk0"

Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I91facaf6d1ac0d52258fc97ba93e6f2138619073
diff --git a/include/estoraged.hpp b/include/estoraged.hpp
index 791134d..d14a007 100644
--- a/include/estoraged.hpp
+++ b/include/estoraged.hpp
@@ -8,6 +8,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/exception.hpp>
 #include <sdbusplus/server/object.hpp>
+#include <xyz/openbmc_project/Inventory/Item/Drive/server.hpp>
 #include <xyz/openbmc_project/Inventory/Item/Volume/server.hpp>
 
 #include <filesystem>
@@ -18,6 +19,8 @@
 
 namespace estoraged
 {
+using driveInherit = sdbusplus::server::object_t<
+    sdbusplus::xyz::openbmc_project::Inventory::Item::server::Drive>;
 using eStoragedInherit = sdbusplus::server::object_t<
     sdbusplus::xyz::openbmc_project::Inventory::Item::server::Volume>;
 using estoraged::Cryptsetup;
@@ -26,7 +29,7 @@
 /** @class eStoraged
  *  @brief eStoraged object to manage a LUKS encrypted storage device.
  */
-class EStoraged : eStoragedInherit
+class EStoraged : private eStoragedInherit, private driveInherit
 {
   public:
     /** @brief Constructor for eStoraged
@@ -47,7 +50,7 @@
               std::unique_ptr<FilesystemInterface> fsInterface =
                   std::make_unique<Filesystem>()) :
         eStoragedInherit(bus, path),
-        devPath(devPath), containerName(luksName),
+        driveInherit(bus, path), devPath(devPath), containerName(luksName),
         mountPoint("/mnt/" + luksName + "_fs"),
         cryptIface(std::move(cryptInterface)), fsIface(std::move(fsInterface))
     {}
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index 7a3286c..e77d4c6 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -48,6 +48,7 @@
     const char* testPath = "/test/openbmc_project/storage/test_dev";
     const char* estoragedInterface =
         "xyz.openbmc_project.Inventory.Item.Volume";
+    const char* driveInterface = "xyz.openbmc_project.Inventory.Item.Drive";
     sdbusplus::bus::bus bus;
     std::string passwordString;
     std::vector<uint8_t> password;
@@ -76,6 +77,11 @@
             .WillRepeatedly(Return(0));
 
         EXPECT_CALL(sdbusMock,
+                    sd_bus_add_object_vtable(IsNull(), _, StrEq(testPath),
+                                             StrEq(driveInterface), _, _))
+            .WillRepeatedly(Return(0));
+
+        EXPECT_CALL(sdbusMock,
                     sd_bus_emit_object_added(IsNull(), StrEq(testPath)))
             .WillRepeatedly(Return(0));
 
@@ -105,6 +111,11 @@
 TEST_F(EStoragedTest, FormatPass)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -155,6 +166,11 @@
 TEST_F(EStoragedTest, MountPointExistsPass)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -229,6 +245,11 @@
 TEST_F(EStoragedTest, AddKeyslotFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -247,6 +268,11 @@
 TEST_F(EStoragedTest, LoadLuksHeaderFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -267,6 +293,11 @@
 TEST_F(EStoragedTest, ActivateFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -290,6 +321,11 @@
 TEST_F(EStoragedTest, CreateFilesystemFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -315,6 +351,11 @@
 TEST_F(EStoragedTest, CreateMountPointFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -346,6 +387,11 @@
 TEST_F(EStoragedTest, MountFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -385,6 +431,11 @@
 TEST_F(EStoragedTest, UnmountFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -426,6 +477,11 @@
 TEST_F(EStoragedTest, RemoveMountPointFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));
@@ -471,6 +527,11 @@
 TEST_F(EStoragedTest, DeactivateFail)
 {
     EXPECT_CALL(sdbusMock,
+                sd_bus_emit_properties_changed_strv(IsNull(), StrEq(testPath),
+                                                    StrEq(driveInterface), _))
+        .WillRepeatedly(Return(0));
+
+    EXPECT_CALL(sdbusMock,
                 sd_bus_emit_properties_changed_strv(
                     IsNull(), StrEq(testPath), StrEq(estoragedInterface), _))
         .WillRepeatedly(Return(0));