From e35e526ad6ddb60913deda84d188aba4e6507fd7 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Mon, 15 May 2017 19:53:01 +0200 Subject: [PATCH] ceph: fix errno_to_exception We are using an internal API of rados. This change removes its usage. Closes-bug: #1690876 Change-Id: Ia1304395748f54fed0995406b9bc7260af8f5e84 --- gnocchi/storage/common/ceph.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gnocchi/storage/common/ceph.py b/gnocchi/storage/common/ceph.py index 764cdf4f..b1c9b673 100644 --- a/gnocchi/storage/common/ceph.py +++ b/gnocchi/storage/common/ceph.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import errno + from oslo_log import log LOG = log.getLogger(__name__) @@ -73,6 +75,26 @@ def close_rados_connection(conn, ioctx): conn.shutdown() +# NOTE(sileht): The mapping is not part of the rados Public API So we copy it +# here. +EXCEPTION_NAMES = { + errno.EPERM: 'PermissionError', + errno.ENOENT: 'ObjectNotFound', + errno.EIO: 'IOError', + errno.ENOSPC: 'NoSpace', + errno.EEXIST: 'ObjectExists', + errno.EBUSY: 'ObjectBusy', + errno.ENODATA: 'NoData', + errno.EINTR: 'InterruptedOrTimeoutError', + errno.ETIMEDOUT: 'TimedOut', + errno.EACCES: 'PermissionDeniedError' +} + + def errno_to_exception(ret): if ret < 0: - raise rados.errno_to_exception[abs(ret)] + name = EXCEPTION_NAMES.get(abs(ret)) + if name is None: + raise rados.Error("Unhandled error '%s'" % ret) + else: + raise getattr(rados, name)