summaryrefslogtreecommitdiff
path: root/redfish-core/src/utils/dbus_utils.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-08-24Make PATCH return 204 againEd Tanous1-2/+2
It was correctly pointed out that for PATCH, we cannot return 200 success without also returning the object, per Redfish. This commit partially reverts cdf25ff, to give PATCH the old (204) behavior again. Tested: Patch now returns 204 Change-Id: I8ede932a73ae064586d94c47393e4418350adb00 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-08-17clang-format: re-format for clang-18Patrick Williams1-5/+4
clang-format-18 isn't compatible with the clang-format-17 output, so we need to reformat the code with the latest version. The way clang-18 handles lambda formatting also changed, so we have made changes to the organization default style format to better handle lambda formatting. See I5e08687e696dd240402a2780158664b7113def0e for updated style. See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement. Change-Id: Iceec1dc95b6c908ec6c21fb40093de9dd18bf11a Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2024-08-17Make set properties return 200 Success not 204Ed Tanous1-4/+4
Both 200 and 204 are allowed by the Redfish specification. Table 11 states: 200 OK Success, and the action's schema definition does not contain an action response. 204 No Content: Success, and the action's schema definition does not contain an action response. While both of these are allowed, we accidentally changed behavior in the following commit: 87c4496 Move to Redfish setProperty call When we transitioned these over to the common dbus calling methods. This commit restores the old behavior of returning 200 success on actions, which some implementations are expecting. Tested: WIP. Change-Id: I02e47585acf85bd04dcb9d428ef3e39a21d9c75f Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-29Break out formattersEd Tanous1-0/+1
In the change made to move to std::format, we defined some custom type formatters in logging.hpp. This had the unintended effect of making all compile units pull in the majority of boost::url, and nlohmann::json as includes. This commit breaks out boost and json formatters into their own separate includes. Tested: Code compiles. Logging changes only. Change-Id: I6a788533169f10e19130a1910cd3be0cc729b020 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-19Add missing headersEd Tanous1-1/+6
Most of these were found by breaking every redfish class handler into its own compile unit: When that's done, these missing headers become compile errors. We should just fix them. In addition, this allows us to enable automatic header checking in clang-tidy using misc-header-cleaner. Because the compiler can now "see" all the defines, it no longer tries to remove headers that it thinks are unused. [1] https://github.com/openbmc/bmcweb/commit/4fdee9e39e9f03122ee16a6fb251a380681f56ac Tested: Code compiles. Change-Id: Ifa27ac4a512362b7ded7cc3068648dc4aea6ad7b Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-15Move to Redfish setProperty callAsmitha Karunanithi1-0/+11
This commit changes sdbusplus setProperty calls (in various files) to setDbusProperty method in Redfish namespace that handles all DBus errors in a consistent manner. It also handles and translates additional DBus errors to Redfish specific errors in dbus_utils file. Tested By: Not tested yet Change-Id: If440774879413754f4c24f9b6572c3c9fa1fd033 Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
2024-04-09Move to Redfish Action specific setProperty callAsmitha Karunanithi1-1/+48
This commit will migrate all the setProperty calls initiated by a redfish"Action" to "setDbusProperty" method in Redfish namespace that handles all DBuserrors in a consistent manner. This method will determine if a setProperty is called during redfish "Action" or just setting of a dbus property and internally call appropriate methods that handles different set of errors. All the Redfish action specific errors are defined in error_messages.hpp file. This specific change moves setProperty call in hypervisor_system.hpp and covers errors in the mentioned file only. Tested-By: <Yet to test this usecase> Change-Id: I3da48fbeabcdcf088c4481021232f08a44797c86 Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com> Signed-off-by: Ed Tanous <ed@tanous.net>
2024-03-28Create Redfish specific setProperty callEd Tanous1-0/+76
There are currently 78 sdbusplus::asio::setProperty calls in redfish-core. The error handler for nearly all of them looks something like: ``` if (ec) { const sd_bus_error* dbusError = msg.get_error(); if ((dbusError != nullptr) && (dbusError->name == std::string_view( "xyz.openbmc_project.Common.Error.InvalidArgument"))) { BMCWEB_LOG_WARNING("DBUS response error: {}", ec); messages::propertyValueIncorrect(asyncResp->res, "<PropertyName>", <PropertyValue>); return; } messages::internalError(asyncResp->res); return; } messages::success(asyncResp->res); ``` In some cases there are more errors handled that translate to more error messages, but the vast majority only handle InvalidArgument. Many of these, like the ones in account_service.hpp, do the error handling in a lambda, which causes readability problems. This commit starts to make things more consistent, and easier for trivial property sets. This commit invents a setDbusProperty method in the redfish namespace that tries to handle all DBus errors in a consistent manner. Looking for input on whether this will work before changing over the other 73 calls. Overall this is less code, fewer inline lambdas, and defaults that should work for MOST use cases of calling an OpenBMC daemon, and fall back to more generic errors when calling a "normal" dbus daemon. As part of this, I've ported over several examples. Some things that might be up in the air: 1. Do we always return 204 no_content on property sets? Today there's a mix of 200, with a Base::Success message, and 204, with an empty body. 2. Do all DBus response codes map to the same error? A majority are covered by xyz.openbmc_project.Common.Error.InvalidArgument, but there are likely differences. If we allow any daemon to return any return code, does that cause compatibility problems later? Tested: ``` curl -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"HostName":"openbmc@#"}' https://192.168.7.2/redfish/v1/Managers/bmc/EthernetInterfaces/eth0 ``` Returns the appropriate error in the response Base.1.16.0.PropertyValueIncorrect Change-Id: If033a1112ba516792c9386c997d090c8f9094f3a Signed-off-by: Ed Tanous <ed@tanous.net>