LogService: Sort dump entries collection by Id
Ordering by ID (represented internally as the last part of the D-Bus
object path, after the rightmost slash) is done for human readability,
but please note that Redfish clients should not be written in a way
that assumes a particular ordering of entries in a collection.
Without this change, entries are presented in the collection in
whatever order entries are returned by the D-Bus method
GetManagedObjects(), called in getDumpEntryCollection().
The effect of this change is that entries are presented in
chronological order (by ID) with the earliest entry appearing first.
Testing:
1. Prerequisite: Fixed createDump() locally, similar to
https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/38954
2. Created 12 BMC dump entries by repeatedly calling
CollectDiagnosticData:
curl -k -H "X-Auth-Token: $token" -X POST http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData -d '{"DiagnosticDataType":"Manager", "OEMDiagnosticDataType":"BMC"}'
3. Retrieved BMC dump entries collection and verified that entries were
sorted by ID (1,2,3,4,5,6,7,8,9,10,11,12):
curl -k -H "X-Auth-Token: $token" -X GET http://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Entries
Signed-off-by: Claire Weinan <cweinan@google.com>
Change-Id: I99f96dd6679163cea443353ad0e4c8c750cd4330
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index d31602c..5980071 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -363,6 +363,12 @@
std::string(boost::algorithm::to_lower_copy(dumpType)) +
"/entry/";
+ std::sort(resp.begin(), resp.end(),
+ [](const auto& l, const auto& r) {
+ return AlphanumLess<std::string>()(
+ l.first.filename(), r.first.filename());
+ });
+
for (auto& object : resp)
{
if (object.first.str.find(dumpEntryPath) == std::string::npos)