From: Brian Warner Date: Sun, 15 Feb 2009 23:24:51 +0000 (-0700) Subject: provisioning/reliability: add tests, hush pyflakes, remove dead code, fix web links X-Git-Tag: allmydata-tahoe-1.4.0~221 X-Git-Url: https://git.rkrishnan.org/pf/content/en/nxhtml.html?a=commitdiff_plain;h=cc27b218f5e8064ad8792c18f05b498137beaead;p=tahoe-lafs%2Ftahoe-lafs.git provisioning/reliability: add tests, hush pyflakes, remove dead code, fix web links --- diff --git a/src/allmydata/provisioning.py b/src/allmydata/provisioning.py index 42986dba..3c30418c 100644 --- a/src/allmydata/provisioning.py +++ b/src/allmydata/provisioning.py @@ -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 diff --git a/src/allmydata/reliability.py b/src/allmydata/reliability.py index 5db6a1f2..ecbd7c08 100644 --- a/src/allmydata/reliability.py +++ b/src/allmydata/reliability.py @@ -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:" diff --git a/src/allmydata/test/test_provisioning.py b/src/allmydata/test/test_provisioning.py index 64fbeec3..ec99961e 100644 --- a/src/allmydata/test/test_provisioning.py +++ b/src/allmydata/test/test_provisioning.py @@ -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) diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 381441e8..45a9401c 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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+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() diff --git a/src/allmydata/web/reliability.py b/src/allmydata/web/reliability.py index b91ed854..72474f38 100644 --- a/src/allmydata/web/reliability.py +++ b/src/allmydata/web/reliability.py @@ -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):