Switch eStoraged to asio interface

Switching the D-Bus interface to asio makes it easier to integrate with
EntityManager. In addition, this switch to asio makes sense since some
of the erase operations take a long time, about 6 minutes.

This commit also removes one of the clang-tidy checks because clang was
flagging an error in one of the boost asio files, inside the constructor
for sdbusplus::asio::connection.

Tested:
Tested most of the methods and properties using busctl.
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume FormatLuks ays 3 1 2 3 \
  xyz.openbmc_project.Inventory.Item.Volume.FilesystemType.ext4 \
  --timeout=60
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Lock
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Unlock ay 3 1 2 3
$ busctl get-property xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Locked
$ busctl get-property xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Drive Capacity
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Erase s \
  xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.VerifyGeometry
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Erase s \
  xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.LogicalOverWrite \
  --timeout=1200
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
  /xyz/openbmc_project/inventory/storage/mmcblk0 \
  xyz.openbmc_project.Inventory.Item.Volume Erase s \
  xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.LogicalVerify \
  --timeout=1200

Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I99cb371871bfa68eb0193f614f899221afd9013a
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index e7ad562..05f872f 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -4,7 +4,9 @@
 
 #include <unistd.h>
 
-#include <sdbusplus/test/sdbus_mock.hpp>
+#include <boost/asio/io_context.hpp>
+#include <sdbusplus/asio/connection.hpp>
+#include <sdbusplus/asio/object_server.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/Inventory/Item/Volume/client.hpp>
 
@@ -12,6 +14,7 @@
 #include <filesystem>
 #include <fstream>
 #include <iterator>
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -27,37 +30,31 @@
 using std::filesystem::path;
 using ::testing::_;
 using ::testing::ContainsRegex;
-using ::testing::IsNull;
 using ::testing::Return;
 using ::testing::StrEq;
 
-/*
- * This sdbus mock object gets used in the destructor of one of the parent
- * classes for the MockeStoraged object, so this can't be part of the
- * eStoragedTest class.
- */
-sdbusplus::SdBusMock sdbusMock;
-
 class EStoragedTest : public testing::Test
 {
   public:
     const char* testFileName = "testfile";
     const char* testLuksDevName = "testfile_luksDev";
-    uint64_t testSize = 24;
+    const uint64_t testSize = 24;
     std::ofstream testFile;
-    std::unique_ptr<estoraged::EStoraged> esObject;
     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;
     MockCryptsetupInterface* mockCryptIface{};
     MockFilesystemInterface* mockFsIface{};
+    boost::asio::io_context io;
+    std::shared_ptr<sdbusplus::asio::connection> conn;
+    std::unique_ptr<sdbusplus::asio::object_server> objectServer;
+    std::unique_ptr<estoraged::EStoraged> esObject;
 
     EStoragedTest() :
-        bus(sdbusplus::get_mocked_new(&sdbusMock)), passwordString("password"),
+        passwordString("password"),
         password(passwordString.begin(), passwordString.end())
     {}
 
@@ -72,24 +69,6 @@
             throw std::runtime_error("Failed to open test file");
         }
 
-        EXPECT_CALL(sdbusMock,
-                    sd_bus_add_object_vtable(IsNull(), _, StrEq(testPath),
-                                             StrEq(estoragedInterface), _, _))
-            .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));
-
-        EXPECT_CALL(sdbusMock,
-                    sd_bus_emit_object_removed(IsNull(), StrEq(testPath)))
-            .WillRepeatedly(Return(0));
-
         std::unique_ptr<MockCryptsetupInterface> cryptIface =
             std::make_unique<MockCryptsetupInterface>();
         mockCryptIface = cryptIface.get();
@@ -97,8 +76,13 @@
             std::make_unique<MockFilesystemInterface>();
         mockFsIface = fsIface.get();
 
+        conn = std::make_shared<sdbusplus::asio::connection>(io);
+        // request D-Bus server name.
+        conn->request_name("xyz.openbmc_project.eStoraged.test");
+        objectServer = std::make_unique<sdbusplus::asio::object_server>(conn);
+
         esObject = std::make_unique<estoraged::EStoraged>(
-            bus, testPath, testFileName, testLuksDevName, testSize,
+            *objectServer, testFileName, testLuksDevName, testSize,
             std::move(cryptIface), std::move(fsIface));
     }
 
@@ -111,16 +95,6 @@
 /* Test case to format and then lock the LUKS device. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -166,16 +140,6 @@
  */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -245,16 +209,6 @@
 /* Test case where we fail to set the password for the LUKS device. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -268,16 +222,6 @@
 /* Test case where we fail to load the LUKS header. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -293,16 +237,6 @@
 /* Test case where we fail to activate the LUKS device. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -321,16 +255,6 @@
 /* Test case where we fail to create the filesystem. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -351,16 +275,6 @@
 /* Test case where we fail to create the mount point. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -387,16 +301,6 @@
 /* Test case where we fail to mount the filesystem. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -431,16 +335,6 @@
 /* Test case where we fail to unmount the filesystem. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -477,16 +371,6 @@
 /* Test case where we fail to remove the mount point. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
@@ -527,16 +411,6 @@
 /* Test case where we fail to deactivate the LUKS device. */
 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));
-
     EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _)).Times(1);
 
     EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))