Refactor get keyword value API exception handling
This commit refactors vpd specific utility API used to read value of a
keyword,in order to handle any exceptions thrown by it locally. All
utility methods should handle exceptions locally and log a journal log
in case of failure. The caller of the utility APIs should check the
return value to detect success/failure.
This commit also changes the caller of this API throughout the repo, in
order to check the return value.
Test:
```
- Install bitbaked image on Everest system
- After BMC boots, BMC should reach Ready state
- Check vpd-manager service status, should be active(running)
- Check no restarts in vpd-manager service
- Check vpd-manager "CollectionStatus" = "Completed"
- Check extra interfaces are processed properly
- Check backup restore working properly
```
Change-Id: I965313f512553ed5d39373dd871754e1a8fed5f3
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/src/backup_restore.cpp b/vpd-manager/src/backup_restore.cpp
index 9de43b9..e275ea2 100644
--- a/vpd-manager/src/backup_restore.cpp
+++ b/vpd-manager/src/backup_restore.cpp
@@ -244,8 +244,16 @@
std::string l_srcStrValue;
if (!io_srcVpdMap.empty())
{
- vpdSpecificUtility::getKwVal(io_srcVpdMap.at(l_srcRecordName),
- l_srcKeywordName, l_srcStrValue);
+ l_srcStrValue = vpdSpecificUtility::getKwVal(
+ io_srcVpdMap.at(l_srcRecordName), l_srcKeywordName);
+
+ if (l_srcStrValue.empty())
+ {
+ std::runtime_error(
+ std::string("Failed to get value for keyword [") +
+ l_srcKeywordName + std::string("]"));
+ }
+
l_srcBinaryValue =
types::BinaryVector(l_srcStrValue.begin(), l_srcStrValue.end());
}
@@ -268,8 +276,16 @@
std::string l_dstStrValue;
if (!io_dstVpdMap.empty())
{
- vpdSpecificUtility::getKwVal(io_dstVpdMap.at(l_dstRecordName),
- l_dstKeywordName, l_dstStrValue);
+ l_dstStrValue = vpdSpecificUtility::getKwVal(
+ io_dstVpdMap.at(l_dstRecordName), l_dstKeywordName);
+
+ if (l_dstStrValue.empty())
+ {
+ std::runtime_error(
+ std::string("Failed to get value for keyword [") +
+ l_dstKeywordName + std::string("]"));
+ }
+
l_dstBinaryValue =
types::BinaryVector(l_dstStrValue.begin(), l_dstStrValue.end());
}
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 1529924..4bd61bf 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -931,9 +931,9 @@
return;
}
- std::string pgKeywordValue;
- vpdSpecificUtility::getKwVal(itrToRec->second, "PG",
- pgKeywordValue);
+ const std::string pgKeywordValue{
+ vpdSpecificUtility::getKwVal(itrToRec->second, "PG")};
+
if (!pgKeywordValue.empty())
{
if (isCPUIOGoodOnly(pgKeywordValue))
@@ -942,6 +942,10 @@
["PrettyName"] = "IO Module";
}
}
+ else
+ {
+ throw std::runtime_error("Failed to get value for keyword PG");
+ }
}
}
}
@@ -999,8 +1003,9 @@
return false;
}
- std::string ccinFromVpd;
- vpdSpecificUtility::getKwVal(itrToRec->second, "CC", ccinFromVpd);
+ std::string ccinFromVpd{
+ vpdSpecificUtility::getKwVal(itrToRec->second, "CC")};
+
if (ccinFromVpd.empty())
{
return false;
@@ -1187,13 +1192,27 @@
auto l_itrToVsys = (*l_parsedVpdMap).find(constants::recVSYS);
if (l_itrToVsys != (*l_parsedVpdMap).end())
{
- std::string l_tmKwdValue;
- vpdSpecificUtility::getKwVal(l_itrToVsys->second, constants::kwdTM,
- l_tmKwdValue);
+ const std::string l_tmKwdValue{vpdSpecificUtility::getKwVal(
+ l_itrToVsys->second, constants::kwdTM)};
- std::string l_seKwdValue;
- vpdSpecificUtility::getKwVal(l_itrToVsys->second, constants::kwdSE,
- l_seKwdValue);
+ if (l_tmKwdValue.empty())
+ {
+ throw std::runtime_error(
+ std::string("Failed to get value for keyword [") +
+ constants::kwdTM +
+ std::string("] while creating Asset tag."));
+ }
+
+ const std::string l_seKwdValue{vpdSpecificUtility::getKwVal(
+ l_itrToVsys->second, constants::kwdSE)};
+
+ if (l_seKwdValue.empty())
+ {
+ throw std::runtime_error(
+ std::string("Failed to get value for keyword [") +
+ constants::kwdSE +
+ std::string("] while creating Asset tag."));
+ }
l_assetTag = std::string{"Server-"} + l_tmKwdValue +
std::string{"-"} + l_seKwdValue;