Update PELs while parsing FRU
Severity of PEL needs to be updated as informational in case any
of the FRU collection fails for reason other than EEPROM or data
failure, for which the severity will be handled by the specific parser.
This is done as successful collection of a FRU other than system VPD
is not a mandatory condition to bring BMC to ready state.
In case of failure in the processing of pre action, to figure out what
failed in the flow, informational PEL is added while processing
pre-action tags.
No error in case the file is not found and pre-action was not required
as FRU can be actually absent.
Empty map is also not considered for logging PEL in worker as
respective parser should take care of any error and log PEL at their
end.
Change-Id: I4adf5be3adeb5ca556b1b4283e3036361793b108
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/exceptions.hpp b/vpd-manager/include/exceptions.hpp
index 7109453..347e704 100644
--- a/vpd-manager/include/exceptions.hpp
+++ b/vpd-manager/include/exceptions.hpp
@@ -138,6 +138,11 @@
Exception(msg), m_jsonPath(path)
{}
+ /** @brief constructor
+ * @param[in] msg - Information w.r.t. exception.
+ */
+ JsonException(const std::string& msg) : Exception(msg) {}
+
/** @brief Json path getter method.
*
* @return - Json path
diff --git a/vpd-manager/include/utility/json_utility.hpp b/vpd-manager/include/utility/json_utility.hpp
index c3d358c..990abb2 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -275,15 +275,17 @@
i_baseAction.empty() || i_flagToProcess.empty())
{
throw std::runtime_error(
- "Invalid parameter. Abort processing of processSystemCmd.");
+ std::string(__FUNCTION__) +
+ " Invalid parameter. Abort processing of processSystemCmd.");
}
if (!((i_parsedConfigJson["frus"][i_vpdFilePath].at(
0)[i_baseAction][i_flagToProcess]["systemCmd"])
.contains("cmd")))
{
- throw std::runtime_error(
- "Config JSON missing required information to execute system command for EEPROM " +
+ throw JsonException(
+ std::string(__FUNCTION__) +
+ " Config JSON missing required information to execute system command for EEPROM " +
i_vpdFilePath);
}
@@ -296,8 +298,10 @@
}
catch (const std::exception& l_ex)
{
- logging::logMessage("Process system command tag failed. Error : " +
- std::string(l_ex.what()));
+ EventLogger::createSyncPel(
+ EventLogger::getErrorType(l_ex), types::SeverityType::Informational,
+ __FILE__, __FUNCTION__, 0, EventLogger::getErrorMsg(l_ex),
+ std::nullopt, std::nullopt, std::nullopt, std::nullopt);
return false;
}
}
@@ -319,39 +323,39 @@
const nlohmann::json& i_parsedConfigJson, const std::string& i_vpdFilePath,
const std::string& i_baseAction, const std::string& i_flagToProcess)
{
- if (i_vpdFilePath.empty() || i_parsedConfigJson.empty() ||
- i_baseAction.empty() || i_flagToProcess.empty())
- {
- logging::logMessage(
- "Invalid parameter. Abort processing of processGpioPresence tag");
- return false;
- }
-
- if (!(((i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["gpioPresence"])
- .contains("pin")) &&
- ((i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["gpioPresence"])
- .contains("value"))))
- {
- logging::logMessage(
- "Config JSON missing required information to detect presence for EEPROM " +
- i_vpdFilePath);
-
- return false;
- }
-
- // get the pin name
- const std::string& l_presencePinName =
- i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["gpioPresence"]["pin"];
-
- // get the pin value
- uint8_t l_presencePinValue = i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["gpioPresence"]["value"];
-
+ std::string l_presencePinName;
try
{
+ if (i_vpdFilePath.empty() || i_parsedConfigJson.empty() ||
+ i_baseAction.empty() || i_flagToProcess.empty())
+ {
+ throw std::runtime_error(
+ std::string(__FUNCTION__) +
+ "Invalid parameter. Abort processing of processGpioPresence tag");
+ }
+
+ if (!(((i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["gpioPresence"])
+ .contains("pin")) &&
+ ((i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["gpioPresence"])
+ .contains("value"))))
+ {
+ throw JsonException(
+ std::string(__FUNCTION__) +
+ "Config JSON missing required information to detect presence for EEPROM " +
+ i_vpdFilePath);
+ }
+
+ // get the pin name
+ l_presencePinName = i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["gpioPresence"]["pin"];
+
+ // get the pin value
+ uint8_t l_presencePinValue =
+ i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["gpioPresence"]["value"];
+
gpiod::line l_presenceLine = gpiod::find_line(l_presencePinName);
if (!l_presenceLine)
@@ -364,17 +368,27 @@
return (l_presencePinValue == l_presenceLine.get_value());
}
- catch (const std::exception& ex)
+ catch (const std::exception& l_ex)
{
+ if (EventLogger::getErrorType(l_ex) != types::ErrorType::GpioError)
+ {
+ EventLogger::createSyncPel(
+ EventLogger::getErrorType(l_ex),
+ types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
+ EventLogger::getErrorMsg(l_ex), std::nullopt, std::nullopt,
+ std::nullopt, std::nullopt);
+ return false;
+ }
+
std::string l_errMsg = "Exception on GPIO line: ";
l_errMsg += l_presencePinName;
l_errMsg += " Reason: ";
- l_errMsg += ex.what();
+ l_errMsg += l_ex.what();
l_errMsg += " File: " + i_vpdFilePath + " Pel Logged";
// ToDo -- Update Internal Rc code.
EventLogger::createAsyncPelWithInventoryCallout(
- types::ErrorType::GpioError, types::SeverityType::Informational,
+ EventLogger::getErrorType(l_ex), types::SeverityType::Informational,
{{getInventoryObjPathFromJson(i_parsedConfigJson, i_vpdFilePath),
types::CalloutPriority::High}},
std::source_location::current().file_name(),
@@ -406,39 +420,40 @@
const nlohmann::json& i_parsedConfigJson, const std::string& i_vpdFilePath,
const std::string& i_baseAction, const std::string& i_flagToProcess)
{
- if (i_vpdFilePath.empty() || i_parsedConfigJson.empty() ||
- i_baseAction.empty() || i_flagToProcess.empty())
- {
- logging::logMessage(
- "Invalid parameter. Abort processing of procesSetGpio.");
- return false;
- }
-
- if (!(((i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["setGpio"])
- .contains("pin")) &&
- ((i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["setGpio"])
- .contains("value"))))
- {
- logging::logMessage(
- "Config JSON missing required information to set gpio line for EEPROM " +
- i_vpdFilePath);
-
- return false;
- }
-
- const std::string& l_pinName = i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["setGpio"]["pin"];
-
- // Get the value to set
- uint8_t l_pinValue = i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0)[i_baseAction][i_flagToProcess]["setGpio"]["value"];
-
- logging::logMessage(
- "Setting GPIO: " + l_pinName + " to " + std::to_string(l_pinValue));
+ std::string l_pinName;
try
{
+ if (i_vpdFilePath.empty() || i_parsedConfigJson.empty() ||
+ i_baseAction.empty() || i_flagToProcess.empty())
+ {
+ throw std::runtime_error(
+ std::string(__FUNCTION__) +
+ " Invalid parameter. Abort processing of procesSetGpio.");
+ }
+
+ if (!(((i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["setGpio"])
+ .contains("pin")) &&
+ ((i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["setGpio"])
+ .contains("value"))))
+ {
+ throw JsonException(
+ std::string(__FUNCTION__) +
+ " Config JSON missing required information to set gpio line for EEPROM " +
+ i_vpdFilePath);
+ }
+
+ l_pinName = i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["setGpio"]["pin"];
+
+ // Get the value to set
+ uint8_t l_pinValue = i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0)[i_baseAction][i_flagToProcess]["setGpio"]["value"];
+
+ logging::logMessage(
+ "Setting GPIO: " + l_pinName + " to " + std::to_string(l_pinValue));
+
gpiod::line l_outputLine = gpiod::find_line(l_pinName);
if (!l_outputLine)
@@ -451,24 +466,37 @@
l_pinValue);
return true;
}
- catch (const std::exception& ex)
+ catch (const std::exception& l_ex)
{
- std::string l_errMsg = "Exception on GPIO line: ";
- l_errMsg += l_pinName;
- l_errMsg += " Reason: ";
- l_errMsg += ex.what();
- l_errMsg += " File: " + i_vpdFilePath + " Pel Logged";
+ if (EventLogger::getErrorType(l_ex) != types::ErrorType::GpioError)
+ {
+ EventLogger::createSyncPel(
+ EventLogger::getErrorType(l_ex),
+ types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
+ EventLogger::getErrorMsg(l_ex), std::nullopt, std::nullopt,
+ std::nullopt, std::nullopt);
+ }
+ else
+ {
+ std::string l_errMsg = "Exception on GPIO line: ";
+ l_errMsg += l_pinName;
+ l_errMsg += " Reason: ";
+ l_errMsg += l_ex.what();
+ l_errMsg += " File: " + i_vpdFilePath + " Pel Logged";
- // ToDo -- Update Internal RC code
- EventLogger::createAsyncPelWithInventoryCallout(
- types::ErrorType::GpioError, types::SeverityType::Informational,
- {{getInventoryObjPathFromJson(i_parsedConfigJson, i_vpdFilePath),
- types::CalloutPriority::High}},
- std::source_location::current().file_name(),
- std::source_location::current().function_name(), 0, l_errMsg,
- std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+ // ToDo -- Update Internal RC code
+ EventLogger::createAsyncPelWithInventoryCallout(
+ EventLogger::getErrorType(l_ex),
+ types::SeverityType::Informational,
+ {{getInventoryObjPathFromJson(i_parsedConfigJson,
+ i_vpdFilePath),
+ types::CalloutPriority::High}},
+ std::source_location::current().file_name(),
+ std::source_location::current().function_name(), 0, l_errMsg,
+ std::nullopt, std::nullopt, std::nullopt, std::nullopt);
- logging::logMessage(l_errMsg);
+ logging::logMessage(l_errMsg);
+ }
return false;
}
@@ -493,33 +521,43 @@
const nlohmann::json& i_parsedConfigJson, const std::string& i_action,
const std::string& i_vpdFilePath, const std::string& i_flagToProcess)
{
- if (i_flagToProcess.empty() || i_action.empty() || i_vpdFilePath.empty() ||
- !i_parsedConfigJson.contains("frus"))
+ try
{
- logging::logMessage("Invalid parameter");
- return false;
+ if (i_flagToProcess.empty() || i_action.empty() ||
+ i_vpdFilePath.empty() || !i_parsedConfigJson.contains("frus"))
+ {
+ throw std::runtime_error(
+ std::string(__FUNCTION__) + " Invalid parameter");
+ }
+
+ if (!i_parsedConfigJson["frus"].contains(i_vpdFilePath))
+ {
+ throw JsonException(std::string(__FUNCTION__) + " File path: " +
+ i_vpdFilePath + " not found in JSON");
+ }
+
+ if (!i_parsedConfigJson["frus"][i_vpdFilePath].at(0).contains(i_action))
+ {
+ throw JsonException(
+ std::string(__FUNCTION__) + " Action [" + i_action +
+ "] not defined for file path:" + i_vpdFilePath);
+ }
+
+ if (!(i_parsedConfigJson["frus"][i_vpdFilePath].at(0))[i_action]
+ .contains(i_flagToProcess))
+ {
+ throw JsonException(
+ std::string(__FUNCTION__) + "Config JSON missing flag [" +
+ i_flagToProcess +
+ "] to execute action for path = " + i_vpdFilePath);
+ }
}
-
- if (!i_parsedConfigJson["frus"].contains(i_vpdFilePath))
+ catch (const std::exception& l_ex)
{
- logging::logMessage(
- "File path: " + i_vpdFilePath + " not found in JSON");
- return false;
- }
-
- if (!i_parsedConfigJson["frus"][i_vpdFilePath].at(0).contains(i_action))
- {
- logging::logMessage("Action [" + i_action +
- "] not defined for file path:" + i_vpdFilePath);
- return false;
- }
-
- if (!(i_parsedConfigJson["frus"][i_vpdFilePath].at(0))[i_action].contains(
- i_flagToProcess))
- {
- logging::logMessage("Config JSON missing flag [" + i_flagToProcess +
- "] to execute action for path = " + i_vpdFilePath);
-
+ EventLogger::createSyncPel(
+ EventLogger::getErrorType(l_ex), types::SeverityType::Informational,
+ __FILE__, __FUNCTION__, 0, EventLogger::getErrorMsg(l_ex),
+ std::nullopt, std::nullopt, std::nullopt, std::nullopt);
return false;
}
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index d54b317..ac104bb 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1371,24 +1371,30 @@
{
throw std::runtime_error(
std::string(__FUNCTION__) +
- "Empty VPD file path passed. Abort processing");
+ " Empty VPD file path passed. Abort processing");
}
+ bool isPreActionRequired = false;
if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath,
"preAction", "collection"))
{
+ isPreActionRequired = true;
if (!processPreAction(i_vpdFilePath, "collection"))
{
throw std::runtime_error(
- std::string(__FUNCTION__) + "Pre-Action failed");
+ std::string(__FUNCTION__) + " Pre-Action failed");
}
}
if (!std::filesystem::exists(i_vpdFilePath))
{
- throw std::runtime_error(
- std::string(__FUNCTION__) + "Could not find file path " +
- i_vpdFilePath + "Skipping parser trigger for the EEPROM");
+ if (isPreActionRequired)
+ {
+ throw std::runtime_error(
+ std::string(__FUNCTION__) + " Could not find file path " +
+ i_vpdFilePath + "Skipping parser trigger for the EEPROM");
+ }
+ return types::VPDMapVariant{};
}
std::shared_ptr<Parser> vpdParser =
@@ -1474,16 +1480,23 @@
}
const types::VPDMapVariant& parsedVpdMap = parseVpdFile(i_vpdFilePath);
-
- types::ObjectMap objectInterfaceMap;
- populateDbus(parsedVpdMap, objectInterfaceMap, i_vpdFilePath);
-
- // Notify PIM
- if (!dbusUtility::callPIM(move(objectInterfaceMap)))
+ if (!std::holds_alternative<std::monostate>(parsedVpdMap))
{
- throw std::runtime_error(
- std::string(__FUNCTION__) +
- "Call to PIM failed while publishing VPD.");
+ types::ObjectMap objectInterfaceMap;
+ populateDbus(parsedVpdMap, objectInterfaceMap, i_vpdFilePath);
+
+ // Notify PIM
+ if (!dbusUtility::callPIM(move(objectInterfaceMap)))
+ {
+ throw std::runtime_error(
+ std::string(__FUNCTION__) +
+ "Call to PIM failed while publishing VPD.");
+ }
+ }
+ else
+ {
+ logging::logMessage("Empty parsedVpdMap recieved for path [" +
+ i_vpdFilePath + "]. Check PEL for reason.");
}
}
catch (const std::exception& ex)
@@ -1521,7 +1534,7 @@
}
EventLogger::createSyncPel(
- EventLogger::getErrorType(ex), types::SeverityType::Critical,
+ EventLogger::getErrorType(ex), types::SeverityType::Informational,
__FILE__, __FUNCTION__, 0, EventLogger::getErrorMsg(ex),
std::nullopt, std::nullopt, std::nullopt, std::nullopt);