vpd-tool force reset command implementation
This commit implements force reset command option in vpd-tool
application.
The commit implements clearing of Phosphor Inventory Manager’s (PIM)
persisted data, restarts the PIM and VPD manager services. In turn VPD
manager triggers the VPD collection for the FRUs listed in the system
config JSON.
Output:
```
Create mismatch value, by updating keyword value only on DBus.
busctl call xyz.openbmc_project.Inventory.Manager /xyz/openbmc_project/inventory xyz.openbmc_project.Inventory.Manager Notify a{oa{sa{sv}}} 1 "/system/chassis/motherboard" 1 "com.ibm.ipzvpd.VSYS" 1 "BR" ay 2 0x32 0x33
Data On Hardware:
root@rainvpdteam:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H
{
"/sys/bus/i2c/drivers/at24/8-0050/eeprom": {
"BR": "S0"
}
}
Data on DBus:
root@rainvpdteam:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r
{
"/system/chassis/motherboard": {
"BR": "23"
}
}
On force reset command:
root@rainvpdteam:/tmp# ./vpd-tool -f
Stopping vpd-manager service.
Restarting xyz.openbmc_project.Inventory.Manager service.
Starting vpd-manager service.
After force reset command, DBus got updated with hardware data:
root@rainvpdteam:/tmp# vpd-tool -O /system/chassis/motherboard -R VSYS -K BR -r
{
"/system/chassis/motherboard": {
"BR": "S0"
}
}
root@rainvpdteam:/tmp# vpd-tool -O /sys/bus/i2c/drivers/at24/8-0050/eeprom -R VSYS -K BR -r -H
{
"/sys/bus/i2c/drivers/at24/8-0050/eeprom": {
"BR": "S0"
}
}
```
Change-Id: Ic236265817d793892902f63835667167365b8cdc
Signed-off-by: Anupama B R <anupama.b.r1@ibm.com>
diff --git a/vpd-tool/include/tool_constants.hpp b/vpd-tool/include/tool_constants.hpp
index 00c64b8..7fe0190 100644
--- a/vpd-tool/include/tool_constants.hpp
+++ b/vpd-tool/include/tool_constants.hpp
@@ -18,6 +18,7 @@
constexpr auto inventoryManagerService =
"xyz.openbmc_project.Inventory.Manager";
constexpr auto baseInventoryPath = "/xyz/openbmc_project/inventory";
+constexpr auto pimPersistPath = "/var/lib/phosphor-inventory-manager";
constexpr auto ipzVpdInfPrefix = "com.ibm.ipzvpd.";
constexpr auto vpdManagerService = "com.ibm.VPD.Manager";
@@ -44,5 +45,6 @@
constexpr auto slotNumInf = "xyz.openbmc_project.Inventory.Decorator.Slot";
constexpr auto i2cDeviceInf =
"xyz.openbmc_project.Inventory.Decorator.I2CDevice";
+constexpr auto vpdManagerProcessName = "vpd-manager";
} // namespace constants
} // namespace vpd
diff --git a/vpd-tool/src/vpd_tool.cpp b/vpd-tool/src/vpd_tool.cpp
index e9f15eb..9e2df42 100644
--- a/vpd-tool/src/vpd_tool.cpp
+++ b/vpd-tool/src/vpd_tool.cpp
@@ -6,6 +6,7 @@
#include "tool_types.hpp"
#include "tool_utils.hpp"
+#include <cstdlib>
#include <iostream>
#include <regex>
#include <tuple>
@@ -1315,8 +1316,115 @@
int VpdTool::resetVpdOnDbus()
{
- // ToDo: Implementation needs to be added
- return constants::SUCCESS;
+ // ToDo: Limit this function to lab mode only.
+
+ int l_rc = constants::FAILURE;
+ try
+ {
+ std::string l_vpdManagerStopCmd(
+ "systemctl stop " + std::string(constants::vpdManagerProcessName));
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_vpdManagerStopCmd.c_str()); l_rc != 0)
+ {
+ std::cerr << "Failed to stop " << constants::vpdManagerProcessName
+ << " service. Return code [" << l_rc << "]. Exiting."
+ << std::endl;
+ return l_rc;
+ }
+
+ std::string l_vpdServiceIsActiveCmd(
+ "systemctl is-active --quiet " +
+ std::string(constants::vpdManagerProcessName));
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_vpdServiceIsActiveCmd.c_str()); l_rc == 0)
+ {
+ std::cerr
+ << constants::vpdManagerProcessName
+ << " service is still active, can't proceed further. Return code ["
+ << l_rc << "]. Exiting." << std::endl;
+ return l_rc;
+ }
+
+ std::error_code l_ec;
+ if (static_cast<std::uintmax_t>(-1) ==
+ std::filesystem::remove_all(constants::pimPersistPath, l_ec))
+ {
+ std::cerr
+ << "Error occured while removing the persisted VPD under path ["
+ << constants::pimPersistPath << "]." << std::endl;
+
+ if (l_ec)
+ {
+ std::cerr << "Reason: " << l_ec.message() << std::endl;
+ }
+
+ std::cerr << "Reboot BMC to recover the system." << std::endl;
+ return l_rc;
+ }
+
+ std::string l_pimServiceRestartCmd(
+ "systemctl restart " +
+ std::string(constants::inventoryManagerService));
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_pimServiceRestartCmd.c_str()); l_rc != 0)
+ {
+ std::cerr << "Failed to restart "
+ << constants::inventoryManagerService
+ << " service. Return code [" << l_rc << "]. Exiting."
+ << std::endl
+ << "Reboot BMC to recover the system." << std::endl;
+ return l_rc;
+ }
+
+ std::string l_pimServiceIsActiveCmd(
+ "systemctl is-active --quiet " +
+ std::string(constants::inventoryManagerService));
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_pimServiceIsActiveCmd.c_str()); l_rc != 0)
+ {
+ std::cerr << constants::inventoryManagerService
+ << " service is not active. Return code [" << l_rc
+ << "]. Exiting." << std::endl
+ << "Reboot BMC to recover the system." << std::endl;
+ return l_rc;
+ }
+
+ std::string l_vpdManagerStartCmd(
+ "systemctl start " + std::string(constants::vpdManagerProcessName));
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_vpdManagerStartCmd.c_str()); l_rc != 0)
+ {
+ std::cerr << "Failed to start " << constants::vpdManagerProcessName
+ << " service. Return code [" << l_rc << "]. Exiting."
+ << std::endl
+ << "Reboot BMC to recover the system." << std::endl;
+ return l_rc;
+ }
+
+ std::cout << std::flush;
+ if (auto l_rc = std::system(l_vpdServiceIsActiveCmd.c_str()); l_rc != 0)
+ {
+ std::cerr << constants::vpdManagerProcessName
+ << " service is not active. Return code [" << l_rc
+ << "]. Exiting." << std::endl
+ << "Reboot BMC to recover the system." << std::endl;
+ return l_rc;
+ }
+
+ l_rc = constants::SUCCESS;
+ }
+ catch (const std::exception& l_ex)
+ {
+ // TODO: Enable logging when verbose is enabled.
+ std::cerr << l_ex.what() << std::endl;
+ }
+
+ return l_rc;
}
types::BinaryVector VpdTool::getVpdValueInBiosConfigManager(