Handle error code in pre action
Call to execute pre action needs to handle error code to detect the type
of failure that occurred while executing the required tags.
Based on error code adequate action needs to be taken.
Change-Id: I428d8eab7d895b17a26068a116c28de1d4616628
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index de14c38..b5b3780 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1175,17 +1175,18 @@
}
bool Worker::processPreAction(const std::string& i_vpdFilePath,
- const std::string& i_flagToProcess)
+ const std::string& i_flagToProcess,
+ uint16_t& i_errCode)
{
if (i_vpdFilePath.empty() || i_flagToProcess.empty())
{
- logging::logMessage(
- "Invalid input parameter. Abort processing pre action");
+ i_errCode = error_code::INVALID_INPUT_PARAMETER;
return false;
}
if ((!jsonUtility::executeBaseAction(m_parsedJson, "preAction",
- i_vpdFilePath, i_flagToProcess)) &&
+ i_vpdFilePath, i_flagToProcess,
+ i_errCode)) &&
(i_flagToProcess.compare("collection") == constants::STR_CMP_SUCCESS))
{
// TODO: Need a way to delete inventory object from Dbus and persisted
@@ -1265,11 +1266,14 @@
}
}
+ uint16_t l_errCode = 0;
if (!jsonUtility::executeBaseAction(m_parsedJson, "postAction",
- i_vpdFruPath, i_flagToProcess))
+ i_vpdFruPath, i_flagToProcess,
+ l_errCode))
{
logging::logMessage(
- "Execution of post action failed for path: " + i_vpdFruPath);
+ "Execution of post action failed for path: " + i_vpdFruPath +
+ " . Reason: " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
// If post action was required and failed only in that case return
// false. In all other case post action is considered passed.
@@ -1295,10 +1299,23 @@
"preAction", "collection"))
{
isPreActionRequired = true;
- if (!processPreAction(i_vpdFilePath, "collection"))
+ uint16_t l_errCode = 0;
+ if (!processPreAction(i_vpdFilePath, "collection", l_errCode))
{
+ if (l_errCode == error_code::DEVICE_NOT_PRESENT)
+ {
+ logging::logMessage(
+ vpdSpecificUtility::getErrCodeMsg(l_errCode) +
+ i_vpdFilePath);
+ // Presence pin has been read successfully and has been read
+ // as false, so this is not a failure case, hence returning
+ // empty variant so that pre action is not marked as failed.
+ return types::VPDMapVariant{};
+ }
throw std::runtime_error(
- std::string(__FUNCTION__) + " Pre-Action failed");
+ std::string(__FUNCTION__) +
+ " Pre-Action failed with error: " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode));
}
}
@@ -1709,9 +1726,17 @@
if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
"preAction", "deletion"))
{
- if (!processPreAction(l_fruPath, "deletion"))
+ uint16_t l_errCode = 0;
+ if (!processPreAction(l_fruPath, "deletion", l_errCode))
{
- throw std::runtime_error("Pre action failed");
+ std::string l_msg = "Pre action failed";
+ if (l_errCode)
+ {
+ l_msg +=
+ " Reason: " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode);
+ }
+ throw std::runtime_error(l_msg);
}
}