Initial integration with Entity Manager
This commit changes eStoraged so that it doesn't take a specific device
as an argument. Instead, it looks for a config object from Entity
Manager and creates a D-Bus object corresponding to the config object.
The config objects need to expose the following interface:
"xyz.openbmc_project.Configuration.EmmcDevice"
To support more types of storage devices in the future, we can introduce
a new interface for each one.
In addition, eStoraged currently only supports 1 eMMC device. If we want
to support more than one in the future, we will need to add more
information to the Entity Manager config, to distinguish between them.
Assuming the eMMC is located on a FRU-detectable board, an "Exposes"
entry can be added to that board's Entity Manager config, for example:
{
"Name": "example_emmc",
"Type": "EmmcDevice"
}
Doing so will tell Entity Manager to create a config object with the
EmmcDevice interface mentioned above. Then, eStoraged will find the
config object with that interface and create its own D-Bus object that
can be used to manage the eMMC.
Tested:
Updated the Entity Manager config (as described above), started
eStoraged, then tested most of its methods and properties using busctl.
$ busctl call xyz.openbmc_project.eStoraged \
/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 \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Lock
$ busctl call xyz.openbmc_project.eStoraged \
/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 \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Drive Capacity
$ busctl call xyz.openbmc_project.eStoraged \
/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 \
/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 \
/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: If137d02e185c366f4a1437076512b4883ba6d595
diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp
index 8f53510..a4b796c 100644
--- a/src/test/util_test.cpp
+++ b/src/test/util_test.cpp
@@ -1,5 +1,11 @@
+#include "getConfig.hpp"
+
+#include <unistd.h>
+
+#include <boost/container/flat_map.hpp>
#include <util.hpp>
+#include <filesystem>
#include <fstream>
#include <gmock/gmock-matchers.h>
@@ -49,4 +55,136 @@
EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 255);
}
+/* Test case where we successfully find the device file. */
+TEST(utilTest, findDevicePass)
+{
+ estoraged::StorageData data;
+
+ /* Set up the map of properties. */
+ data.emplace(std::string("Type"),
+ estoraged::BasicVariantType("EmmcDevice"));
+ data.emplace(std::string("Name"), estoraged::BasicVariantType("emmc"));
+
+ /* Create a dummy device file. */
+ const std::string testDevName("mmcblk0");
+ std::ofstream testFile;
+ testFile.open(testDevName,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Create another dummy file. */
+ const std::string testDummyFilename("abc");
+ testFile.open(testDummyFilename,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Look for the device file. */
+ std::filesystem::path deviceFile, sysfsDir;
+ std::string luksName;
+ EXPECT_TRUE(estoraged::util::findDevice(data, std::filesystem::path("./"),
+ deviceFile, sysfsDir, luksName));
+
+ /* Validate the results. */
+ EXPECT_EQ("/dev/mmcblk0", deviceFile.string());
+ EXPECT_EQ("./mmcblk0/device", sysfsDir.string());
+ EXPECT_EQ("luks-mmcblk0", luksName);
+
+ /* Delete the dummy files. */
+ EXPECT_EQ(0, unlink(testDevName.c_str()));
+ EXPECT_EQ(0, unlink(testDummyFilename.c_str()));
+}
+
+/* Test case where the "Type" property doesn't exist. */
+TEST(utilTest, findDeviceNoTypeFail)
+{
+ estoraged::StorageData data;
+
+ /* Set up the map of properties (with the "Type" property missing). */
+ data.emplace(std::string("Name"), estoraged::BasicVariantType("emmc"));
+
+ /* Create a dummy device file. */
+ const std::string testDevName("mmcblk0");
+ std::ofstream testFile;
+ testFile.open(testDevName,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Create another dummy file. */
+ const std::string testDummyFilename("abc");
+ testFile.open(testDummyFilename,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Look for the device file. */
+ std::filesystem::path deviceFile, sysfsDir;
+ std::string luksName;
+ EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
+ deviceFile, sysfsDir, luksName));
+
+ /* Delete the dummy files. */
+ EXPECT_EQ(0, unlink(testDevName.c_str()));
+ EXPECT_EQ(0, unlink(testDummyFilename.c_str()));
+}
+
+/* Test case where the device type is not supported. */
+TEST(utilTest, findDeviceUnsupportedTypeFail)
+{
+ estoraged::StorageData data;
+
+ /* Set up the map of properties (with an unsupported "Type"). */
+ data.emplace(std::string("Type"), estoraged::BasicVariantType("NvmeDrive"));
+ data.emplace(std::string("Name"),
+ estoraged::BasicVariantType("some_drive"));
+
+ /* Create a dummy device file. */
+ const std::string testDevName("mmcblk0");
+ std::ofstream testFile;
+ testFile.open(testDevName,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Create another dummy file. */
+ const std::string testDummyFilename("abc");
+ testFile.open(testDummyFilename,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Look for the device file. */
+ std::filesystem::path deviceFile, sysfsDir;
+ std::string luksName;
+ EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
+ deviceFile, sysfsDir, luksName));
+
+ /* Delete the dummy files. */
+ EXPECT_EQ(0, unlink(testDevName.c_str()));
+ EXPECT_EQ(0, unlink(testDummyFilename.c_str()));
+}
+
+/* Test case where we can't find the device file. */
+TEST(utilTest, findDeviceNotFoundFail)
+{
+ estoraged::StorageData data;
+
+ /* Set up the map of properties. */
+ data.emplace(std::string("Type"),
+ estoraged::BasicVariantType("EmmcDevice"));
+ data.emplace(std::string("Name"), estoraged::BasicVariantType("emmc"));
+
+ /* Create a dummy file. */
+ const std::string testDummyFilename("abc");
+ std::ofstream testFile;
+ testFile.open(testDummyFilename,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile.close();
+
+ /* Look for the device file. */
+ std::filesystem::path deviceFile, sysfsDir;
+ std::string luksName;
+ EXPECT_FALSE(estoraged::util::findDevice(data, std::filesystem::path("./"),
+ deviceFile, sysfsDir, luksName));
+
+ /* Delete the dummy file. */
+ EXPECT_EQ(0, unlink(testDummyFilename.c_str()));
+}
+
} // namespace estoraged_test