Remove copies from log services and virtual media
Both of these entries make complete copies of the Request object.
Following the pattern in the prior commit, move these to more modern
patterns.
For log service, this simply means constructing a payload object
earlier.
For virtual media, it means doing the readJson call and parameter
validation much earlier, which generally is the pattern we should strive
for, validating and unpacking the structs in the first scope, then
dealing with them as structures. To do this, this commit also creates a
secondary struct to store the param data in to make the lambdas cleaner.
Tested:
From Ashmitha
POST https://${bmc}/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData -d '{"DiagnosticDataType":"Manager"}'
{
"@odata.id": "/redfish/v1/TaskService/Tasks/0",
"@odata.type": "#Task.v1_4_3.Task",
"Id": "0",
"TaskState": "Running",
"TaskStatus": "OK"
}
-----------------------------------------------------------------
On task completion:
GET https://${bmc}/redfish/v1/TaskService/Tasks/0
{
"@odata.id": "/redfish/v1/TaskService/Tasks/0",
"@odata.type": "#Task.v1_4_3.Task",
"EndTime": "2021-12-03T13:40:58+00:00",
"Id": "0",
"Messages": [
{
"@odata.type": "#Message.v1_0_0.Message",
"Message": "The task with id 0 has started.",
"MessageArgs": [
"0"
],
"MessageId": "TaskEvent.1.0.1.TaskStarted",
"Resolution": "None.",
"Severity": "OK"
},
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "Successfully Completed Request",
"MessageArgs": [],
"MessageId": "Base.1.8.1.Success",
"MessageSeverity": "OK",
"Resolution": "None"
}
],
"Name": "Task 0",
"Payload": {
"HttpHeaders": [
"Host: 9.3.29.238",
"User-Agent: curl/7.71.1",
"Accept: */*",
"Content-Length: 32",
"Location: /redfish/v1/Managers/bmc/LogServices/Dump/Entries/32"
],
"HttpOperation": "POST",
"JsonBody": "{\n \"DiagnosticDataType\": \"Manager\"\n}",
"TargetUri": "/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData"
},
"PercentComplete": 0,
"StartTime": "2021-12-03T13:38:20+00:00",
"TaskMonitor": "/redfish/v1/TaskService/Tasks/0/Monitor",
"TaskState": "Completed",
"TaskStatus": "OK"
}
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I178a3a7a7b27dfd34ec50a06398ac243a9d4ab67
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 64f9a4c..34c1c4b 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -775,6 +775,17 @@
}
}
+struct InsertMediaActionParams
+{
+ std::string imageUrl;
+ std::optional<std::string> userName;
+ std::optional<std::string> password;
+ std::optional<std::string> transferMethod;
+ std::optional<std::string> transferProtocolType;
+ std::optional<bool> writeProtected = true;
+ std::optional<bool> inserted;
+};
+
inline void requestNBDVirtualMediaRoutes(App& app)
{
BMCWEB_ROUTE(
@@ -792,11 +803,37 @@
return;
}
+ InsertMediaActionParams actionParams;
+
+ // Read obligatory parameters (url of
+ // image)
+ if (!json_util::readJson(
+ req, asyncResp->res, "Image", actionParams.imageUrl,
+ "WriteProtected", actionParams.writeProtected,
+ "UserName", actionParams.userName, "Password",
+ actionParams.password, "Inserted",
+ actionParams.inserted, "TransferMethod",
+ actionParams.transferMethod, "TransferProtocolType",
+ actionParams.transferProtocolType))
+ {
+ BMCWEB_LOG_DEBUG << "Image is not provided";
+ return;
+ }
+
+ bool paramsValid = validateParams(
+ asyncResp->res, actionParams.imageUrl,
+ actionParams.inserted, actionParams.transferMethod,
+ actionParams.transferProtocolType);
+
+ if (paramsValid == false)
+ {
+ return;
+ }
crow::connections::systemBus->async_method_call(
- [asyncResp, req,
+ [asyncResp, actionParams,
resName](const boost::system::error_code ec,
- const GetObjectType& getObjectType) {
+ const GetObjectType& getObjectType) mutable {
if (ec)
{
BMCWEB_LOG_ERROR
@@ -810,9 +847,9 @@
BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
crow::connections::systemBus->async_method_call(
- [service, resName, req,
+ [service, resName, actionParams,
asyncResp](const boost::system::error_code ec,
- ManagedObjectType& subtree) {
+ ManagedObjectType& subtree) mutable {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
@@ -857,53 +894,14 @@
continue;
}
- // Legacy mode
- std::string imageUrl;
- std::optional<std::string> userName;
- std::optional<std::string> password;
- std::optional<std::string>
- transferMethod;
- std::optional<std::string>
- transferProtocolType;
- std::optional<bool> writeProtected =
- true;
- std::optional<bool> inserted;
-
- // Read obligatory parameters (url of
- // image)
- if (!json_util::readJson(
- req, asyncResp->res, "Image",
- imageUrl, "WriteProtected",
- writeProtected, "UserName",
- userName, "Password", password,
- "Inserted", inserted,
- "TransferMethod",
- transferMethod,
- "TransferProtocolType",
- transferProtocolType))
- {
- BMCWEB_LOG_DEBUG
- << "Image is not provided";
- return;
- }
-
- bool paramsValid = validateParams(
- asyncResp->res, imageUrl, inserted,
- transferMethod,
- transferProtocolType);
-
- if (paramsValid == false)
- {
- return;
- }
-
// manager is irrelevant for
// VirtualMedia dbus calls
- doMountVmLegacy(asyncResp, service,
- resName, imageUrl,
- !(*writeProtected),
- std::move(*userName),
- std::move(*password));
+ doMountVmLegacy(
+ asyncResp, service, resName,
+ actionParams.imageUrl,
+ !(*actionParams.writeProtected),
+ std::move(*actionParams.userName),
+ std::move(*actionParams.password));
return;
}
@@ -928,7 +926,7 @@
"/redfish/v1/Managers/<str>/VirtualMedia/<str>/Actions/VirtualMedia.EjectMedia")
.privileges(redfish::privileges::postVirtualMedia)
.methods(boost::beast::http::verb::post)(
- [](const crow::Request& req,
+ [](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& name, const std::string& resName) {
if (name != "bmc")
@@ -940,9 +938,8 @@
}
crow::connections::systemBus->async_method_call(
- [asyncResp, req,
- resName](const boost::system::error_code ec,
- const GetObjectType& getObjectType) {
+ [asyncResp, resName](const boost::system::error_code ec,
+ const GetObjectType& getObjectType) {
if (ec)
{
BMCWEB_LOG_ERROR
@@ -956,7 +953,7 @@
BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
crow::connections::systemBus->async_method_call(
- [resName, service, req, asyncResp{asyncResp}](
+ [resName, service, asyncResp{asyncResp}](
const boost::system::error_code ec,
ManagedObjectType& subtree) {
if (ec)