LogService: Fix setUpRedfishRoute() for dumps

There's an inconsistency between how setUpRedfishRoute() is called for
BMC dump vs. System dump. In requestRoutesSystemDumpEntry(),
setUpRedfishRoute() is called within getDumpEntryById, while in
requestRoutesBMCDumpEntry() setUpRedfishRoute() is called before
getDumpEntryById() as well as within getDumpEntryById(). The
inconsistency was introduced in
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/52393/20/redfish-core/lib/log_services.hpp
and seems to be accidental.

This change removes setUpRedfishRoute() from getDumpEntryById() and
makes requestRoutesSystemDumpEntry() call setUpRedfishRoute() before
calling getDumpEntryById(). In addition to fixing the inconsistency,
this change prevents setUpRedfishRoute() from being called twice for
BMC dump.

Tested:
After creating System dump entry, retrieved it successfully with
./curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Systems/system/LogServices/Dump/Entries/1

Saw “setup redfish route” message in journalctl:
bmcweb[19717]: (2022-06-13 16:42:52) [DEBUG "routing.hpp":1294] Matched rule '/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/' 2 / 4
bmcweb[19717]: (2022-06-13 16:42:52) [DEBUG "query.hpp":19] setup redfish route

Received the expected error when adding a query parameter for a
non-collection resource, which indicates setUpRedfishRoute() had been
called:
./curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Systems/system/LogServices/Dump/Entries/1?\$skip=1
{
  "@odata.id": "/redfish/v1/Systems/system/LogServices/Dump/Entries/1",
  "@odata.type": "#LogEntry.v1_8_0.LogEntry",
  "AdditionalDataSizeBytes": 0,
  "AdditionalDataURI": "/redfish/v1/Systems/system/LogServices/Dump/Entries/1/attachment",
  "Created": "1970-01-01T00:27:35.135000+00:00",
  "DiagnosticDataType": "OEM",
  "EntryType": "Event",
  "Id": "1",
  "Name": "System Dump Entry",
  "OEMDiagnosticDataType": "System",
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "Querying is not supported on the requested resource.",
        "MessageArgs": [],
        "MessageId": "Base.1.11.0.QueryNotSupportedOnResource",
        "MessageSeverity": "Warning",
        "Resolution": "Remove the query parameters and resubmit the request if the operation failed."
      }
    ],
    "code": "Base.1.11.0.QueryNotSupportedOnResource",
    "message": "Querying is not supported on the requested resource."
  }
}

Repeated the same testing for a BMC dump entry.

Signed-off-by: Claire Weinan <cweinan@google.com>
Change-Id: I41ea93bfc6971a775241a368491e4615295cc4db
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 3572cca..4f6e85b 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -485,14 +485,9 @@
 }
 
 inline void
-    getDumpEntryById(crow::App& app, const crow::Request& req,
-                     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+    getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                      const std::string& entryID, const std::string& dumpType)
 {
-    if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
-    {
-        return;
-    }
     std::string dumpPath;
     if (dumpType == "BMC")
     {
@@ -2347,8 +2342,7 @@
         {
             return;
         }
-
-        getDumpEntryById(app, req, asyncResp, param, "BMC");
+        getDumpEntryById(asyncResp, param, "BMC");
         });
     BMCWEB_ROUTE(app,
                  "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/")
@@ -2473,7 +2467,11 @@
             [&app](const crow::Request& req,
                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                    const std::string& param) {
-        getDumpEntryById(app, req, asyncResp, param, "System");
+        if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
+        {
+            return;
+        }
+        getDumpEntryById(asyncResp, param, "System");
         });
 
     BMCWEB_ROUTE(app,