summaryrefslogtreecommitdiffstats
path: root/testsuite
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-16 10:53:23 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-08-16 10:53:23 -0400
commit38f3cfcfdbf36bca3b048cc87e6d11e0c883673b (patch)
tree6a12ce51ad9078dd843dc41f668da3a77e889979 /testsuite
parent35498c8b849c15632d720656d5736c4c85f76b53 (diff)
downloadbcfg2-38f3cfcfdbf36bca3b048cc87e6d11e0c883673b.tar.gz
bcfg2-38f3cfcfdbf36bca3b048cc87e6d11e0c883673b.tar.bz2
bcfg2-38f3cfcfdbf36bca3b048cc87e6d11e0c883673b.zip
Rewrote arbitrary data cache system
The caching facilities in Bcfg2.Server.Cache provided basically no features. This rewrites that to allow for much more powerful cache expiration, with a particular focus on interoperation between different components and plugins to let caches be expired as necessary. (E.g., the Probes plugin can expire the Metadata cache.) This does not affect any of the file data cached by Bcfg2, only the caches that are populated with arbitrary data (Metadata, Packages, Probes, etc.).
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestCache.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestCache.py b/testsuite/Testsrc/Testlib/TestServer/TestCache.py
new file mode 100644
index 000000000..7c26e52b8
--- /dev/null
+++ b/testsuite/Testsrc/Testlib/TestServer/TestCache.py
@@ -0,0 +1,54 @@
+import os
+import sys
+
+# add all parent testsuite directories to sys.path to allow (most)
+# relative imports in python 2.4
+path = os.path.dirname(__file__)
+while path != "/":
+ if os.path.basename(path).lower().startswith("test"):
+ sys.path.append(path)
+ if os.path.basename(path) == "testsuite":
+ break
+ path = os.path.dirname(path)
+from common import *
+
+from Bcfg2.Server.Cache import *
+
+
+class TestCache(Bcfg2TestCase):
+ def test_cache(self):
+ md_cache = Cache("Metadata")
+ md_cache['foo.example.com'] = 'foo metadata'
+ md_cache['bar.example.com'] = 'bar metadata'
+ self.assertItemsEqual(list(iter(md_cache)),
+ ["foo.example.com", "bar.example.com"])
+
+ probe_cache = Cache("Probes", "data")
+ probe_cache['foo.example.com'] = 'foo probe data'
+ probe_cache['bar.example.com'] = 'bar probe data'
+ self.assertItemsEqual(list(iter(probe_cache)),
+ ["foo.example.com", "bar.example.com"])
+
+ md_cache.expire("foo.example.com")
+ self.assertItemsEqual(list(iter(md_cache)), ["bar.example.com"])
+ self.assertItemsEqual(list(iter(probe_cache)),
+ ["foo.example.com", "bar.example.com"])
+
+ probe_cache.expire("bar.example.com")
+ self.assertItemsEqual(list(iter(md_cache)), ["bar.example.com"])
+ self.assertItemsEqual(list(iter(probe_cache)),
+ ["foo.example.com"])
+
+ probe_cache['bar.example.com'] = 'bar probe data'
+ self.assertItemsEqual(list(iter(md_cache)), ["bar.example.com"])
+ self.assertItemsEqual(list(iter(probe_cache)),
+ ["foo.example.com", "bar.example.com"])
+
+ expire("bar.example.com")
+ self.assertEqual(len(md_cache), 0)
+ self.assertItemsEqual(list(iter(probe_cache)),
+ ["foo.example.com"])
+
+ probe_cache2 = Cache("Probes", "data")
+ self.assertItemsEqual(list(iter(probe_cache)),
+ list(iter(probe_cache2)))