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/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 71accee..aa5d178 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -16,6 +16,7 @@
#include <sdbusplus/exception.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/exception.hpp>
+#include <xyz/openbmc_project/State/Chassis/error.hpp>
#include <xyz/openbmc_project/State/Decorator/PowerSystemInputs/server.hpp>
#include <filesystem>
@@ -590,6 +591,14 @@
{
info("Change to Chassis Requested Power State: {REQ_POWER_TRAN}",
"REQ_POWER_TRAN", value);
+#if ONLY_ALLOW_BOOT_WHEN_BMC_READY
+ if ((value != Transition::Off) && (!utils::isBmcReady(this->bus)))
+ {
+ info("BMC State is not Ready so no chassis on operations allowed");
+ throw sdbusplus::xyz::openbmc_project::State::Chassis::Error::
+ BMCNotReady();
+ }
+#endif
startUnit(systemdTargetTable.find(value)->second);
return server::Chassis::requestedPowerTransition(value);
}
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