Skip to content

Commit

Permalink
Fix 670598: dbus_util changes to fix response (#1135)
Browse files Browse the repository at this point in the history
Taking latest upstream changes to fix multiple success message seen in
response. Now the behaviour is similar to what upstream does, which mean
there is no message in the response. The response is set with no_content
flag.

Signed-off-by: Abhilash Raju <[email protected]>
  • Loading branch information
abhilashraju authored Jan 30, 2025
1 parent 84d9bd3 commit 5f04ab3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 3 additions & 2 deletions redfish-core/src/utils/dbus_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/asio/error.hpp>
#include <boost/beast/http/status.hpp>
#include <boost/system/error_code.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/message.hpp>

#include <memory>
Expand Down Expand Up @@ -83,10 +84,10 @@ void afterSetProperty(
messages::internalError(asyncResp->res);
return;
}
// Only set success if another error hasn't already happened.
// Only set 204 if another error hasn't already happened.
if (asyncResp->res.result() == boost::beast::http::status::ok)
{
messages::success(asyncResp->res);
asyncResp->res.result(boost::beast::http::status::no_content);
}
};

Expand Down
23 changes: 17 additions & 6 deletions test/redfish-core/include/utils/dbus_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@

#include "utils/dbus_utils.hpp"

#include "http_request.hpp"
#include "async_resp.hpp"
#include "http_response.hpp"

#include <boost/beast/http/status.hpp>
#include <boost/system/errc.hpp>
#include <nlohmann/json.hpp>
#include <sdbusplus/message.hpp>

#include <cstdint>
#include <optional>
#include <memory>
#include <string>
#include <system_error>
#include <vector>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace redfish::details
Expand All @@ -31,6 +29,19 @@ TEST(DbusUtils, AfterPropertySetSuccess)
afterSetProperty(asyncResp, "MyRedfishProperty",
nlohmann::json("MyRedfishValue"), ec, msg);

EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::no_content);
}

TEST(DbusUtils, AfterActionPropertySetSuccess)
{
std::shared_ptr<bmcweb::AsyncResp> asyncResp =
std::make_shared<bmcweb::AsyncResp>();

boost::system::error_code ec;
sdbusplus::message_t msg;
afterSetPropertyAction(asyncResp, "MyRedfishProperty",
nlohmann::json("MyRedfishValue"), ec, msg);

EXPECT_EQ(asyncResp->res.result(), boost::beast::http::status::ok);
EXPECT_EQ(asyncResp->res.jsonValue,
R"({
Expand Down

0 comments on commit 5f04ab3

Please sign in to comment.