Export the part number and serial number
This commit exposes the eMMC's part name and serial number over the
appropriate D-Bus interface, so that it can be exposed over Redfish in
bmcweb.
Tested:
$ busctl introspect xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0
...
xyz.openbmc_project.Inventory.Decorator.Asset interface - - -
.PartNumber property s "ABCDEF" emits-change
.SerialNumber property s "123456abcd" emits-change
...
$ wget -qO- http://localhost:80/redfish/v1/Chassis/DC_SCM/Drives/mmcblk0
{
"@odata.id": "/redfish/v1/Chassis/DC_SCM/Drives/mmcblk0",
"@odata.type": "#Drive.v1_7_0.Drive",
"CapacityBytes": 15634268160,
"Id": "mmcblk0",
"Links": {
"Chassis": {
"@odata.id": "/redfish/v1/Chassis/DC_SCM"
}
},
"Name": "Name",
"PartNumber": "ABCDEF",
"PhysicalLocation": {
"PartLocation": {
"LocationType": "Embedded"
}
},
"SerialNumber": "123456abcd",
"Status": {
"State": "Enabled"
}
}
Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I1d17f08b99907620b5f2c73fdaeacc84950ce64e
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index 89581ab..0bbb32b 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -42,6 +42,8 @@
"/xyz/openbmc_project/inventory/system/board/test_board/test_emmc";
const uint64_t testSize = 24;
const uint8_t testLifeTime = 25;
+ const std::string testPartNumber = "12345678";
+ const std::string testSerialNumber = "ABCDEF1234";
std::ofstream testFile;
std::string passwordString;
std::vector<uint8_t> password;
@@ -82,7 +84,8 @@
esObject = std::make_unique<estoraged::EStoraged>(
*objectServer, testConfigPath, testFileName, testLuksDevName,
- testSize, testLifeTime, std::move(cryptIface), std::move(fsIface));
+ testSize, testLifeTime, testPartNumber, testSerialNumber,
+ std::move(cryptIface), std::move(fsIface));
}
void TearDown() override
diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp
index 9059d76..5f16068 100644
--- a/src/test/util_test.cpp
+++ b/src/test/util_test.cpp
@@ -13,6 +13,8 @@
namespace estoraged_test
{
using estoraged::util::findPredictedMediaLifeLeftPercent;
+using estoraged::util::getPartNumber;
+using estoraged::util::getSerialNumber;
TEST(utilTest, passFindPredictedMediaLife)
{
@@ -24,6 +26,7 @@
testFile << "0x07 0x04";
testFile.close();
EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 40);
+ EXPECT_TRUE(std::filesystem::remove(testFileName));
}
TEST(utilTest, estimatesSame)
@@ -38,6 +41,7 @@
testFile.close();
EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 70);
+ EXPECT_TRUE(std::filesystem::remove(testFileName));
}
TEST(utilTest, estimatesNotAvailable)
@@ -51,6 +55,49 @@
testFile.close();
EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 255);
+ EXPECT_TRUE(std::filesystem::remove(testFileName));
+}
+
+TEST(utilTest, getPartNumberFail)
+{
+ std::string prefixName = ".";
+ std::string testFileName = prefixName + "/name";
+ /* The part name file won't exist for this test. */
+ EXPECT_EQ(getPartNumber(prefixName), "unknown");
+}
+
+TEST(utilTest, getPartNumberPass)
+{
+ std::string prefixName = ".";
+ std::string testFileName = prefixName + "/name";
+ std::ofstream testFile;
+ testFile.open(testFileName,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile << "ABCD1234";
+ testFile.close();
+ EXPECT_EQ(getPartNumber(prefixName), "ABCD1234");
+ EXPECT_TRUE(std::filesystem::remove(testFileName));
+}
+
+TEST(utilTest, getSerialNumberFail)
+{
+ std::string prefixName = ".";
+ std::string testFileName = prefixName + "/serial";
+ /* The serial number file won't exist for this test. */
+ EXPECT_EQ(getSerialNumber(prefixName), "unknown");
+}
+
+TEST(utilTest, getSerialNumberPass)
+{
+ std::string prefixName = ".";
+ std::string testFileName = prefixName + "/serial";
+ std::ofstream testFile;
+ testFile.open(testFileName,
+ std::ios::out | std::ios::binary | std::ios::trunc);
+ testFile << "0x12345678";
+ testFile.close();
+ EXPECT_EQ(getSerialNumber(prefixName), "0x12345678");
+ EXPECT_TRUE(std::filesystem::remove(testFileName));
}
/* Test case where we successfully find the device file. */