Merge pull request #30504 from Songweibin/wip-app-meta-get

pybind/rados: add application_metadata_get

Reviewed-by: xie xingguo <xie.xingguo@zte.com.cn>
This commit is contained in:
Kefu Chai 2019-09-27 13:24:56 +08:00 committed by GitHub
commit 866eac0834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -3937,6 +3937,44 @@ returned %d, but should return zero on success." % (self.name, ret))
finally:
free(apps)
def application_metadata_get(self, app_name, key):
"""
Gets application metadata on an OSD pool for the given key
:param app_name: application name
:type app_name: str
:param key: metadata key
:type key: str
:returns: str - metadata value
:raises: :class:`Error`
"""
app_name = cstr(app_name, 'app_name')
key = cstr(key, 'key')
cdef:
char *_app_name = app_name
char *_key = key
size_t size = 129
char *value = NULL
int ret
try:
while True:
value = <char *>realloc_chk(value, size)
with nogil:
ret = rados_application_metadata_get(self.io, _app_name,
_key, value, &size)
if ret != -errno.ERANGE:
break
if ret == -errno.ENOENT:
raise KeyError('no metadata %s for application %s' % (key, _app_name))
elif ret != 0:
raise make_ex(ret, 'error getting metadata %s for application %s' %
(key, _app_name))
return decode_cstr(value)
finally:
free(value)
def application_metadata_set(self, app_name, key, value):
"""
Sets application metadata on an OSD pool

View File

@ -881,8 +881,11 @@ class TestIoctx(object):
assert_raises(Error, self.ioctx.application_metadata_set, "dne", "key",
"key")
self.ioctx.application_metadata_set("app1", "key1", "val1")
eq("val1", self.ioctx.application_metadata_get("app1", "key1"))
self.ioctx.application_metadata_set("app1", "key2", "val2")
eq("val2", self.ioctx.application_metadata_get("app1", "key2"))
self.ioctx.application_metadata_set("app2", "key1", "val1")
eq("val1", self.ioctx.application_metadata_get("app2", "key1"))
eq([("key1", "val1"), ("key2", "val2")],
self.ioctx.application_metadata_list("app1"))