Show only "Completed" dump entries in Redfish resp

In the current implementation, the dumps whose status
remain "InProgress" were also displayed when a GET
request on dump entries is fired. That is, when the user
initiates a dump creation, and immediately does a GET on
dump entries, the dump that is now created will also be
displayed with size 0 and an invalid date in the redfish
response as below, until the status becomes "Completed"

{
  "@odata.id": "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/7",
  "@odata.type": "#LogEntry.v1_7_0.LogEntry",
  "AdditionalDataSizeBytes": 0,
  "AdditionalDataURI": "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/7/attachment",
  "Created": "1970-01-01T00:00:00+00:00",
  "DiagnosticDataType": "Manager",
  "EntryType": "Event",
  "Id": "7",
  "Name": "BMC Dump Entry"
}

This commit contains changes that will avoid displaying
the incomplete dumps.

Tested By:

* GET https://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries/12
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The requested resource of type BMC dump named 12 was not found.",
        "MessageArgs": [
          "BMC dump",
          "12"
        ],
        "MessageId": "Base.1.8.1.ResourceNotFound",
        "MessageSeverity": "Critical",
        "Resolution": "Provide a valid resource identifier and resubmit the request."
      }
    ],
    "code": "Base.1.8.1.ResourceNotFound",
    "message": "The requested resource of type BMC dump named 12 was not found."
  }
}

* GET https://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries/ -- This also
avoids displaying incomplete dump entries.

Redfish Validator passed.

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ifc5e1773cde0c4c4288e8ebbcdf87b2ec480af55
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 3b9069f..943e08e 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -421,8 +421,8 @@
                 }
                 std::time_t timestamp;
                 uint64_t size = 0;
-                entriesArray.push_back({});
-                nlohmann::json& thisEntry = entriesArray.back();
+                std::string dumpStatus;
+                nlohmann::json thisEntry;
 
                 std::string entryID = object.first.filename();
                 if (entryID.empty())
@@ -432,7 +432,26 @@
 
                 for (auto& interfaceMap : object.second)
                 {
-                    if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
+                    if (interfaceMap.first ==
+                        "xyz.openbmc_project.Common.Progress")
+                    {
+                        for (auto& propertyMap : interfaceMap.second)
+                        {
+                            if (propertyMap.first == "Status")
+                            {
+                                auto status = std::get_if<std::string>(
+                                    &propertyMap.second);
+                                if (status == nullptr)
+                                {
+                                    messages::internalError(asyncResp->res);
+                                    break;
+                                }
+                                dumpStatus = *status;
+                            }
+                        }
+                    }
+                    else if (interfaceMap.first ==
+                             "xyz.openbmc_project.Dump.Entry")
                     {
 
                         for (auto& propertyMap : interfaceMap.second)
@@ -474,6 +493,14 @@
                     }
                 }
 
+                if (dumpStatus != "xyz.openbmc_project.Common.Progress."
+                                  "OperationStatus.Completed" &&
+                    !dumpStatus.empty())
+                {
+                    // Dump status is not Complete, no need to enumerate
+                    continue;
+                }
+
                 thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry";
                 thisEntry["@odata.id"] = dumpPath + entryID;
                 thisEntry["Id"] = entryID;
@@ -498,6 +525,7 @@
                         "/redfish/v1/Systems/system/LogServices/Dump/Entries/" +
                         entryID + "/attachment";
                 }
+                entriesArray.push_back(std::move(thisEntry));
             }
             asyncResp->res.jsonValue["Members@odata.count"] =
                 entriesArray.size();
@@ -552,10 +580,30 @@
                 foundDumpEntry = true;
                 std::time_t timestamp;
                 uint64_t size = 0;
+                std::string dumpStatus;
 
                 for (auto& interfaceMap : objectPath.second)
                 {
-                    if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
+                    if (interfaceMap.first ==
+                        "xyz.openbmc_project.Common.Progress")
+                    {
+                        for (auto& propertyMap : interfaceMap.second)
+                        {
+                            if (propertyMap.first == "Status")
+                            {
+                                auto status = std::get_if<std::string>(
+                                    &propertyMap.second);
+                                if (status == nullptr)
+                                {
+                                    messages::internalError(asyncResp->res);
+                                    break;
+                                }
+                                dumpStatus = *status;
+                            }
+                        }
+                    }
+                    else if (interfaceMap.first ==
+                             "xyz.openbmc_project.Dump.Entry")
                     {
                         for (auto& propertyMap : interfaceMap.second)
                         {
@@ -595,6 +643,17 @@
                     }
                 }
 
+                if (dumpStatus != "xyz.openbmc_project.Common.Progress."
+                                  "OperationStatus.Completed" &&
+                    !dumpStatus.empty())
+                {
+                    // Dump status is not Complete
+                    // return not found until status is changed to Completed
+                    messages::resourceNotFound(asyncResp->res,
+                                               dumpType + " dump", entryID);
+                    return;
+                }
+
                 asyncResp->res.jsonValue["@odata.type"] =
                     "#LogEntry.v1_7_0.LogEntry";
                 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;