Log vpd write action to file
This commit implements changes to log VPD write action to file.
VPD WriteKeyword API is exposed on DBus and can be triggered by any
application. VPD write also has the potential to corrupt data in some
cases. Hence all VPD write actions need to be logged. This commit also
implements an utility API to convert WriteVpdParams to string data type.
Test:
```
- execute vpd-tool writeKeyword on Op Panel's VINI record, CC keyword
- observe vpd-tool writeKeyword is successful and following log entry is
added in /var/lib/vpd/vpdWrite.log
2025-09-18 08:17:02.367 [Info] FileName: /usr/src/debug/openpower-fru-vpd
/1.0+git/vpd-manager/src/manager.cpp, Line: 277 VPD write successful on
path[/xyz/openbmc_project/inventory/system/chassis/motherboard/tpm_wilson
] : Record: VINI Keyword: CC Value: 0x36423630
- execute vpd-tool writeKeyword with invalid Keyword, observe no new log
added to /var/lib/vpd/vpdWrite.log
```
Change-Id: I209d761d3504dea6a1b65577fb4f3ee548c8adf6
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index fa8c3fc..33ba317 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -1129,5 +1129,50 @@
return std::string{};
}
+
+/**
+ * @brief API to convert write VPD parameters to a string.
+ *
+ * @param[in] i_paramsToWriteData - write VPD parameters.
+ * @param[out] o_errCode - To set error code in case of error.
+ *
+ * @return On success returns string representation of write VPD parameters,
+ * otherwise returns an empty string.
+ */
+inline const std::string convertWriteVpdParamsToString(
+ const types::WriteVpdParams& i_paramsToWriteData,
+ uint16_t& o_errCode) noexcept
+{
+ try
+ {
+ if (const types::IpzData* l_ipzDataPtr =
+ std::get_if<types::IpzData>(&i_paramsToWriteData))
+ {
+ return std::string{
+ "Record: " + std::get<0>(*l_ipzDataPtr) +
+ " Keyword: " + std::get<1>(*l_ipzDataPtr) + " Value: " +
+ commonUtility::convertByteVectorToHex(
+ std::get<2>(*l_ipzDataPtr))};
+ }
+ else if (const types::KwData* l_kwDataPtr =
+ std::get_if<types::KwData>(&i_paramsToWriteData))
+ {
+ return std::string{
+ "Keyword: " + std::get<0>(*l_kwDataPtr) + " Value: " +
+ commonUtility::convertByteVectorToHex(
+ std::get<1>(*l_kwDataPtr))};
+ }
+ else
+ {
+ o_errCode = error_code::UNSUPPORTED_VPD_TYPE;
+ }
+ }
+ catch (const std::exception& l_ex)
+ {
+ o_errCode = error_code::STANDARD_EXCEPTION;
+ }
+ return std::string{};
+}
+
} // namespace vpdSpecificUtility
} // namespace vpd