VPD Tool : Force Collect On Hardware
This commit adds an additional option called --forceReset
in the vpd-tool.
This option is used to restart the Inventory Manager service
and retrigger the udev events which launches the VPD services.
How to use the option?
./vpd-tool --forceReset/-f/-F
This option does not take any arguments.
Tested on simics.
Signed-off-by: PriyangaRamasamy <priyanga24@in.ibm.com>
Change-Id: Icd1ad30389432f731f21cc84999f7a54fcbbec65
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index a424312..37fede1 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -30,7 +30,7 @@
"xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
properties.append(INVENTORY_PATH);
properties.append(0);
- properties.append(std::array<const char*, 1>{POWER_SUPPLY_TYPE_INTERFACE});
+ properties.append(array<const char*, 1>{POWER_SUPPLY_TYPE_INTERFACE});
auto result = bus.call(properties);
@@ -415,3 +415,45 @@
}
return 0;
}
+
+void VpdTool::forceReset(const nlohmann::basic_json<>& jsObject)
+{
+ for (const auto& itemFRUS : jsObject["frus"].items())
+ {
+ for (const auto& itemEEPROM : itemFRUS.value().items())
+ {
+ string fru = itemEEPROM.value().at("inventoryPath");
+
+ fs::path fruCachePath = INVENTORY_MANAGER_CACHE;
+ fruCachePath += INVENTORY_PATH;
+ fruCachePath += fru;
+
+ try
+ {
+ for (const auto& it : fs::directory_iterator(fruCachePath))
+ {
+ if (fs::is_regular_file(it.status()))
+ {
+ fs::remove(it);
+ }
+ }
+ }
+ catch (const fs::filesystem_error& e)
+ {
+ }
+ }
+ }
+
+ string udevRemove = "udevadm trigger -c remove -s \"*nvmem*\" -v";
+ system(udevRemove.c_str());
+
+ string invManagerRestart =
+ "systemctl restart xyz.openbmc_project.Inventory.Manager.service";
+ system(invManagerRestart.c_str());
+
+ string sysVpdStop = "systemctl stop system-vpd.service";
+ system(sysVpdStop.c_str());
+
+ string udevAdd = "udevadm trigger -c add -s \"*nvmem*\" -v";
+ system(udevAdd.c_str());
+}