check requested state before update properties
When the power policy is "Restore" or "Always-Off", software only
updates properties if current requested state is "On". This action is
necessary to avoid redundant tasks when AC power.
Tested:
1. Turn Off the HOST and set power policy to Always-Off
ipmitool chassis power off
ipmitool chassis policy always-off
2. AC power, wait until BMC has been rebooted.
3. HOST is OFF, check journalctl log.
BMC did not request to update requested state.
4. Turn On the HOST, AC power, wait until BMC has been rebooted.
5. HOST is OFF, check journalctl log.
BMC requests to update requested state to "Off".
6. Set power policy to Previous.
ipmitool chassis policy previous
7. AC power, wait until BMC has been rebooted.
8. HOST is OFF, check journalctl log.
BMC did not request to update requested state.
9. Turn On the HOST, AC power, wait until BMC has been rebooted.
10. HOST is ON, check journalctl log.
BMC requests to update requested state to "On".
Signed-off-by: Thang Tran <thuutran@amperecomputing.com>
Change-Id: I14f89d7cdd3911dc74f693aadb60ae04e6819bc2
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index bfabdaf..19afa2d 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -144,24 +144,33 @@
RestorePolicy::convertPolicyFromString(powerPolicy))
{
info("power_policy=ALWAYS_POWER_OFF, set requested state to off");
- phosphor::state::manager::utils::setProperty(
- bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
- convertForMessage(server::Host::Transition::Off));
+ // Read last requested state and re-request it to execute it
+ auto hostReqState = phosphor::state::manager::utils::getProperty(
+ bus, hostPath, HOST_BUSNAME, "RequestedHostTransition");
+ if (hostReqState == convertForMessage(server::Host::Transition::On))
+ {
+ phosphor::state::manager::utils::setProperty(
+ bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
+ convertForMessage(server::Host::Transition::Off));
+ }
}
else if (RestorePolicy::Policy::Restore ==
RestorePolicy::convertPolicyFromString(powerPolicy))
{
info("power_policy=RESTORE, restoring last state");
- phosphor::state::manager::utils::setProperty(
- bus, hostPath, HOST_BUSNAME, "RestartCause",
- convertForMessage(
- server::Host::RestartCause::PowerPolicyPreviousState));
// Read last requested state and re-request it to execute it
auto hostReqState = phosphor::state::manager::utils::getProperty(
bus, hostPath, HOST_BUSNAME, "RequestedHostTransition");
- phosphor::state::manager::utils::setProperty(
- bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
- hostReqState);
+ if (hostReqState == convertForMessage(server::Host::Transition::On))
+ {
+ phosphor::state::manager::utils::setProperty(
+ bus, hostPath, HOST_BUSNAME, "RestartCause",
+ convertForMessage(
+ server::Host::RestartCause::PowerPolicyPreviousState));
+ phosphor::state::manager::utils::setProperty(
+ bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
+ hostReqState);
+ }
}
}
catch (const sdbusplus::exception::exception& e)