Return proper redfish errors for createDump call
Currently, only internal server error will be returned to a client when
there is a create dump dbus call failure in the backend, irrespective
of the error that's returned by the phosphor-dump-manager.
This change will send a proper error response to the user based on the
host state.
Tested By:
curl -k -H "X-Auth-Token: $bmc_token" -X POST https://${bmc}
/redfish/v1/Systems/system/LogServices/Dump/Actions/
LogService.CollectDiagnosticData -d
'{"DiagnosticDataType":"OEM", "OEMDiagnosticDataType":"Resource_vps_str"}'
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The request could not be performed because the resource is in standby.",
"MessageArgs": [],
"MessageId": "Base.1.8.1.ResourceInStandby",
"MessageSeverity": "Critical",
"Resolution": "Ensure that the resource is in the correct power state and resubmit the request."
}
],
"code": "Base.1.8.1.ResourceInStandby",
"message": "The request could not be performed because the resource is in standby."
}
}
curl -k -H "X-Auth-Token: $bmc_token" -X POST
https://${bmc}/redfish/v1/Managers/bmc/LogServices/
Dump/Actions/LogService.CollectDiagnosticData -d '{"DiagnosticDataType":"Manager"}'
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The operation failed because the service at /redfish/v1/Managers/bmc/LogServices/Dump/ is disabled and cannot accept requests.",
"MessageArgs": [
"/redfish/v1/Managers/bmc/LogServices/Dump/"
],
"MessageId": "Base.1.11.0.ServiceDisabled",
"MessageSeverity": "Warning",
"Resolution": "Enable the service and resubmit the request if the operation failed."
}
],
"code": "Base.1.11.0.ServiceDisabled",
"message": "The operation failed because the service at /redfish/v1/Managers/bmc/LogServices/Dump/ is disabled and cannot accept requests."
}
}
Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ica087e4cac2beeded896f0c83c9481f8164d2c62
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 7d511e2..7740014 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -725,6 +725,7 @@
messages::internalError(asyncResp->res);
return;
}
+ dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/";
}
else if (dumpType == "BMC")
{
@@ -743,15 +744,60 @@
messages::internalError(asyncResp->res);
return;
}
+ dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/";
+ }
+ else
+ {
+ BMCWEB_LOG_ERROR << "CreateDump failed. Unknown dump type";
+ messages::internalError(asyncResp->res);
+ return;
}
crow::connections::systemBus->async_method_call(
[asyncResp, payload(task::Payload(req)), dumpPath,
dumpType](const boost::system::error_code ec,
+ const sdbusplus::message::message& msg,
const uint32_t& dumpId) mutable {
if (ec)
{
BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
+ const sd_bus_error* dbusError = msg.get_error();
+ if (dbusError == nullptr)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ BMCWEB_LOG_ERROR << "CreateDump DBus error: " << dbusError->name
+ << " and error msg: " << dbusError->message;
+ if (std::string_view(
+ "xyz.openbmc_project.Common.Error.NotAllowed") ==
+ dbusError->name)
+ {
+ messages::resourceInStandby(asyncResp->res);
+ return;
+ }
+ if (std::string_view(
+ "xyz.openbmc_project.Dump.Create.Error.Disabled") ==
+ dbusError->name)
+ {
+ messages::serviceDisabled(asyncResp->res, dumpPath);
+ return;
+ }
+ if (std::string_view(
+ "xyz.openbmc_project.Common.Error.Unavailable") ==
+ dbusError->name)
+ {
+ messages::resourceInUse(asyncResp->res);
+ return;
+ }
+ // Other Dbus errors such as:
+ // xyz.openbmc_project.Common.Error.InvalidArgument &
+ // org.freedesktop.DBus.Error.InvalidArgs are all related to
+ // the dbus call that is made here in the bmcweb
+ // implementation and has nothing to do with the client's
+ // input in the request. Hence, returning internal error
+ // back to the client.
messages::internalError(asyncResp->res);
return;
}