-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest_nplusone.py
executable file
·150 lines (100 loc) · 3.76 KB
/
test_nplusone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import time
import socket
import tempfile
from ConfigParser import NoOptionError, NoSectionError
__doc__ = """ Add nfiles to a directory and check consistency.
"""
from smashbox.utilities import *
from smashbox.utilities.hash_files import *
from smashbox.utilities.monitoring import push_to_monitoring
nfiles = int(config.get('nplusone_nfiles',10))
filesize = config.get('nplusone_filesize',1000)
hostname = socket.gethostname()
hostname = str.split(hostname, '.cern.ch')[0]
try:
instance_name = config['instance_name']
except AttributeError:
instance_name = None
if instance_name is None:
source = 'cernbox.%s.nplusone' % hostname
else:
source = 'cernbox.%s.%s.nplusone' % (hostname,instance_name)
# optional fs check before files are uploaded by worker0
fscheck = config.get('nplusone_fscheck',False)
if type(filesize) is type(''):
filesize = eval(filesize)
testsets = [
{ 'nplusone_filesize': 1000,
'nplusone_nfiles':100
},
{ 'nplusone_filesize': OWNCLOUD_CHUNK_SIZE(0.3),
'nplusone_nfiles':10
},
{ 'nplusone_filesize': OWNCLOUD_CHUNK_SIZE(1.3),
'nplusone_nfiles':2
},
{ 'nplusone_filesize': OWNCLOUD_CHUNK_SIZE(3.5),
'nplusone_nfiles':1
},
{ 'nplusone_filesize': (3.5,1.37), # standard file distribution: 10^(3.5) Bytes
'nplusone_nfiles':10
},
]
@add_worker
def worker0(step):
# do not cleanup server files from previous run
reset_owncloud_account()
# cleanup all local files for the test
reset_rundir()
step(1,'Preparation')
d = make_workdir()
run_ocsync(d)
k0 = count_files(d)
step(2,'Add %s files and check if we still have k1+nfiles after resync'%nfiles)
total_size=0
sizes=[]
# compute the file sizes in the set
for i in range(nfiles):
size=size2nbytes(filesize)
sizes.append(size)
total_size+=size
time0=time.time()
logger.log(35,"Timestamp %f Files %d TotalSize %d",time.time(),nfiles,total_size)
# create the test files
for size in sizes:
create_hashfile(d,size=size)
if fscheck:
# drop the caches (must be running as root on Linux)
runcmd('echo 3 > /proc/sys/vm/drop_caches')
ncorrupt = analyse_hashfiles(d)[2]
fatal_check(ncorrupt==0, 'Corrupted files ON THE FILESYSTEM (%s) found'%ncorrupt)
run_ocsync(d)
ncorrupt = analyse_hashfiles(d)[2]
k1 = count_files(d)
error_check(k1-k0==nfiles,'Expecting to have %d files more: see k1=%d k0=%d'%(nfiles,k1,k0))
fatal_check(ncorrupt==0, 'Corrupted files (%s) found'%ncorrupt)
logger.info('SUCCESS: %d files found',k1)
step(4,"Final report")
time1 = time.time()
push_to_monitoring("%s.nfiles" % source,nfiles)
push_to_monitoring("%s.total_size" % source,total_size)
push_to_monitoring("%s.elapsed" % source,time1-time0)
push_to_monitoring("%s.total_size" % source,total_size)
push_to_monitoring("%s.transfer_rate" % source,total_size/(time1-time0))
push_to_monitoring("%s.worker0.synced_files" % source,k1-k0)
push_to_monitoring("%s.norm_synced_files" % source,float((k1-k0)/nfiles))
@add_worker
def worker1(step):
step(1,'Preparation')
d = make_workdir()
run_ocsync(d)
k0 = count_files(d)
step(3,'Resync and check files added by worker0')
run_ocsync(d)
ncorrupt = analyse_hashfiles(d)[2]
k1 = count_files(d)
push_to_monitoring("%s.worker1.synced_files" % source,k1-k0)
push_to_monitoring("%s.worker1.cor" % source,ncorrupt)
error_check(k1-k0==nfiles,'Expecting to have %d files more: see k1=%d k0=%d'%(nfiles,k1,k0))
fatal_check(ncorrupt==0, 'Corrupted files (%d) found'%ncorrupt) #Massimo 12-APR