From 1c1f475a518e772b8de6c8fe5fcfdffbab6039ce Mon Sep 17 00:00:00 2001 From: Souvik Roy Date: Wed, 16 Oct 2024 05:56:32 -0500 Subject: [PATCH] Execute Post Fail Action if VPD parsing fails This commit adds changes to execute Post Fail Action for a FRU if Pre Action for the FRU has passed and VPD parsing has failed. Test: 1. Create a malformed VPD file by modifying copy of 7-0051/eeprom, name the copy as 7-0051_eeprom_noVTOC.dat 2. Create a copy of 50001001.json, name the copy as 50001001_custom.json. Replace "/sys/bus/i2c/drivers/at24/7-0051/eeprom" string in the custom JSON with "7-0051_eeprom_noVTOC.dat". 3. Run ./vpd-parser -f /tmp/7-0051_eeprom_noVTOC.dat -c ./50001001_custom.json. 4. Observe the logs to see "preAction" is successful, VPD parsing fails and "postFailAction" is executed as specified in the custom JSON. 5. Now run /vpd-parser -f /sys/bus/i2c/drivers/at24/7-0051/eeprom -c ./50001001.json. 6. Observe the logs to see "preAction" is successful, VPD parsing is successful and "postFailAction" is not executed. Signed-off-by: Souvik Roy --- src/worker.cpp | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/worker.cpp b/src/worker.cpp index 82f25f64..fba2c7f8 100644 --- a/src/worker.cpp +++ b/src/worker.cpp @@ -1169,24 +1169,44 @@ types::VPDMapVariant Worker::parseVpdFile(const std::string& i_vpdFilePath) std::shared_ptr vpdParser = std::make_shared(i_vpdFilePath, m_parsedJson); - types::VPDMapVariant l_parsedVpd = vpdParser->parse(); - - // Before returning, as collection is over, check if FRU qualifies for - // any post action in the flow of collection. - // Note: Don't change the order, post action needs to be processed only - // after collection for FRU is successfully done. - if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath, "postAction", - "collection")) + try { - if (!processPostAction(i_vpdFilePath, "collection", l_parsedVpd)) + types::VPDMapVariant l_parsedVpd = vpdParser->parse(); + + // Before returning, as collection is over, check if FRU qualifies for + // any post action in the flow of collection. + // Note: Don't change the order, post action needs to be processed only + // after collection for FRU is successfully done. + if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath, + "postAction", "collection")) { - throw std::runtime_error("Required post action failed for path " + - i_vpdFilePath + - " Aborting collection for this FRU"); + if (!processPostAction(i_vpdFilePath, "collection", l_parsedVpd)) + { + throw std::runtime_error( + "Required post action failed for path " + i_vpdFilePath + + " Aborting collection for this FRU"); + } } + + return l_parsedVpd; } + catch (std::exception& ex) + { + // If VPD parsing fails, and post fail action is required, execute it. + if (l_isPostFailActionRequired) + { + if (!jsonUtility::executePostFailAction(m_parsedJson, i_vpdFilePath, + "collection")) + { + throw std::runtime_error("Post fail action failed for path " + + i_vpdFilePath + + " Aborting collection for this FRU"); + } + } - return l_parsedVpd; + throw DataException("VPD parsing failed for " + i_vpdFilePath + + " due to error: " + ex.what()); + } } std::tuple