-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbadnodes.py
93 lines (75 loc) · 2.85 KB
/
badnodes.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
#!/usr/bin/env python2
import os, random, pickle, time
# ------------------------------------------
# first things first - import fcp module
#Maybe randomize used nodes? Possibly increased perf...
import fcp
fcpHost = "127.0.0.1"
seedNodes = 2
openNodes = 50
monitorNodes = 5
badNodes = 10
lowestfcpport = 9481+seedNodes+openNodes+monitorNodes
highestfcpport = lowestfcpport + (badNodes-1)
#Empty textfiles that save said lists
putCHKs = []
if (os.path.isfile('./badjobs.txt')):
#putCHKs = pickle.load( open('./badjobs.txt', 'rb'))
with open('./badjobs.txt', 'rb') as f:
putCHKs = pickle.load(f)
dirList = os.listdir('./Bad')
def split(sequence, number_of_chunks):
if not sequence:
return []
chunk_size, remainder = divmod(len(sequence), number_of_chunks)
if chunk_size:
result = [sequence[x:x+chunk_size]
for x in xrange(0, number_of_chunks * chunk_size, chunk_size)]
else:
result = [[]]
if remainder:
result[-1].extend(sequence[-remainder:])
return result
def changefileset(fileList):
for sfile in fileList:
with open('./Bad/'+sfile, 'ab') as fout:
fout.write(str(random.getrandbits(1))) # replace 1024 with size_kb if not unreasonably large
return
#Calls changefileset and randomly add 10 elements of changed fileset
def putfiles(fileList):
jobs = []
changefileset(fileList)
print("Changing our bad files and adding 10 of 'em")
for i in range(10):
fcpPort = random.randint(lowestfcpport, highestfcpport)
node = fcp.FCPNode(host=fcpHost, port = fcpPort, verbosity=fcp.FATAL)
sfile = random.choice(fileList)
job = node.put('CHK@', file = './Bad/'+sfile, async = True)
jobs.append(job)
for job in jobs:
print("waiting for our bad inserts to settle")
putCHKs.append(job.wait())
return
changefileset(dirList)
jobs = []
for item in dirList:
print("Being bad with " + item)
fcpPort = random.randint(lowestfcpport, highestfcpport)
node = fcp.FCPNode(host=fcpHost, port = fcpPort, verbosity=fcp.FATAL)
job = node.put('CHK@', file = './Bad/'+item, async = True)
jobs.append(job)
for job in jobs:
print("Waiting for CHK")
putCHKs.append(job.wait())
#pickle.dump(putCHKs, open('./badjobs.txt', 'w'))
with open('./badjobs.txt', 'wb') as f:
pickle.dump(putCHKs, f)
while True:
print("We arrived in the endless badlands (We are calling our inserts and inserting 10 new ones at the end)")
for CHK in putCHKs:
fcpPort = random.randint(lowestfcpport, highestfcpport)
node = fcp.FCPNode(host=fcpHost, port = fcpPort, verbosity=fcp.FATAL)
node.get(CHK, async = True, timeout = 360, ignoreDS = True)
print("Tried to get each of our corrupted files!")
putfiles(dirList)
time.sleep(random.randint(3, 10))