mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-05-01 16:30:14 +00:00
provisioning/reliability: add tests, hush pyflakes, remove dead code, fix web links
This commit is contained in:
parent
e1380b132b
commit
cc27b218f5
@ -709,7 +709,9 @@ class ProvisioningTool(rend.Page):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from allmydata import reliability
|
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:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -19,9 +19,6 @@ def my_dot(v1, v2):
|
|||||||
#for i in range(v1.shape[1]):
|
#for i in range(v1.shape[1]):
|
||||||
return Numeric.sum(Numeric.sum(v1*v2))
|
return Numeric.sum(Numeric.sum(v1*v2))
|
||||||
|
|
||||||
def yandm(seconds):
|
|
||||||
return "%dy.%dm" % (int(seconds/YEAR), int( (seconds%YEAR)/MONTH))
|
|
||||||
|
|
||||||
class ReliabilityModel:
|
class ReliabilityModel:
|
||||||
"""Generate a model of system-wide reliability, given several input
|
"""Generate a model of system-wide reliability, given several input
|
||||||
parameters.
|
parameters.
|
||||||
@ -152,6 +149,8 @@ class ReliabilityModel:
|
|||||||
cumulative_number_of_new_shares,
|
cumulative_number_of_new_shares,
|
||||||
P_dead_unmaintained, P_dead_maintained)
|
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_repairs_total = sum(needed_repairs)
|
||||||
#needed_new_shares_total = sum(needed_new_shares)
|
#needed_new_shares_total = sum(needed_new_shares)
|
||||||
#print "at 2y:"
|
#print "at 2y:"
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from allmydata.provisioning import ProvisioningTool
|
from allmydata import provisioning
|
||||||
#from nevow.context import PageContext, RequestContext
|
ReliabilityModel = None
|
||||||
|
try:
|
||||||
|
from allmydata.reliability import ReliabilityModel
|
||||||
|
except ImportError:
|
||||||
|
pass # might not be importable, since it needs Numeric
|
||||||
|
|
||||||
from nevow import inevow
|
from nevow import inevow
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
|
||||||
@ -16,7 +21,7 @@ class Provisioning(unittest.TestCase):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def test_load(self):
|
def test_load(self):
|
||||||
pt = ProvisioningTool()
|
pt = provisioning.ProvisioningTool()
|
||||||
self.fields = {}
|
self.fields = {}
|
||||||
#r = MyRequest()
|
#r = MyRequest()
|
||||||
#r.fields = self.fields
|
#r.fields = self.fields
|
||||||
@ -50,3 +55,23 @@ class Provisioning(unittest.TestCase):
|
|||||||
more_stan = pt.do_forms(self.getarg)
|
more_stan = pt.do_forms(self.getarg)
|
||||||
self.fields["ownership_mode"] = "E"
|
self.fields["ownership_mode"] = "E"
|
||||||
more_stan = pt.do_forms(self.getarg)
|
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)
|
||||||
|
@ -5,7 +5,7 @@ from twisted.trial import unittest
|
|||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, reactor
|
||||||
from twisted.web import client, error, http
|
from twisted.web import client, error, http
|
||||||
from twisted.python import failure, log
|
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.immutable import upload, download
|
||||||
from allmydata.web import status, common
|
from allmydata.web import status, common
|
||||||
from allmydata.util import fileutil, base32
|
from allmydata.util import fileutil, base32
|
||||||
@ -415,13 +415,6 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check)
|
d.addCallback(_check)
|
||||||
return d
|
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):
|
def test_provisioning(self):
|
||||||
d = self.GET("/provisioning/")
|
d = self.GET("/provisioning/")
|
||||||
def _check(res):
|
def _check(res):
|
||||||
@ -473,6 +466,35 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check4)
|
d.addCallback(_check4)
|
||||||
return d
|
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):
|
def test_status(self):
|
||||||
dl_num = self.s.list_all_download_statuses()[0].get_counter()
|
dl_num = self.s.list_all_download_statuses()[0].get_counter()
|
||||||
ul_num = self.s.list_all_upload_statuses()[0].get_counter()
|
ul_num = self.s.list_all_upload_statuses()[0].get_counter()
|
||||||
|
@ -57,12 +57,8 @@ class ReliabilityTool(rend.Page):
|
|||||||
return parameters
|
return parameters
|
||||||
|
|
||||||
def renderHTTP(self, ctx):
|
def renderHTTP(self, ctx):
|
||||||
print "renderHTTP"
|
|
||||||
print "two"
|
|
||||||
self.parameters = self.get_parameters(ctx)
|
self.parameters = self.get_parameters(ctx)
|
||||||
print "parms", self.parameters
|
|
||||||
self.results = reliability.ReliabilityModel.run(**self.parameters)
|
self.results = reliability.ReliabilityModel.run(**self.parameters)
|
||||||
print "got results"
|
|
||||||
return rend.Page.renderHTTP(self, ctx)
|
return rend.Page.renderHTTP(self, ctx)
|
||||||
|
|
||||||
def make_input(self, name, old_value):
|
def make_input(self, name, old_value):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user