Get Chassis Status should not bail if button interfaces are not present
The recent rewrite of Get Chassis Status also added support for reading
the front panel enables status instead of returning a hard-coded false.
But the implementation also errors out if the interface is not present
This makes the interfaces optional, returning false if they are not presnt
and reading them correctly if they are.
Tested-by: running ipmitool chassis status with and without the
xyz.openbmc_project.Chassis.Buttons service running:
# ipmitool chassis status
System Power : on
Power Overload : false
Power Interlock : inactive
Main Power Fault : false
Power Control Fault : false
Power Restore Policy : previous
Last Power Event :
Chassis Intrusion : inactive
Front-Panel Lockout : inactive
Drive Fault : false
Cooling/Fan Fault : false
Sleep Button Disable : not allowed
Diag Button Disable : not allowed
Reset Button Disable : allowed
Power Button Disable : allowed
Sleep Button Disabled: false
Diag Button Disabled : false
Reset Button Disabled: false
Power Button Disabled: false
# systemctl stop xyz.openbmc_project.Chassis.Buttons@0.service
# ipmitool chassis status
System Power : on
Power Overload : false
Power Interlock : inactive
Main Power Fault : false
Power Control Fault : false
Power Restore Policy : previous
Last Power Event :
Chassis Intrusion : inactive
Front-Panel Lockout : inactive
Drive Fault : false
Cooling/Fan Fault : false
Front Panel Control : none
Change-Id: If845194b6f052ba84f8b062ac4259ec66f706bb5
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/chassishandler.cpp b/chassishandler.cpp
index dafc055..c9b39c0 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -936,17 +936,28 @@
}
// Front Panel Button Capabilities and disable/enable status(Optional)
- std::optional<bool> powerButtonDisabled =
+ std::optional<bool> powerButtonReading =
getButtonEnabled(powerButtonPath, powerButtonIntf);
- constexpr bool powerButtonDisableAllow = true;
-
- std::optional<bool> resetButtonDisabled =
- getButtonEnabled(resetButtonPath, resetButtonIntf);
- constexpr bool resetButtonDisableAllow = true;
-
- if (!powerButtonDisabled || !resetButtonDisabled)
+ // allow disable if the interface is present
+ bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
+ // default return the button is enabled (not disabled)
+ bool powerButtonDisabled = false;
+ if (powerButtonDisableAllow)
{
- return ipmi::responseUnspecifiedError();
+ // return the real value of the button status, if present
+ powerButtonDisabled = *powerButtonReading;
+ }
+
+ std::optional<bool> resetButtonReading =
+ getButtonEnabled(resetButtonPath, resetButtonIntf);
+ // allow disable if the interface is present
+ bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
+ // default return the button is enabled (not disabled)
+ bool resetButtonDisabled = false;
+ if (resetButtonDisableAllow)
+ {
+ // return the real value of the button status, if present
+ resetButtonDisabled = *resetButtonReading;
}
// This response has a lot of hard-coded, unsupported fields
@@ -985,7 +996,7 @@
coolingFanFault, chassisIdentifyState, chassisIdentifySupport,
false, // reserved
- *powerButtonDisabled, *resetButtonDisabled, diagButtonDisabled,
+ powerButtonDisabled, resetButtonDisabled, diagButtonDisabled,
sleepButtonDisabled, powerButtonDisableAllow, resetButtonDisableAllow,
diagButtonDisableAllow, sleepButtonDisableAllow);
}