]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
provisioning/reliability: add tests, hush pyflakes, remove dead code, fix web links
authorBrian Warner <warner@lothar.com>
Sun, 15 Feb 2009 23:24:51 +0000 (16:24 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 15 Feb 2009 23:24:51 +0000 (16:24 -0700)
src/allmydata/provisioning.py
src/allmydata/reliability.py
src/allmydata/test/test_provisioning.py
src/allmydata/test/test_web.py
src/allmydata/web/reliability.py

index 42986dbac372cc81db037c7f2164c9b082e565ca..3c30418cb9615d860d320f6b1c35900bf19b5cfa 100644 (file)
@@ -709,7 +709,9 @@ class ProvisioningTool(rend.Page):
 
         try:
             from allmydata import reliability
-            f = [T.div[T.href(a="reliability.html")["Reliability Math"]], f]
+            # we import this just to test to see if the page is available
+            _hush_pyflakes = reliability
+            f = [T.div[T.a(href="reliability.html")["Reliability Math"]], f]
         except ImportError:
             pass
 
index 5db6a1f2607b66221fecb565a3981636b864b357..ecbd7c083fa3489e4a0ee40484afbf8d70e16bc3 100644 (file)
@@ -19,9 +19,6 @@ def my_dot(v1, v2):
     #for i in range(v1.shape[1]):
     return Numeric.sum(Numeric.sum(v1*v2))
 
-def yandm(seconds):
-    return "%dy.%dm" % (int(seconds/YEAR), int( (seconds%YEAR)/MONTH))
-
 class ReliabilityModel:
     """Generate a model of system-wide reliability, given several input
     parameters.
@@ -152,6 +149,8 @@ class ReliabilityModel:
                           cumulative_number_of_new_shares,
                           P_dead_unmaintained, P_dead_maintained)
 
+        #def yandm(seconds):
+        #    return "%dy.%dm" % (int(seconds/YEAR), int( (seconds%YEAR)/MONTH))
         #needed_repairs_total = sum(needed_repairs)
         #needed_new_shares_total = sum(needed_new_shares)
         #print "at 2y:"
index 64fbeec31f67f4cb9ed8d5d8fbf3c71b272aa7c4..ec99961edf28f2745daa85a22eb3d3ebbe02ad70 100644 (file)
@@ -1,7 +1,12 @@
 
 from twisted.trial import unittest
-from allmydata.provisioning import ProvisioningTool
-#from nevow.context import PageContext, RequestContext
+from allmydata import provisioning
+ReliabilityModel = None
+try:
+    from allmydata.reliability import ReliabilityModel
+except ImportError:
+    pass # might not be importable, since it needs Numeric
+
 from nevow import inevow
 from zope.interface import implements
 
@@ -16,7 +21,7 @@ class Provisioning(unittest.TestCase):
         return None
 
     def test_load(self):
-        pt = ProvisioningTool()
+        pt = provisioning.ProvisioningTool()
         self.fields = {}
         #r = MyRequest()
         #r.fields = self.fields
@@ -50,3 +55,23 @@ class Provisioning(unittest.TestCase):
         more_stan = pt.do_forms(self.getarg)
         self.fields["ownership_mode"] = "E"
         more_stan = pt.do_forms(self.getarg)
+
+    def test_provisioning_math(self):
+        self.failUnlessEqual(provisioning.binomial(10, 0), 1)
+        self.failUnlessEqual(provisioning.binomial(10, 1), 10)
+        self.failUnlessEqual(provisioning.binomial(10, 2), 45)
+        self.failUnlessEqual(provisioning.binomial(10, 9), 10)
+        self.failUnlessEqual(provisioning.binomial(10, 10), 1)
+
+DAY=24*60*60
+MONTH=31*DAY
+YEAR=365*DAY
+
+class Reliability(unittest.TestCase):
+    def test_basic(self):
+        if ReliabilityModel is None:
+            raise unittest.SkipTest("reliability model requires Numeric")
+        r = ReliabilityModel.run(delta=100000,
+                                 report_period=3*MONTH,
+                                 report_span=5*YEAR)
+        self.failUnlessEqual(len(r.samples), 20)
index 381441e8b7a4cf6d8e901f8c521e99c906f2e0a3..45a9401c3edb1d5ce8301dbb148592e29277444c 100644 (file)
@@ -5,7 +5,7 @@ from twisted.trial import unittest
 from twisted.internet import defer, reactor
 from twisted.web import client, error, http
 from twisted.python import failure, log
-from allmydata import interfaces, provisioning, uri, webish
+from allmydata import interfaces, uri, webish
 from allmydata.immutable import upload, download
 from allmydata.web import status, common
 from allmydata.util import fileutil, base32
@@ -415,13 +415,6 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
         d.addCallback(_check)
         return d
 
-    def test_provisioning_math(self):
-        self.failUnlessEqual(provisioning.binomial(10, 0), 1)
-        self.failUnlessEqual(provisioning.binomial(10, 1), 10)
-        self.failUnlessEqual(provisioning.binomial(10, 2), 45)
-        self.failUnlessEqual(provisioning.binomial(10, 9), 10)
-        self.failUnlessEqual(provisioning.binomial(10, 10), 1)
-
     def test_provisioning(self):
         d = self.GET("/provisioning/")
         def _check(res):
@@ -473,6 +466,35 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
         d.addCallback(_check4)
         return d
 
+    def test_reliability_tool(self):
+        try:
+            from allmydata import reliability
+            _hush_pyflakes = reliability
+        except:
+            raise unittest.SkipTest("reliability tool requires Numeric")
+
+        d = self.GET("/reliability/")
+        def _check(res):
+            self.failUnless('Tahoe Reliability Tool' in res)
+            fields = {'drive_lifetime': "8Y",
+                      "k": "3",
+                      "R": "7",
+                      "N": "10",
+                      "delta": "100000",
+                      "check_period": "1M",
+                      "report_period": "3M",
+                      "report_span": "5Y",
+                      }
+            return self.POST("/reliability/", **fields)
+
+        d.addCallback(_check)
+        def _check2(res):
+            self.failUnless('Tahoe Reliability Tool' in res)
+            r = r'Probability of loss \(no maintenance\):\s+<span>0.033591'
+            self.failUnless(re.search(r, res), res)
+        d.addCallback(_check2)
+        return d
+
     def test_status(self):
         dl_num = self.s.list_all_download_statuses()[0].get_counter()
         ul_num = self.s.list_all_upload_statuses()[0].get_counter()
index b91ed854c0adfe48fb4902a9f87d13eb98693176..72474f38c584ad92f7cd5775d21963bb8610eba5 100644 (file)
@@ -57,12 +57,8 @@ class ReliabilityTool(rend.Page):
         return parameters
 
     def renderHTTP(self, ctx):
-        print "renderHTTP"
-        print "two"
         self.parameters = self.get_parameters(ctx)
-        print "parms", self.parameters
         self.results = reliability.ReliabilityModel.run(**self.parameters)
-        print "got results"
         return rend.Page.renderHTTP(self, ctx)
 
     def make_input(self, name, old_value):