vpd-tool dump inventory: trim out base inventory path prefix
This commit trims out the base inventory path
prefix("/xyz/openbmc_project/inventory") from the vpd-tool
--dumpInventory and --dumpObject JSON output. Other scripts assume the
object paths in the JSON to be without the prefix.
Change-Id: I566d40cda59a3c8835590fb7a8ce8501a1a98aa0
Signed-off-by: Souvik Roy <souvik.roy10@ibm.com>
diff --git a/vpd-tool/include/vpd_tool.hpp b/vpd-tool/include/vpd_tool.hpp
index 80be8e5..3213af4 100644
--- a/vpd-tool/include/vpd_tool.hpp
+++ b/vpd-tool/include/vpd_tool.hpp
@@ -38,7 +38,7 @@
* If FRU's "Present" property is false, this API returns an empty JSON.
* Note: The caller of this API should handle empty JSON.
*
- * @throw json::exception
+ * @throw json::exception, std::out_of_range, std::bad_alloc
*/
nlohmann::json getFruProperties(const std::string& i_objectPath) const;
diff --git a/vpd-tool/src/vpd_tool.cpp b/vpd-tool/src/vpd_tool.cpp
index 7d229d7..93776c1 100644
--- a/vpd-tool/src/vpd_tool.cpp
+++ b/vpd-tool/src/vpd_tool.cpp
@@ -114,8 +114,8 @@
catch (std::exception& l_ex)
{
// TODO: Enable logging when verbose is enabled.
- // std::cerr << "Dump Object failed for FRU [" << i_fruPath
- // << "], Error: " << l_ex.what() << std::endl;
+ std::cerr << "Dump Object failed for FRU [" << i_fruPath
+ << "], Error: " << l_ex.what() << std::endl;
}
return l_rc;
}
@@ -130,9 +130,15 @@
nlohmann::json l_fruJson = nlohmann::json::object_t({});
- l_fruJson.emplace(i_objectPath, nlohmann::json::object_t({}));
+ // need to trim out the base inventory path in the FRU JSON.
+ const std::string l_displayObjectPath =
+ (i_objectPath.find(constants::baseInventoryPath) == std::string::npos)
+ ? i_objectPath
+ : i_objectPath.substr(strlen(constants::baseInventoryPath));
- auto& l_fruObject = l_fruJson[i_objectPath];
+ l_fruJson.emplace(l_displayObjectPath, nlohmann::json::object_t({}));
+
+ auto& l_fruObject = l_fruJson[l_displayObjectPath];
const auto l_prettyNameInJson = getInventoryPropertyJson<std::string>(
i_objectPath, constants::inventoryItemInf, "PrettyName");