]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/rados: add application_metadata_get
authorsongweibin <song.weibin@zte.com.cn>
Sat, 21 Sep 2019 00:37:09 +0000 (08:37 +0800)
committersongweibin <song.weibin@zte.com.cn>
Tue, 24 Sep 2019 08:53:04 +0000 (16:53 +0800)
Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/pybind/rados/rados.pyx
src/test/pybind/test_rados.py

index 01b25d207d268fb201ca704b6b603138eacfd540..9123a11691e4d1b60493b0a3d249c63e18f03231 100644 (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
index 9f8358b32871c476b0a6148c42142467bfc5e689..8d65942f4a8da8dd1431d165ed1b027871f514a1 100644 (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"))