bmc-ready: don't allow power operations if not ready
Tested:
- Put BMC in NotReady state and verified error was returned when
requesting a chassis or host power on
- Verified that a power off was still possible in this state
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I8f17c681469c01c701e80cdb57ed623e04c8b921
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 398fca5..8890b56 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -20,6 +20,7 @@
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Control/Power/RestorePolicy/server.hpp>
+#include <xyz/openbmc_project/State/Host/error.hpp>
#include <filesystem>
#include <fstream>
@@ -397,6 +398,16 @@
Host::Transition Host::requestedHostTransition(Transition value)
{
info("Host state transition request of {REQ}", "REQ", value);
+
+#if ONLY_ALLOW_BOOT_WHEN_BMC_READY
+ if ((value != Transition::Off) && (!utils::isBmcReady(this->bus)))
+ {
+ info("BMC State is not Ready so no host on operations allowed");
+ throw sdbusplus::xyz::openbmc_project::State::Host::Error::
+ BMCNotReady();
+ }
+#endif
+
// If this is not a power off request then we need to
// decrement the reboot counter. This code should
// never prevent a power on, it should just decrement