-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdssSanityLib.py
executable file
·254 lines (214 loc) · 7.36 KB
/
dssSanityLib.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import re
import sys
import time
import boto
import getopt
from boto.s3.key import Key
from boto.s3.connection import S3Connection
###################### INIT ########################
# PARAMS
GLOBAL_DEBUG = 1
MULTIPART_LARGE_FILE = ''
#RADOSHOST = 'dss.ind-west-1.internal.jiocloudservices.com'
#RADOSPORT = 443
#isSecure = True
RADOSHOST = 'dss.ind-west-1.staging.jiocloudservices.com'
RADOSPORT = 443
isSecure = True
#RADOSHOST = '10.140.214.199'
#RADOSPORT = 7480
#isSecure = False
#RADOSHOST = '127.0.0.1'
#RADOSPORT = 8000
#isSecure = False
#RADOSHOST = '10.140.208.225'
#RADOSPORT = 443
#isSecure = True
CLI_USER = ''
CLI_COMMAND = ''
COMMAND_NUM = ''
COMMAND_TARG = ''
# ACCESS PARAMS
access_key = ''
secret_key = ''
user_profiles = None
isAwsConn = False
has_incore_params = False
####################################################
################## CREATE CONNECTION ###############
def getConnection(user = None):
global has_incore_params
global access_key
global secret_key
global user_profiles
if (user is not None) and (user_profiles is not None):
try:
access_key = user_profiles[user]['access']
secret_key = user_profiles[user]['secret']
except:
print "Must have dsskeys file for multiuser access!"
return -1
conn_obj = None
if (has_incore_params and (GLOBAL_DEBUG == 1)):
conn_obj = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = RADOSHOST,
port = RADOSPORT,
is_secure = isSecure,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
debug = 2,
)
elif (has_incore_params and (GLOBAL_DEBUG == 0)):
conn_obj = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = RADOSHOST,
port = RADOSPORT,
is_secure = isSecure,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
elif (has_incore_params and isAwsConn):
conn_obj = S3Connection(access_key, secret_key)
else:
return -1
return conn_obj
####################################################
############### INFO PRESENTATION ##################
def whisper(mystr):
if GLOBAL_DEBUG == 1:
print "DEBUG: " + mystr
return
def callTest(output, testname):
if output != 0:
print "\n\t=====================================\n\t" + testname + " : Failed"
else:
print "\n\t=====================================\n\t" + testname + " : Pass"
print "\t=====================================\n\n"
return
####################################################
############### DATA POPULATION ####################
def createMaxBuckets(num, buckpref, user = None):
obj = getConnection(user)
listBucketNum(obj, "User")
whisper("Creating new buckets")
for i in range(1, num + 1):
name = buckpref + str(i)
buck = obj.create_bucket(name)
whisper("Creating bucket " + name)
for j in range(1, 11):
k = Key(buck)
k.key = name + '_OBJ_' + str(j)
whisper("Creating object " + k.key)
k.set_contents_from_string('Data for obj ' + str(j))
return;
####################################################
############## CLEANUP AND LISTING #################
def cleanupUser(userObj, patstr = None):
whisper("Cleaning up...")
if (patstr):
pstring = patstr + '*'
else:
pstring = '*'
pattern = re.compile(pstring)
for bkt in userObj.get_all_buckets():
if (pattern.match(bkt.name)) or (not patstr):
for k in bkt.list():
whisper("Deleting " + str(k))
k.delete()
whisper("Deleting bucket " + str(bkt))
userObj.delete_bucket(bkt.name)
listBucket(userObj, "User")
return
def listBucketNum(userObj, uname):
print "Total number of buckets for " + uname + ": " + str(len(userObj.get_all_buckets()))
return
def listBucket(userObj, uname):
print "Listing buckets for " + uname
for bucket in userObj.get_all_buckets():
print "{name}\t{created}".format(name = bucket.name, created = bucket.creation_date)
return
####################################################
############## KEEP CHANGING ACLS ##################
def keepChangingAcls(bucket):
obj = getConnection()
acl_list = ('public-read', 'private')
for i in range(1, 11):
b1 = obj.get_bucket(bucket)
whisper("Changing ACL to " + str(acl_list[i % 2]))
b1.set_acl(acl_list[i % 2])
time.sleep(1)
return
####################################################
################ BUCKET NAME GEN ###################
def getsNewBucketName(pref = None):
ts = time.time()
str_ts = str(ts)
index = str_ts.find('.')
str_ts = str_ts[0:index]
if pref is None:
bucketpref = 'rjilbucketsanity' + str_ts
else:
bucketpref = str(pref) + str_ts
return bucketpref
####################################################
################# CLI ARGUMENTS ####################
def fetchArgs(argv):
global has_incore_params
global access_key
global secret_key
global user_profiles
global CLI_USER
global CLI_COMMAND
global COMMAND_NUM
global COMMAND_TARG
try:
opts, args = getopt.getopt(argv,"a:s:h:i:c:n:t:u",["access-key=","secret-key=","ifile=","command=","number=","target=","user="])
except getopt.GetoptError:
printsHelp()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
printsHelp()
sys.exit()
elif opt in ("-c", "--command"):
CLI_COMMAND = arg
elif opt in ("-n", "--number"):
COMMAND_NUM = arg
elif opt in ("-t", "--target"):
COMMAND_TARG = arg
elif opt in ("-u", "--user"):
CLI_USER = arg
elif opt in ("-i", "--ifile"):
try:
import dsskeys
has_incore_params = True
access_key = dsskeys.access_key
secret_key = dsskeys.secret_key
user_profiles = dsskeys.user_profiles
except ImportError:
print "Error: Failed to import dsskeys from file. Make sure that the file is present."
elif opt in ("-a", "--access-key"):
has_incore_params = True
access_key = arg
elif opt in ("-s", "--secret-key"):
print "Sending secret key using command line is unsafe. Use dsskeys file."
print "Sleeping for 5 seconds before continuing..."
time.sleep(5)
secret_key = arg
if (not has_incore_params):
printsHelp()
return -1
return 0
def printsHelp():
print "HELP"
print "===="
print '<Test script> {-a <Access Key> -s <Secret Key>} or {-i True (To read from dsskeys)}'
print '<Test script> {--access-key <Access Key> --secret-key <Secret Key>} or { --ifile True (To read from dsskeys)}'
print "\nDSSKEYS FILE"
print "============"
print "Make a file called dsskeys.py and put inside it:"
print " access_key = \'<value>\'"
print " secret_key = \'<value>\'"
return
####################################################