source: trunk/misc/operations_helpers/provisioning/test_provisioning.py

Last change on this file was b856238, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-15T15:53:34Z

remove old Python2 future statements

  • Property mode set to 100644
File size: 4.1 KB
Line 
1
2import unittest
3from allmydata import provisioning
4ReliabilityModel = None
5try:
6    from allmydata.reliability import ReliabilityModel
7except ImportError:
8    pass # might not be importable, since it needs NumPy
9
10from nevow import inevow
11from zope.interface import implements
12
13class MyRequest(object):
14    implements(inevow.IRequest)
15    pass
16
17class Provisioning(unittest.TestCase):
18    def getarg(self, name, astype=int):
19        if name in self.fields:
20            return astype(self.fields[name])
21        return None
22
23    def test_load(self):
24        pt = provisioning.ProvisioningTool()
25        self.fields = {}
26        #r = MyRequest()
27        #r.fields = self.fields
28        #ctx = RequestContext()
29        #unfilled = pt.renderSynchronously(ctx)
30        lots_of_stan = pt.do_forms(self.getarg)
31        self.failUnless(lots_of_stan is not None)
32
33        self.fields = {'filled': True,
34                       "num_users": 50e3,
35                       "files_per_user": 1000,
36                       "space_per_user": 1e9,
37                       "sharing_ratio": 1.0,
38                       "encoding_parameters": "3-of-10-5",
39                       "num_servers": 30,
40                       "ownership_mode": "A",
41                       "download_rate": 100,
42                       "upload_rate": 10,
43                       "delete_rate": 10,
44                       "lease_timer": 7,
45                       }
46        #filled = pt.renderSynchronously(ctx)
47        more_stan = pt.do_forms(self.getarg)
48        self.failUnless(more_stan is not None)
49
50        # trigger the wraparound configuration
51        self.fields["num_servers"] = 5
52        #filled = pt.renderSynchronously(ctx)
53        more_stan = pt.do_forms(self.getarg)
54
55        # and other ownership modes
56        self.fields["ownership_mode"] = "B"
57        more_stan = pt.do_forms(self.getarg)
58        self.fields["ownership_mode"] = "E"
59        more_stan = pt.do_forms(self.getarg)
60
61    def test_provisioning_math(self):
62        self.failUnlessEqual(provisioning.binomial(10, 0), 1)
63        self.failUnlessEqual(provisioning.binomial(10, 1), 10)
64        self.failUnlessEqual(provisioning.binomial(10, 2), 45)
65        self.failUnlessEqual(provisioning.binomial(10, 9), 10)
66        self.failUnlessEqual(provisioning.binomial(10, 10), 1)
67
68DAY=24*60*60
69MONTH=31*DAY
70YEAR=365*DAY
71
72class Reliability(unittest.TestCase):
73    def test_basic(self):
74        if ReliabilityModel is None:
75            raise unittest.SkipTest("reliability model requires NumPy")
76
77        # test that numpy math works the way I think it does
78        import numpy
79        decay = numpy.matrix([[1,0,0],
80                             [.1,.9,0],
81                             [.01,.09,.9],
82                             ])
83        start = numpy.array([0,0,1])
84        g2 = (start * decay).A[0]
85        self.failUnlessEqual(repr(g2), repr(numpy.array([.01,.09,.9])))
86        g3 = (g2 * decay).A[0]
87        self.failUnlessEqual(repr(g3), repr(numpy.array([.028,.162,.81])))
88
89        # and the dot product
90        recoverable = numpy.array([0,1,1])
91        P_recoverable_g2 = numpy.dot(g2, recoverable)
92        self.failUnlessAlmostEqual(P_recoverable_g2, .9 + .09)
93        P_recoverable_g3 = numpy.dot(g3, recoverable)
94        self.failUnlessAlmostEqual(P_recoverable_g3, .81 + .162)
95
96        r = ReliabilityModel.run(delta=100000,
97                                 report_period=3*MONTH,
98                                 report_span=5*YEAR)
99        self.failUnlessEqual(len(r.samples), 20)
100
101        last_row = r.samples[-1]
102        #print(last_row)
103        (when, unmaintained_shareprobs, maintained_shareprobs,
104         P_repaired_last_check_period,
105         cumulative_number_of_repairs,
106         cumulative_number_of_new_shares,
107         P_dead_unmaintained, P_dead_maintained) = last_row
108        self.failUnless(isinstance(P_repaired_last_check_period, float))
109        self.failUnless(isinstance(P_dead_unmaintained, float))
110        self.failUnless(isinstance(P_dead_maintained, float))
111        self.failUnlessAlmostEqual(P_dead_unmaintained, 0.033591004555395272)
112        self.failUnlessAlmostEqual(P_dead_maintained, 3.2983995819177542e-08)
113
114if __name__=='__main__':
115    unittest.main()
Note: See TracBrowser for help on using the repository browser.