sched-host-tran: implement host transition process
Set the scheduled time and host transition to trigger power on/off.
Tested:
1. Check the state first
$ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
{
"data": {
"AttemptsLeft": 3,
"BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
"CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Off",
"OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
"RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.Off",
"RequestedTransition": "xyz.openbmc_project.State.Host.Transition.On",
"ScheduledTime": 0
},
"message": "200 OK",
"status": "ok"
}
2. Set a time in future
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582184830
# busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime
t 1582184830
3. Check the state again after scheduled time
Jan 15 06:38:20 WS-Seq-FW-2 phosphor-host-state-manager[442]: Host State transaction request
$ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
{
"data": {
"AttemptsLeft": 3,
"BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
"CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running",
"OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
"RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On",
"RequestedTransition": "xyz.openbmc_project.State.Host.Transition.On",
"ScheduledTime": 0
},
"message": "200 OK",
"status": "ok"
}
4. Set quested transition to off
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition RequestedTransition \
s "xyz.openbmc_project.State.Host.Transition.Off"
# busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
/xyz/openbmc_project/state/host0 \
xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582250580
$ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
{
"data": {
"AttemptsLeft": 3,
"BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
"CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Off",
"OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
"RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.Off"
"RequestedTransition": "xyz.openbmc_project.State.Host.Transition.Off",
"ScheduledTime": 0
},
"message": "200 OK",
"status": "ok"
}
Change-Id: Ib9f3a3984005d9187a9b98603ec1598d8992869e
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
diff --git a/scheduled_host_transition.hpp b/scheduled_host_transition.hpp
index c125638..1cb2591 100644
--- a/scheduled_host_transition.hpp
+++ b/scheduled_host_transition.hpp
@@ -2,7 +2,10 @@
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
#include <xyz/openbmc_project/State/ScheduledHostTransition/server.hpp>
+#include "config.h"
class TestScheduledHostTransition;
@@ -13,6 +16,8 @@
namespace manager
{
+using Transition =
+ sdbusplus::xyz::openbmc_project::State::server::Host::Transition;
using ScheduledHostTransitionInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition>;
@@ -24,8 +29,11 @@
class ScheduledHostTransition : public ScheduledHostTransitionInherit
{
public:
- ScheduledHostTransition(sdbusplus::bus::bus& bus, const char* objPath) :
- ScheduledHostTransitionInherit(bus, objPath)
+ ScheduledHostTransition(sdbusplus::bus::bus& bus, const char* objPath,
+ const sdeventplus::Event& event) :
+ ScheduledHostTransitionInherit(bus, objPath),
+ bus(bus),
+ timer(event, std::bind(&ScheduledHostTransition::callback, this))
{
}
@@ -43,11 +51,28 @@
private:
friend class TestScheduledHostTransition;
+
+ /** @brief sdbusplus bus client connection */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Timer used for host transition with seconds */
+ sdeventplus::utility::Timer<sdeventplus::ClockId::RealTime> timer;
+
/** @brief Get current time
*
* @return - return current epoch time
*/
std::chrono::seconds getTime();
+
+ /** @brief Implement host transition
+ *
+ * @return - Does not return anything. Error will result in exception
+ * being thrown
+ */
+ void hostTransition();
+
+ /** @brief Used by the timer to do host transition */
+ void callback();
};
} // namespace manager
} // namespace state