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/error_codes.hpp b/vpd-manager/include/error_codes.hpp
index cea46f1..e0d8eeb 100644
--- a/vpd-manager/include/error_codes.hpp
+++ b/vpd-manager/include/error_codes.hpp
@@ -29,7 +29,11 @@
DEVICE_NOT_PRESENT,
DEVICE_PRESENCE_UNKNOWN,
GPIO_LINE_EXCEPTION,
- ERROR_PROCESSING_SYSTEM_CMD
+ ERROR_PROCESSING_SYSTEM_CMD,
+ STANDARD_EXCEPTION,
+
+ // VPD specific errors
+ UNSUPPORTED_VPD_TYPE
};
const std::unordered_map<int, std::string> errorCodeMap = {
@@ -58,5 +62,7 @@
{error_code::DEVICE_PRESENCE_UNKNOWN, "Exception on presence line GPIO."},
{error_code::GPIO_LINE_EXCEPTION, "There was an exception in GPIO line."},
{error_code::ERROR_PROCESSING_SYSTEM_CMD,
- "Error while executing system command tag."}};
+ "Error while executing system command tag."},
+ {error_code::UNSUPPORTED_VPD_TYPE, "This VPD type is not supported"},
+ {error_code::STANDARD_EXCEPTION, "Standard Exception thrown"}};
} // namespace vpd
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
diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp
index 27b1f63..dd94d3b 100644
--- a/vpd-manager/src/manager.cpp
+++ b/vpd-manager/src/manager.cpp
@@ -270,6 +270,19 @@
l_fruPath, l_writeParams, l_sysCfgJsonObj);
}
+ // log VPD write success or failure
+ auto l_logger = Logger::getLoggerInstance();
+
+ uint16_t l_errorCode;
+ l_logger->logMessage(
+ "VPD write " +
+ std::string(
+ (l_rc != constants::FAILURE) ? "successful" : "failed") +
+ " on path[" + i_vpdPath + "] : " +
+ vpdSpecificUtility::convertWriteVpdParamsToString(l_writeParams,
+ l_errorCode),
+ PlaceHolder::VPD_WRITE);
+
return l_rc;
}
catch (const std::exception& l_exception)