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());
}