]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: update python interface for store vs. config
authorJohn Spray <john.spray@redhat.com>
Mon, 9 Apr 2018 19:24:14 +0000 (15:24 -0400)
committerJohn Spray <john.spray@redhat.com>
Mon, 23 Apr 2018 11:29:45 +0000 (07:29 -0400)
Signed-off-by: John Spray <john.spray@redhat.com>
src/pybind/mgr/mgr_module.py
src/pybind/mgr/selftest/module.py

index b51952ebd18e08b5220284e7a44020c5176476dc..01745fff2934c1c9c3ab5ac200899915673136c4 100644 (file)
@@ -498,14 +498,27 @@ class MgrModule(ceph_module.BaseMgrModule):
         else:
             return r
 
-    def get_config_prefix(self, key_prefix):
+    def get_store_prefix(self, key_prefix):
         """
-        Retrieve a dict of config values with the given prefix
+        Retrieve a dict of KV store keys to values, where the keys
+        have the given prefix
 
         :param str key_prefix:
         :return: str
         """
-        return self._ceph_get_config_prefix(key_prefix)
+        return self._ceph_get_store_prefix(key_prefix)
+
+    def _get_localized(self, key, default, getter):
+        r = getter(self.get_mgr_id() + '/' + key)
+        if r is None:
+            r = getter(key)
+
+        if r is None:
+            r = default
+        return r
+
+    def _set_localized(self, key, val, setter):
+        return setter(self.get_mgr_id() + '/' + key, val)
 
     def get_localized_config(self, key, default=None):
         """
@@ -514,13 +527,7 @@ class MgrModule(ceph_module.BaseMgrModule):
         :param str default:
         :return: str
         """
-        r = self.get_config(self.get_mgr_id() + '/' + key)
-        if r is None:
-            r = self.get_config(key)
-
-        if r is None:
-            r = default
-        return r
+        return self._get_localized(key, default, self.get_config)
 
     def set_config(self, key, val):
         """
@@ -538,30 +545,53 @@ class MgrModule(ceph_module.BaseMgrModule):
         :param str default:
         :return: str
         """
-        return self._ceph_set_config(self.get_mgr_id() + '/' + key, val)
+        return self._set_localized(key, val, self.set_config)
 
-    def set_config_json(self, key, val):
+    def set_store_json(self, key, val):
         """
-        Helper for setting json-serialized-config
+        Helper for setting json-serialized stored data
 
         :param str key:
         :param val: json-serializable object
         """
-        self._ceph_set_config(key, json.dumps(val))
+        self.set_store(key, json.dumps(val))
 
-    def get_config_json(self, key):
+    def get_store_json(self, key):
         """
-        Helper for getting json-serialized config
+        Helper for getting json-serialized stored data
 
         :param str key:
         :return: object
         """
-        raw = self.get_config(key)
+        raw = self.get_store(key)
         if raw is None:
             return None
         else:
             return json.loads(raw)
 
+    def set_store(self, key, val):
+        """
+        Set a value in this module's persistent key value store
+        """
+        self._ceph_set_store(key, val)
+
+    def get_store(self, key, default=None):
+        """
+        Get a value from this module's persistent key value store
+        """
+        r = self._ceph_get_store(key)
+        if r is None:
+            return default
+        else:
+            return r
+
+    def get_localized_store(self, key, default=None):
+        return self._get_localized(key, default, self.get_store)
+
+    def set_localized_store(self, key, val):
+        return self._set_localized(key, val, self.set_store)
+
+
     def self_test(self):
         """
         Run a self-test on the module. Override this function and implement
index 401ff1eede60f0333ca256e2ac1b6700f6fb9eeb..b9530c43b146c3cf10a6a0b4603fc5892be9e32d 100644 (file)
@@ -84,6 +84,7 @@ class Module(MgrModule):
         self._self_test_osdmap()
         self._self_test_getters()
         self._self_test_config()
+        self._self_test_store()
         self._self_test_misc()
         self._self_test_perf_counters()
 
@@ -138,11 +139,15 @@ class Module(MgrModule):
         self.set_localized_config("testkey", "testvalue")
         assert self.get_localized_config("testkey") == "testvalue"
 
-        self.set_config_json("testjsonkey", {"testblob": 2})
-        assert self.get_config_json("testjsonkey") == {"testblob": 2}
-
         assert sorted(self.get_config_prefix("test").keys()) == sorted(
-                ["testkey", "testjsonkey"])
+                ["testkey"])
+
+    def _self_test_store(self):
+        self.set_store("testkey", "testvalue")
+        assert self.get_store("testkey") == "testvalue"
+
+        self.set_store_json("testjsonkey", {"testblob": 2})
+        assert self.get_store_json("testjsonkey") == {"testblob": 2}
 
     def _self_test_perf_counters(self):
         self.get_perf_schema("osd", "0")