Refactor insert or merge API exception handling
This commit refactors vpd specific utility API used to insert or merge
property map in interface map ,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 removes unnecessary declaration of this API in
worker.hpp
Test:
```
- Install bitbaked image on Everest
- Clear persistent PIM data on filesystem, restart PIM and then
vpd-manager services
- Check all interfaces under PIM like
LocationCode,Item,OperationalStatus,etc. are populated properly
```
Change-Id: Ie13882c0697d691f0593765f6f4dad5ac5eadea2
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 4a2a741..6b2f685 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -223,36 +223,42 @@
* created. If the property present in propertymap already exist in the
* InterfaceMap, then the new property value is ignored.
*
- * @param[in,out] map - Interface map.
- * @param[in] interface - Interface to be processed.
- * @param[in] propertyMap - new property map that needs to be emplaced.
+ * @param[in,out] io_map - Interface map.
+ * @param[in] i_interface - Interface to be processed.
+ * @param[in] i_propertyMap - new property map that needs to be emplaced.
+ *
+ * @return On success returns 0, otherwise returns -1.
*/
-inline void insertOrMerge(types::InterfaceMap& map,
- const std::string& interface,
- types::PropertyMap&& propertyMap)
+inline int insertOrMerge(types::InterfaceMap& io_map,
+ const std::string& i_interface,
+ types::PropertyMap&& i_propertyMap) noexcept
{
- if (map.find(interface) != map.end())
+ int l_rc{constants::FAILURE};
+ try
{
- try
+ if (io_map.find(i_interface) != io_map.end())
{
- auto& prop = map.at(interface);
- std::for_each(propertyMap.begin(), propertyMap.end(),
- [&prop](auto l_keyValue) {
- prop[l_keyValue.first] = l_keyValue.second;
+ auto& l_prop = io_map.at(i_interface);
+ std::for_each(i_propertyMap.begin(), i_propertyMap.end(),
+ [&l_prop](auto l_keyValue) {
+ l_prop[l_keyValue.first] = l_keyValue.second;
});
}
- catch (const std::exception& l_ex)
+ else
{
- // ToDo:: Log PEL
- logging::logMessage(
- "Inserting properties into interface[" + interface +
- "] map is failed, reason: " + std::string(l_ex.what()));
+ io_map.emplace(i_interface, i_propertyMap);
}
+
+ l_rc = constants::SUCCESS;
}
- else
+ catch (const std::exception& l_ex)
{
- map.emplace(interface, propertyMap);
+ // ToDo:: Log PEL
+ logging::logMessage(
+ "Inserting properties into interface[" + i_interface +
+ "] map failed, reason: " + std::string(l_ex.what()));
}
+ return l_rc;
}
/**
diff --git a/vpd-manager/include/worker.hpp b/vpd-manager/include/worker.hpp
index 68ebb3a..8aa5909 100644
--- a/vpd-manager/include/worker.hpp
+++ b/vpd-manager/include/worker.hpp
@@ -328,25 +328,6 @@
const types::VPDMapVariant& parsedVpdMap);
/**
- * @brief Helper function to insert or merge in map.
- *
- * This method checks in the given inventory::InterfaceMap if the given
- * interface key is existing or not. If the interface key already exists,
- * given property map is inserted into it. If the key does'nt exist then
- * given interface and property map pair is newly created. If the property
- * present in propertymap already exist in the InterfaceMap, then the new
- * property value is ignored.
- *
- * @param[in,out] interfaceMap - map object of type inventory::InterfaceMap
- * only.
- * @param[in] interface - Interface name.
- * @param[in] property - new property map that needs to be emplaced.
- */
- void insertOrMerge(types::InterfaceMap& interfaceMap,
- const std::string& interface,
- types::PropertyMap&& property);
-
- /**
* @brief Check if the given CPU is an IO only chip.
*
* The CPU is termed as IO, whose all of the cores are bad and can never be