rest_dbus: Add read-only property error
There is now support in sdbusplus to mark a property as
read-only, so that a REST request to modify it would return
org.freedesktop.DBus.Error.PropertyReadOnly.
Add support for this error to provide a more useful and
compact error instead of the default 500 Internal Error with
the traceback.
Tested:
Instead of a 500 error with traceback, a compact 403 error
is displayed:
$ curl b cjar -k -H "Content-Type: application/json" -X PUT -d '{"data": 50}' https://${bmc}/xyz/openbmc_project/control/power_supply/attr/DeratingFactor
{
"data": {
"description": "org.freedesktop.DBus.Error.PropertyReadOnly: Property 'DeratingFactor' is not writable."
},
"message": "403 Forbidden",
"status": "error"
}
Change-Id: I5648a99c7656a6f9d9a8ca967418fabd64b080c6
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 5eaffb7..9cb69f0 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -50,6 +50,7 @@
DBUS_UNKNOWN_INTERFACE = 'org.freedesktop.DBus.Error.UnknownInterface'
DBUS_UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod'
+DBUS_PROPERTY_READONLY = 'org.freedesktop.DBus.Error.PropertyReadOnly'
DBUS_INVALID_ARGS = 'org.freedesktop.DBus.Error.InvalidArgs'
DBUS_TYPE_ERROR = 'org.freedesktop.DBus.Python.TypeError'
DELETE_IFACE = 'xyz.openbmc_project.Object.Delete'
@@ -495,6 +496,8 @@
except ValueError as e:
abort(400, str(e))
except dbus.exceptions.DBusException as e:
+ if e.get_dbus_name() == DBUS_PROPERTY_READONLY:
+ abort(403, str(e))
if e.get_dbus_name() == DBUS_INVALID_ARGS and retry:
bus_name = properties_iface.bus_name
expected_type = get_type_signature_by_introspection(self.bus,