Skip to content

Commit

Permalink
Execute Post Fail Action if VPD parsing fails (#425)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Souvik Roy committed Oct 16, 2024
1 parent effda2b commit b723db3
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,24 +1169,44 @@ types::VPDMapVariant Worker::parseVpdFile(const std::string& i_vpdFilePath)

std::shared_ptr<Parser> vpdParser = std::make_shared<Parser>(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<bool, std::string>
Expand Down

0 comments on commit b723db3

Please sign in to comment.