-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsanity_tests.py
218 lines (179 loc) · 7.33 KB
/
sanity_tests.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import os
import sys
import time
import math
import dssSanityLib
from boto.s3.key import Key
from filechunkio import FileChunkIO
############### MAX BUCKET LIMIT ###################
def bucketSanity():
## Create five buckets
dssSanityLib.whisper("Creating five test buckets and putting objects in them...")
bucketpref = dssSanityLib.getsNewBucketName()
dssSanityLib.createMaxBuckets(5, bucketpref)
## Bucket name conflict during creation
#dssSanityLib.whisper("Trying to create a bucket with name conflict...")
#userObj = dssSanityLib.getConnection(1) ## Different user
#buck_str = bucketpref + '1'
#try:
#b = userObj.create_bucket(buck_str)
#print "Error: Unexpectedly created bucket " + buck_str
#return -1
#except:
# print "Expected failure: " + str(sys.exc_info())
## Delete all buckets
try:
userObj = dssSanityLib.getConnection()
dssSanityLib.whisper("Deleting the test buckets...")
dssSanityLib.cleanupUser(userObj, bucketpref)
except:
print "Unexpected failure: " + str(sys.exc_info())
return -1
return 0
####################################################
############### MULTI PART UPLOAD ##################
def multipartObjectUpload():
result = 0
dssSanityLib.whisper("Making bucket and listing...")
userObj = dssSanityLib.getConnection()
bucketpref = dssSanityLib.getsNewBucketName()
b = userObj.create_bucket(bucketpref)
#b.set_acl('public-read-write')
##dssSanityLib.listBucket(userObj, "User")
source_path = dssSanityLib.MULTIPART_LARGE_FILE
source_size = os.stat(source_path).st_size
chunk_size = 5242880 ## 5 mb
#chunk_size = 1048576 ## 1 mb
chunk_count = int(math.ceil(source_size / float(chunk_size)))
b1 = userObj.get_bucket(bucketpref)
dssSanityLib.whisper("Got bucket: " + str(b1))
try:
mp = b1.initiate_multipart_upload(os.path.basename(source_path))
for i in range(chunk_count):
dssSanityLib.whisper("Uploading chunk: " + str(i))
offset = chunk_size * i
bytes = min(chunk_size, source_size - offset)
with FileChunkIO(source_path, 'r', offset=offset, bytes=bytes) as fp:
mp.upload_part_from_file(fp, part_num=i + 1)
time.sleep(2)
for i in b1.list_multipart_uploads():
print "list_multipart_uploads: " + str(i)
for i in b1.get_all_multipart_uploads():
print "get_all_multipart_uploads: " + str(i)
print("\n\nCompleting uploads")
resp = mp.complete_upload()
print "\n\n" + str(resp.etag) + "\n\n"
#print("\n\nCancelling uploads")
#mp.cancel_upload()
except:
print "Unexpected error during multipart upload: ", sys.exc_info()
result = -1
dssSanityLib.cleanupUser(userObj, bucketpref)
return result
####################################################
#################### DNS TESTS ####################
def dnsNamesTest():
userObj = dssSanityLib.getConnection()
result = 0
longHundredChars = 'a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789a123456789'
longFiftyChars = 'a123456789a123456789a123456789a123456789a123456789'
longTFTchars = longHundredChars + longHundredChars + longFiftyChars + 'qwe'
try:
userObj.create_bucket(longTFTchars)
userObj.delete_bucket(longTFTchars)
print "Able to create bucket with 253 chars in name"
except:
print "Failed to create or delete a valid bucket name"
print "Unexpected error: ", sys.exc_info()
return -1
try:
badName = longTFTchars + 'abc'
userObj.create_bucket(badName)
print "Unexpectedly created bucket with illegally long name"
dssSanityLib.listBucketNum(userObj, "user")
dssSanityLib.listBucket(userObj, "user")
userObj.delete_bucket(badName)
result = -1
except:
print "Expected failure in creating 256 char bucket name"
print "Expected error: ", sys.exc_info()
try:
badName = 'Abc'
userObj.create_bucket(badName)
print "Unexpectedly created bucket with capital letter name"
dssSanityLib.listBucketNum(userObj, "user")
dssSanityLib.listBucket(userObj, "user")
userObj.delete_bucket(badName)
result = -1
except:
print "Expected failure in creating bucket name with CAPS"
print "Expected error: ", sys.exc_info()
try:
badName = 'bc/'
userObj.create_bucket(badName)
print "Unexpectedly created bucket with slash in name"
dssSanityLib.listBucketNum(userObj, "user")
dssSanityLib.listBucket(userObj, "user")
userObj.delete_bucket(badName)
result = -1
except:
print "Expected failure in creating bucket name with slash"
print "Expected error: ", sys.exc_info()
return result
####################################################
################ PUBLIC URL TESTS ##################
def publicUrlTest():
result = 0
userObj = dssSanityLib.getConnection()
bucketpref = dssSanityLib.getsNewBucketName()
b1 = userObj.create_bucket(bucketpref)
#print "Setting ACL on bucket"
#b1.set_acl('public-read')
k = Key(b1)
k.key = 'userObj1'
k.set_contents_from_string('Data of URL object')
#print "Setting ACL on obj"
#k.set_acl('public-read')
m = Key(b1)
m.key = 'userObj1'
urlname = m.generate_url(1000)
print "\nThe userObj URL is: " + str(urlname)
urlname = b1.generate_url(10000)
print "\nThe bucket URL is: " + str(urlname)
#for i in range(1, 21):
# time.sleep(1)
# if i % 5 == 0:
# print str(20 - i) + " Seconds left before Obj deletion"
#m.delete()
#print "Object deleted\n"
#for i in range(1, 21):
# time.sleep(1)
# if i % 5 == 0:
# print str(20 - i) + " Seconds left before bucket deletion"
#userObj.delete_bucket(bucketpref)
#print "Bucket deleted\n"
return result
####################################################
###################### MAIN ########################
def main(argv):
## PARAM OVERRIDES
#dssSanityLib.MULTIPART_LARGE_FILE = '/boot/initrd.img-3.13.0-24-generic' # Need a large file to upload in multiparts.
dssSanityLib.MULTIPART_LARGE_FILE = 'tput.dat' # Need a large file to upload in multiparts.
dssSanityLib.GLOBAL_DEBUG = 1 # The lib supresses debug logs by default. Override here.
##dssSanityLib.RADOSHOST = '127.0.0.1' # The lib points to DSS staging endpoint by default. Override here.
##dssSanityLib.RADOSPORT = 7480 # The lib points to DSS staging endpoint by default. Override here.
ret = dssSanityLib.fetchArgs(argv)
if(ret == -1):
sys.exit(2)
## TESTCASES
#dssSanityLib.callTest(bucketSanity(), "Create buckets and objects then delete them")
dssSanityLib.callTest(multipartObjectUpload(), "Upload object in Multiparts")
#dssSanityLib.callTest(dnsNamesTest(), "Check various DNS name rules")
#dssSanityLib.callTest(publicUrlTest(), "Public URL test")
## CLEANUP
userObj = dssSanityLib.getConnection()
#dssSanityLib.cleanupUser(userObj, 'rjilbucketsanity')
return
if __name__ == "__main__":
main(sys.argv[1:])
####################################################