From 6b0f66bdaa12ef09bf628f2610ea48ac14888b6f Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 3 Apr 2024 13:38:21 -0700 Subject: Break out DoTftpUpdate This refactor of code is in preparation for adding new SimpleUpdate types. Separating out TFTP helps to keep code organized. Tested: Need help here. TFTP isn't enabled a lot. Change-Id: Ifbdd4b73bb0f9c31092d729d1ec3d3f395f680b8 Signed-off-by: Ed Tanous --- redfish-core/lib/update_service.hpp | 78 +++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'redfish-core') diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index 9fd1499466..a735567c8e 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -505,6 +505,49 @@ inline std::optional return TftpUrl{path, host}; } +inline void doTftpUpdate(const crow::Request& req, + const std::shared_ptr& asyncResp, + const TftpUrl& tftpUrl) +{ +#ifndef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE + messages::actionParameterNotSupported(asyncResp->res, "ImageURI", + tftpUrl.tftpServer); + return; +#endif + BMCWEB_LOG_DEBUG("Server: {} File: {}", tftpUrl.tftpServer, tftpUrl.fwFile); + + // Setup callback for when new software detected + // Give TFTP 10 minutes to complete + monitorForSoftwareAvailable( + asyncResp, req, + "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate", 600); + + // TFTP can take up to 10 minutes depending on image size and + // connection speed. Return to caller as soon as the TFTP operation + // has been started. The callback above will ensure the activate + // is started once the download has completed + redfish::messages::success(asyncResp->res); + + // Call TFTP service + crow::connections::systemBus->async_method_call( + [](const boost::system::error_code& ec) { + if (ec) + { + // messages::internalError(asyncResp->res); + cleanUp(); + BMCWEB_LOG_DEBUG("error_code = {}", ec); + BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); + } + else + { + BMCWEB_LOG_DEBUG("Call to DownloaViaTFTP Success"); + } + }, + "xyz.openbmc_project.Software.Download", + "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP", + "DownloadViaTFTP", tftpUrl.fwFile, tftpUrl.tftpServer); +} + inline void handleUpdateServiceSimpleUpdateAction( crow::App& app, const crow::Request& req, const std::shared_ptr& asyncResp) @@ -540,40 +583,7 @@ inline void handleUpdateServiceSimpleUpdateAction( } BMCWEB_LOG_DEBUG("Server: {} File: {}", ret->tftpServer, ret->fwFile); -#ifndef BMCWEB_INSECURE_ENABLE_REDFISH_FW_TFTP_UPDATE - messages::actionParameterNotSupported(asyncResp->res, "ImageURI", imageURI); - return; -#endif - // Setup callback for when new software detected - // Give TFTP 10 minutes to complete - monitorForSoftwareAvailable( - asyncResp, req, - "/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate", 600); - - // TFTP can take up to 10 minutes depending on image size and - // connection speed. Return to caller as soon as the TFTP operation - // has been started. The callback above will ensure the activate - // is started once the download has completed - redfish::messages::success(asyncResp->res); - - // Call TFTP service - crow::connections::systemBus->async_method_call( - [](const boost::system::error_code& ec) { - if (ec) - { - // messages::internalError(asyncResp->res); - cleanUp(); - BMCWEB_LOG_DEBUG("error_code = {}", ec); - BMCWEB_LOG_DEBUG("error msg = {}", ec.message()); - } - else - { - BMCWEB_LOG_DEBUG("Call to DownloaViaTFTP Success"); - } - }, - "xyz.openbmc_project.Software.Download", - "/xyz/openbmc_project/software", "xyz.openbmc_project.Common.TFTP", - "DownloadViaTFTP", ret->fwFile, ret->tftpServer); + doTftpUpdate(req, asyncResp, *ret); BMCWEB_LOG_DEBUG("Exit UpdateService.SimpleUpdate doPost"); } -- cgit v1.2.3