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
|
#!/usr/bin/env python
import threading
import hashlib
import string
import random
import utils.mojo_os_utils as mojo_os_utils
import utils.mojo_utils as mojo_utils
import sys
class ObjectPushPull(threading.Thread):
def __init__(self, runs, thread_name, payload_size='s'):
super(ObjectPushPull, self).__init__()
self.runs = runs
self.thread_name = thread_name
self.payload_size = payload_size
self.container = thread_name
self.sc = self.get_swiftclient()
self.sc.put_container(container=self.container)
self.successes = 0
self.failures = 0
def get_hash(self, rstring):
hash_object = hashlib.sha1(rstring)
return hash_object.hexdigest()
def get_test_string(self,):
# Large ~ 100Mb
sizes = {
's': 10000,
'm': 100000,
'l': 100000000,
}
root_str = random.choice(string.letters)
root_str += random.choice(string.letters)
return root_str*sizes[self.payload_size]
def run(self):
for i in range(0, self.runs):
test_string = self.get_test_string()
string_hash = self.get_hash(test_string)
test_file = 'testfile.' + self.thread_name
self.upload_file(test_file, test_string)
if self.verify_file(test_file, string_hash):
self.successes += 1
else:
self.failures += 1
def get_swiftclient(self):
keystone_session = mojo_os_utils.get_keystone_session(
mojo_utils.get_overcloud_auth())
swift_client = mojo_os_utils.get_swift_session_client(keystone_session)
return swift_client
def get_checkstring(self, fname):
return fname.split('-')[1]
def verify_file(self, fname, check_hash):
headers, content = self.sc.get_object(self.container, fname,
headers={'If-Match': self.etag})
return check_hash == self.get_hash(content)
def upload_file(self, fname, contents):
response = {}
self.sc.put_object(self.container, fname, contents,
response_dict=response)
self.etag = response['headers']['etag']
def main(argv):
thread1 = ObjectPushPull(10, 'thread1', payload_size='l')
thread2 = ObjectPushPull(100, 'thread2', payload_size='s')
thread1.start()
thread2.start()
thread1.join()
thread2.join()
print("Thread 1")
print(" Successes: {}".format(thread1.successes))
print(" Failures: {}".format(thread1.failures))
print("Thread 2")
print(" Successes: {}".format(thread2.successes))
print(" Failures: {}".format(thread2.failures))
if thread2.failures > 0:
sys.exit(1)
if __name__ == "__main__":
sys.exit(main(sys.argv))
|