log_services: Fix Severity Empty string found issue when running Redfish Service Validator
Symptom:
When running Redfish Service Validator, we found that Severity Empty string issue except first post code in PostCodesEntry.
*** /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1
Regetting resource from URI /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-1
Type (#LogEntry.v1_4_0.LogEntry), GET SUCCESS (time: 0)
PASS
*** /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-2
Regetting resource from URI /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-2
Type (#LogEntry.v1_4_0.LogEntry), GET SUCCESS (time: 0)
Severity: Empty string found - Services should omit properties if not supported
Severity: Invalid Enum value '' found, expected ['OK', 'Warning', 'Critical']
FAIL...
Root cause:
In fillPostCodeEntry(), this statement "severity = message->severity" only be executed once.
And another statement {"Severity", std::move(severity)} in the end of this function will clear severity string to null after calling std::move() standard function.
Thus, only first post code Severity is 'OK', but the others are NULL.
Solution:
Move this statement "severity = message->severity" to for loop in fillPostCodeEntry() then all post codes will be recorded with correct severity string 'OK'.
Tested:
Passed the Redfish Service Validator and verified "Severity": "OK" in /redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-2
{
"@odata.context": "/redfish/v1/$metadata#LogEntry.LogEntry",
"@odata.id": "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/B1-2",
"@odata.type": "#LogEntry.v1_4_0.LogEntry",
"Created": "2020-04-27T01:48:10+00:00",
"EntryType": "Event",
"Id": "B1-2",
"Message": "Boot Count: 1: TS Offset: 0.0046; POST Code: 0x02",
"MessageArgs": [
"1",
"0.0046",
"0x02"
],
"MessageId": "OpenBMC.0.1.BIOSPOSTCode",
"Name": "POST Code Log Entry",
"Severity": "OK"
}
Signed-off-by: Tim Lee <timlee660101@gmail.com>
Change-Id: Ibfccfa47cfe8e0f58e7f24650871edda5d248674
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 2284e23..3f10725 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -2620,11 +2620,6 @@
// Get the Message from the MessageRegistry
const message_registries::Message *message =
message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
- std::string severity;
- if (message != nullptr)
- {
- severity = message->severity;
- }
uint64_t currentCodeIndex = 0;
nlohmann::json &logEntryArray = aResp->res.jsonValue["Members"];
@@ -2710,6 +2705,13 @@
}
}
+ // Get Severity template from message registry
+ std::string severity;
+ if (message != nullptr)
+ {
+ severity = message->severity;
+ }
+
// add to AsyncResp
logEntryArray.push_back({});
nlohmann::json &bmcLogEntry = logEntryArray.back();