Update FRU status on recollection

Some FRUs qualifies for recollection at standby. Based on their
recollection status, clear VPD and reset their functional and
present property if required.

Change-Id: Iaf8f5b783c71c18cb36639846ab791baad989723
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/manager.cpp b/vpd-manager/manager.cpp
index 156bbcc..1e7bab9 100644
--- a/vpd-manager/manager.cpp
+++ b/vpd-manager/manager.cpp
@@ -560,41 +560,6 @@
             singleFru["inventoryPath"]
                 .get_ref<const nlohmann::json::string_t&>();
 
-        // clear VPD of FRU before re-collection.
-        inventory::InterfaceMap interfacesPropMap;
-        clearVpdOnRemoval(INVENTORY_PATH + inventoryPath, interfacesPropMap);
-
-        inventory::ObjectMap objectMap;
-        objectMap.emplace(inventoryPath, move(interfacesPropMap));
-
-        common::utility::callPIM(move(objectMap));
-
-        // check if any subtree exist under the parent path. If so clear VPD for
-        // them as well.
-        std::vector<std::string> interfaceList{
-            "xyz.openbmc_project.Inventory.Item"};
-        MapperResponse subTree = getObjectSubtreeForInterfaces(
-            INVENTORY_PATH + inventoryPath, 0, interfaceList);
-
-        for (auto [objectPath, serviceInterfaceMap] : subTree)
-        {
-            interfacesPropMap.clear();
-            clearVpdOnRemoval(objectPath, interfacesPropMap);
-
-            std::string subTreeObjPath{objectPath};
-            // Strip any inventory prefix in path
-            if (subTreeObjPath.find(INVENTORY_PATH) == 0)
-            {
-                subTreeObjPath =
-                    subTreeObjPath.substr(sizeof(INVENTORY_PATH) - 1);
-            }
-
-            objectMap.clear();
-            objectMap.emplace(subTreeObjPath, move(interfacesPropMap));
-
-            common::utility::callPIM(move(objectMap));
-        }
-
         bool prePostActionRequired = false;
 
         if ((jsonFile["frus"][item].at(0)).find("preAction") !=
@@ -612,6 +577,9 @@
                         "Pre-Action execution failed for the FRU",
                         entry("ERROR=%s",
                               ("Inventory path: " + inventoryPath).c_str()));
+
+                    // As recollection failed delete FRU data.
+                    deleteFRUVPD(inventoryPath);
                     continue;
                 }
             }
@@ -622,6 +590,10 @@
                 additionalData.emplace("DESCRIPTION", e.what());
                 createPEL(additionalData, PelSeverity::WARNING,
                           errIntfForGpioError, sdBus);
+
+                // As recollection failed delete FRU data.
+                deleteFRUVPD(inventoryPath);
+
                 continue;
             }
             prePostActionRequired = true;
@@ -659,6 +631,9 @@
                     {
                         // If not, then take failure postAction
                         executePostFailAction(jsonFile, item);
+
+                        // As recollection failed delete FRU data.
+                        deleteFRUVPD(inventoryPath);
                     }
                     catch (const GpioException& e)
                     {
@@ -666,6 +641,9 @@
                         additionalData.emplace("DESCRIPTION", e.what());
                         createPEL(additionalData, PelSeverity::WARNING,
                                   errIntfForGpioError, sdBus);
+
+                        // As recollection failed delete FRU data.
+                        deleteFRUVPD(inventoryPath);
                     }
                 }
                 else
@@ -897,32 +875,31 @@
         // check if we have cxp-port populated for the given object path.
         std::vector<std::string> interfaceList{
             "xyz.openbmc_project.State.Decorator.OperationalStatus"};
-        MapperResponse subTree =
-            getObjectSubtreeForInterfaces(path, 0, interfaceList);
+        MapperResponse subTree = getObjectSubtreeForInterfaces(
+            INVENTORY_PATH + objPath, 0, interfaceList);
 
         if (subTree.size() != 0)
         {
             for (auto [objectPath, serviceInterfaceMap] : subTree)
             {
                 std::string subTreeObjPath{objectPath};
-                if (subTreeObjPath.find("cxp_top") != std::string::npos ||
-                    subTreeObjPath.find("cxp_bot") != std::string::npos)
+
+                // Strip any inventory prefix in path
+                if (subTreeObjPath.find(INVENTORY_PATH) == 0)
                 {
-                    // Strip any inventory prefix in path
-                    if (subTreeObjPath.find(INVENTORY_PATH) == 0)
-                    {
-                        subTreeObjPath =
-                            subTreeObjPath.substr(sizeof(INVENTORY_PATH) - 1);
-                    }
-
-                    inventory::ObjectMap objectMap{
-                        {subTreeObjPath,
-                         {{"xyz.openbmc_project.State.Decorator.OperationalStatus",
-                           {{"Functional", true}}}}}};
-
-                    // objectMap.emplace(objectPath, move(interfaceMap));
-                    common::utility::callPIM(move(objectMap));
+                    subTreeObjPath =
+                        subTreeObjPath.substr(sizeof(INVENTORY_PATH) - 1);
                 }
+
+                inventory::ObjectMap objectMap{
+                    {subTreeObjPath,
+                     {{"xyz.openbmc_project.State.Decorator.OperationalStatus",
+                       {{"Functional", true}}},
+                      {"xyz.openbmc_project.Inventory.Item",
+                       {{"Present", false}}}}}};
+
+                // objectMap.emplace(objectPath, move(interfaceMap));
+                common::utility::callPIM(move(objectMap));
             }
         }