From 87c449664e5375abb040af6fad63ef965c311bec Mon Sep 17 00:00:00 2001 From: Asmitha Karunanithi Date: Thu, 4 Apr 2024 18:28:33 +0000 Subject: Move to Redfish setProperty call 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 --- redfish-core/lib/led.hpp | 39 ++-- redfish-core/lib/network_protocol.hpp | 56 ++---- redfish-core/lib/power.hpp | 19 +- redfish-core/lib/processor.hpp | 73 +------- redfish-core/lib/systems.hpp | 328 +++++++++------------------------- redfish-core/src/utils/dbus_utils.cpp | 11 ++ 6 files changed, 134 insertions(+), 392 deletions(-) diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp index baf9235ee9..c310e3f2cf 100644 --- a/redfish-core/lib/led.hpp +++ b/redfish-core/lib/led.hpp @@ -138,20 +138,12 @@ inline void ledOn = true; } } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, - "xyz.openbmc_project.LED.GroupManager", - "/xyz/openbmc_project/led/groups/enclosure_identify", - "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_DEBUG("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - messages::success(asyncResp->res); - }); + setDbusProperty( + asyncResp, "xyz.openbmc_project.LED.GroupManager", + sdbusplus::message::object_path( + "/xyz/openbmc_project/led/groups/enclosure_identify"), + "xyz.openbmc_project.Led.Group", "Asserted", "IndicatorLED", + ledBlinkng); }); } @@ -236,19 +228,12 @@ inline void setSystemLocationIndicatorActive( // Some systems may not have enclosure_identify_blink object so // lets set enclosure_identify state also if // enclosure_identify_blink failed - sdbusplus::asio::setProperty( - *crow::connections::systemBus, - "xyz.openbmc_project.LED.GroupManager", - "/xyz/openbmc_project/led/groups/enclosure_identify", - "xyz.openbmc_project.Led.Group", "Asserted", ledState, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_DEBUG("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty( + asyncResp, "xyz.openbmc_project.LED.GroupManager", + sdbusplus::message::object_path( + "/xyz/openbmc_project/led/groups/enclosure_identify"), + "xyz.openbmc_project.Led.Group", "Asserted", + "LocationIndicatorActive", ledState); } }); } diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp index d864e222d6..00b5d9e309 100644 --- a/redfish-core/lib/network_protocol.hpp +++ b/redfish-core/lib/network_protocol.hpp @@ -252,16 +252,11 @@ inline void handleNTPProtocolEnabled( "xyz.openbmc_project.Time.Synchronization.Method.Manual"; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/time/sync_method", - "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", - timeSyncMethod, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - messages::internalError(asyncResp->res); - } - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/time/sync_method"), + "xyz.openbmc_project.Time.Synchronization", + "TimeSyncMethod", "NTP/ProtocolEnabled", timeSyncMethod); } inline void @@ -362,16 +357,9 @@ inline void continue; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, objectPath, - interface, "StaticNTPServers", currentNtpServers, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, objectPath, interface, + "StaticNTPServers", "NTP/NTPServers/", + currentNtpServers); } } } @@ -400,30 +388,14 @@ inline void { if (entry.first.starts_with(netBasePath)) { - sdbusplus::asio::setProperty( - *crow::connections::systemBus, entry.second.begin()->first, - entry.first, + setDbusProperty( + asyncResp, entry.second.begin()->first, entry.first, "xyz.openbmc_project.Control.Service.Attributes", "Running", - protocolEnabled, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - messages::internalError(asyncResp->res); - return; - } - }); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, entry.second.begin()->first, - entry.first, + "IPMI/ProtocolEnabled", protocolEnabled); + setDbusProperty( + asyncResp, entry.second.begin()->first, entry.first, "xyz.openbmc_project.Control.Service.Attributes", "Enabled", - protocolEnabled, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - messages::internalError(asyncResp->res); - return; - } - }); + "IPMI/ProtocolEnabled", protocolEnabled); } } }); diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp index 80276d2817..ad07d1cb9a 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -53,20 +53,11 @@ inline void afterGetPowerCapEnable( return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/power_cap", - "xyz.openbmc_project.Control.Power.Cap", "PowerCap", valueToSet, - [sensorsAsyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_DEBUG("Power Limit Set: Dbus error: {}", ec2); - messages::internalError(sensorsAsyncResp->asyncResp->res); - return; - } - sensorsAsyncResp->asyncResp->res.result( - boost::beast::http::status::no_content); - }); + setDbusProperty(sensorsAsyncResp->asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/power_cap"), + "xyz.openbmc_project.Control.Power.Cap", "PowerCap", + "PowerControl", valueToSet); } inline void afterGetChassisPath( diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp index 7b22c86d2a..ff17ebdcc3 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -998,65 +998,6 @@ inline void }); } -/** - * Handle the D-Bus response from attempting to set the CPU's AppliedConfig - * property. Main task is to translate error messages into Redfish errors. - * - * @param[in,out] resp HTTP response. - * @param[in] setPropVal Value which we attempted to set. - * @param[in] ec D-Bus response error code. - * @param[in] msg D-Bus response message. - */ -inline void - handleAppliedConfigResponse(const std::shared_ptr& resp, - const std::string& setPropVal, - const boost::system::error_code& ec, - const sdbusplus::message_t& msg) -{ - if (!ec) - { - BMCWEB_LOG_DEBUG("Set Property succeeded"); - return; - } - - BMCWEB_LOG_DEBUG("Set Property failed: {}", ec); - - const sd_bus_error* dbusError = msg.get_error(); - if (dbusError == nullptr) - { - messages::internalError(resp->res); - return; - } - - // The asio error code doesn't know about our custom errors, so we have to - // parse the error string. Some of these D-Bus -> Redfish translations are a - // stretch, but it's good to try to communicate something vaguely useful. - if (strcmp(dbusError->name, - "xyz.openbmc_project.Common.Error.InvalidArgument") == 0) - { - // Service did not like the object_path we tried to set. - messages::propertyValueIncorrect( - resp->res, "AppliedOperatingConfig/@odata.id", setPropVal); - } - else if (strcmp(dbusError->name, - "xyz.openbmc_project.Common.Error.NotAllowed") == 0) - { - // Service indicates we can never change the config for this processor. - messages::propertyNotWritable(resp->res, "AppliedOperatingConfig"); - } - else if (strcmp(dbusError->name, - "xyz.openbmc_project.Common.Error.Unavailable") == 0) - { - // Service indicates the config cannot be changed right now, but maybe - // in a different system state. - messages::resourceInStandby(resp->res); - } - else - { - messages::internalError(resp->res); - } -} - /** * Handle the PATCH operation of the AppliedOperatingConfig property. Do basic * validation of the input data, and then set the D-Bus property. @@ -1099,8 +1040,8 @@ inline void patchAppliedOperatingConfig( if (!appliedConfigUri.starts_with(expectedPrefix) || expectedPrefix.size() == appliedConfigUri.size()) { - messages::propertyValueIncorrect( - resp->res, "AppliedOperatingConfig/@odata.id", appliedConfigUri); + messages::propertyValueIncorrect(resp->res, "AppliedOperatingConfig", + appliedConfigUri); return; } @@ -1115,14 +1056,10 @@ inline void patchAppliedOperatingConfig( BMCWEB_LOG_INFO("Setting config to {}", configPath.str); // Set the property, with handler to check error responses - sdbusplus::asio::setProperty( - *crow::connections::systemBus, *controlService, cpuObjectPath, + setDbusProperty( + resp, *controlService, cpuObjectPath, "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", - "AppliedConfig", configPath, - [resp, appliedConfigUri](const boost::system::error_code& ec, - const sdbusplus::message_t& msg) { - handleAppliedConfigResponse(resp, appliedConfigUri, ec, msg); - }); + "AppliedConfig", "AppliedOperatingConfig", configPath); } inline void diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 082af6439b..5765af89ab 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -1265,19 +1265,11 @@ inline void setAutomaticRetryAttempts( const uint32_t retryAttempts) { BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts."); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.State.Host", - "/xyz/openbmc_project/state/host0", + setDbusProperty( + asyncResp, "xyz.openbmc_project.State.Host", + sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"), "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts", - retryAttempts, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR( - "DBUS response error: Set setAutomaticRetryAttempts{}", ec); - messages::internalError(asyncResp->res); - return; - } - }); + "Boot/AutomaticRetryAttempts", retryAttempts); } inline computer_system::PowerRestorePolicyTypes @@ -1528,20 +1520,9 @@ inline void setTrustedModuleRequiredToBoot( } // Valid TPM Enable object found, now setting the value - sdbusplus::asio::setProperty( - *crow::connections::systemBus, serv, path, - "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", tpmRequired, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR( - "DBUS response error: Set TrustedModuleRequiredToBoot{}", - ec2); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot done."); - }); + setDbusProperty(asyncResp, serv, path, + "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", + "Boot/TrustedModuleRequiredToBoot", tpmRequired); }); } @@ -1586,24 +1567,11 @@ inline void setBootType(const std::shared_ptr& asyncResp, // Act on validated parameters BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/boot", - "xyz.openbmc_project.Control.Boot.Type", "BootType", bootTypeStr, - [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - if (ec.value() == boost::asio::error::host_unreachable) - { - messages::resourceNotFound(asyncResp->res, "Set", "BootType"); - return; - } - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Boot type update done."); - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/boot"), + "xyz.openbmc_project.Control.Boot.Type", "BootType", + "Boot/BootSourceOverrideMode", bootTypeStr); } /** @@ -1654,19 +1622,11 @@ inline void setBootEnable(const std::shared_ptr& asyncResp, // Act on validated parameters BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/boot", - "xyz.openbmc_project.Object.Enable", "Enabled", bootOverrideEnable, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Boot override enable update done."); - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/boot"), + "xyz.openbmc_project.Object.Enable", "Enabled", + "Boot/BootSourceOverrideEnabled", bootOverrideEnable); if (!bootOverrideEnable) { @@ -1678,19 +1638,11 @@ inline void setBootEnable(const std::shared_ptr& asyncResp, BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}", bootOverridePersistent); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/boot/one_time", - "xyz.openbmc_project.Object.Enable", "Enabled", !bootOverridePersistent, - [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Boot one_time update done."); - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/boot/one_time"), + "xyz.openbmc_project.Object.Enable", "Enabled", + "Boot/BootSourceOverrideEnabled", !bootOverridePersistent); } /** @@ -1731,33 +1683,16 @@ inline void BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr); BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr); - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/boot", - "xyz.openbmc_project.Control.Boot.Source", "BootSource", bootSourceStr, - [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Boot source update done."); - }); - - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/boot", - "xyz.openbmc_project.Control.Boot.Mode", "BootMode", bootModeStr, - [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - BMCWEB_LOG_DEBUG("Boot mode update done."); - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/boot"), + "xyz.openbmc_project.Control.Boot.Source", "BootSource", + "Boot/BootSourceOverrideTarget", bootSourceStr); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/boot"), + "xyz.openbmc_project.Control.Boot.Mode", "BootMode", + "Boot/BootSourceOverrideTarget", bootModeStr); } /** @@ -1839,18 +1774,9 @@ inline void setAssetTag(const std::shared_ptr& asyncResp, return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", - assetTag, [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("D-Bus response error on AssetTag Set {}", - ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Inventory.Decorator.AssetTag", + "AssetTag", "AssetTag", assetTag); }); } @@ -1903,21 +1829,11 @@ inline void return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/logging/settings", - "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", - *stopBootEnabled, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - if (ec.value() != EBADR) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - } - return; - } - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/logging/settings"), + "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", + "Boot/StopBootOnFault", *stopBootEnabled); } /** @@ -1954,18 +1870,12 @@ inline void return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/auto_reboot", - "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", - autoRebootEnabled, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/auto_reboot"), + "xyz.openbmc_project.Control.Boot.RebootPolicy", + "AutoReboot", "Boot/AutomaticRetryConfig", + autoRebootEnabled); } inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy) @@ -2008,18 +1918,12 @@ inline void return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/power_restore_policy", + setDbusProperty( + asyncResp, "xyz.openbmc_project.Settings", + sdbusplus::message::object_path( + "/xyz/openbmc_project/control/host0/power_restore_policy"), "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", - powerRestorePolicy, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - }); + "PowerRestorePolicy", powerRestorePolicy); } #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE @@ -2388,17 +2292,9 @@ inline void setPowerMode(const std::shared_ptr& asyncResp, BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path); // Set the Power Mode property - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.Mode", "PowerMode", powerMode, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.Mode", "PowerMode", + "PowerMode", powerMode); }); } @@ -2556,34 +2452,20 @@ inline void return; } - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Watchdog", - "/xyz/openbmc_project/watchdog/host0", - "xyz.openbmc_project.State.Watchdog", "ExpireAction", - wdtTimeOutActStr, [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Watchdog", + sdbusplus::message::object_path( + "/xyz/openbmc_project/watchdog/host0"), + "xyz.openbmc_project.State.Watchdog", "ExpireAction", + "HostWatchdogTimer/TimeoutAction", wdtTimeOutActStr); } if (wdtEnable) { - sdbusplus::asio::setProperty( - *crow::connections::systemBus, "xyz.openbmc_project.Watchdog", - "/xyz/openbmc_project/watchdog/host0", - "xyz.openbmc_project.State.Watchdog", "Enabled", *wdtEnable, - [asyncResp](const boost::system::error_code& ec) { - if (ec) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, "xyz.openbmc_project.Watchdog", + sdbusplus::message::object_path( + "/xyz/openbmc_project/watchdog/host0"), + "xyz.openbmc_project.State.Watchdog", "Enabled", + "HostWatchdogTimer/FunctionEnabled", *wdtEnable); } } @@ -2814,81 +2696,45 @@ inline void if (ipsEnable) { - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.IdlePowerSaver", "Enabled", - *ipsEnable, [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.IdlePowerSaver", + "Enabled", "IdlePowerSaver/Enabled", *ipsEnable); } if (ipsEnterUtil) { - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "EnterUtilizationPercent", *ipsEnterUtil, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.IdlePowerSaver", + "EnterUtilizationPercent", + "IdlePowerSaver/EnterUtilizationPercent", + *ipsEnterUtil); } if (ipsEnterTime) { // Convert from seconds into milliseconds for DBus const uint64_t timeMilliseconds = *ipsEnterTime * 1000; - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "EnterDwellTime", timeMilliseconds, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.IdlePowerSaver", + "EnterDwellTime", + "IdlePowerSaver/EnterDwellTimeSeconds", + timeMilliseconds); } if (ipsExitUtil) { - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "ExitUtilizationPercent", *ipsExitUtil, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.IdlePowerSaver", + "ExitUtilizationPercent", + "IdlePowerSaver/ExitUtilizationPercent", + *ipsExitUtil); } if (ipsExitTime) { // Convert from seconds into milliseconds for DBus const uint64_t timeMilliseconds = *ipsExitTime * 1000; - sdbusplus::asio::setProperty( - *crow::connections::systemBus, service, path, - "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "ExitDwellTime", timeMilliseconds, - [asyncResp](const boost::system::error_code& ec2) { - if (ec2) - { - BMCWEB_LOG_ERROR("DBUS response error {}", ec2); - messages::internalError(asyncResp->res); - return; - } - }); + setDbusProperty(asyncResp, service, path, + "xyz.openbmc_project.Control.Power.IdlePowerSaver", + "ExitDwellTime", + "IdlePowerSaver/ExitDwellTimeSeconds", + timeMilliseconds); } }); diff --git a/redfish-core/src/utils/dbus_utils.cpp b/redfish-core/src/utils/dbus_utils.cpp index bffe7a867b..ba84d3063e 100644 --- a/redfish-core/src/utils/dbus_utils.cpp +++ b/redfish-core/src/utils/dbus_utils.cpp @@ -27,6 +27,12 @@ void afterSetProperty(const std::shared_ptr& asyncResp, { messages::insufficientPrivilege(asyncResp->res); } + if (ec.value() == boost::asio::error::host_unreachable) + { + messages::resourceNotFound(asyncResp->res, "Set", + redfishPropertyName); + return; + } const sd_bus_error* dbusError = msg.get_error(); if (dbusError != nullptr) { @@ -60,6 +66,11 @@ void afterSetProperty(const std::shared_ptr& asyncResp, redfishPropertyName); return; } + if (errorName == "xyz.openbmc_project.Common.Error.Unavailable") + { + messages::resourceInStandby(asyncResp->res); + return; + } } BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}", redfishPropertyName, ec); -- cgit v1.2.3