-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_webdav_performance.py
305 lines (262 loc) · 12.8 KB
/
test_webdav_performance.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
""" Testing WebDavPerformance functions for Sunet Drive
Author: Richard Freitag <freitag@sunet.se>
"""
import unittest
import tempfile
import requests
from requests.auth import HTTPBasicAuth
import json
import os
from webdav3.client import Client
from webdav3.exceptions import WebDavException
import logging
import threading
import time
import sys
from datetime import datetime
import xmlrunner
import sunetnextcloud
g_maxCheck = 10
g_WebDavPerformance_timeout = 30
g_testFolder = 'WebDavPerformanceTest'
g_stressTestFolder = 'WebDavPerformanceStressTest'
g_sharedTestFolder = 'SharedFolder'
g_personalBucket = 'selenium-personal'
g_systemBucket = 'selenium-system'
g_filename=datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
g_davPerformanceResults = []
g_testPassed = {}
g_testThreadsRunning = 0
ocsheaders = { "OCS-APIRequest" : "true" }
logger = logging.getLogger(__name__)
logging.basicConfig(format = '%(asctime)s - %(module)s.%(funcName)s - %(levelname)s: %(message)s',
datefmt = '%Y-%m-%d %H:%M:%S', level = logging.INFO)
def excepthook(args):
logger.error(f'Threading exception: {args}')
decreaseUploadCount()
sys.excepthook(*sys.exc_info())
threading.excepthook = excepthook
def decreaseUploadCount():
global g_testThreadsRunning
g_testThreadsRunning -= 1
def webdavUpload(client, local_path, remote_path):
global logger, g_testThreadsRunning
logger.info(f'Upload {local_path}')
if client == None:
logger.error(f'No client provided')
decreaseUploadCount()
return
if local_path == None:
logger.error(f'No filename provided')
decreaseUploadCount()
return
if remote_path == None:
logger.error(f'No target filename provided')
decreaseUploadCount()
return
try:
client.upload_sync(remote_path=remote_path,local_path=local_path)
except Exception as error:
logger.error(f'Error uploading {remote_path}:{error}')
decreaseUploadCount()
return
decreaseUploadCount()
def webdavClean(client, filename):
global logger, g_testThreadsRunning
if client == None:
logger.error(f'No client provided')
return
if filename == None:
logger.error(f'No filename provided')
return
logger.info(f'Cleaning {filename}')
client.clean(filename)
class TestWebDavPerformance(unittest.TestCase):
def test_logger(self):
global logger
logger.info(f'TestID: {self._testMethodName}')
pass
def test_basic_performance(self):
global logger, g_testThreadsRunning, g_davPerformanceResults
numFiles = 100
maxUploads = 4
maxDeletes = 8
drv = sunetnextcloud.TestTarget()
for fullnode in drv.fullnodes:
with self.subTest(mynode=fullnode):
logger.info(f'TestID: {fullnode}')
nodeuser = drv.get_seleniumuser(fullnode)
nodepwd = drv.get_seleniumuserpassword(fullnode)
url = drv.get_webdav_url(fullnode, nodeuser)
logger.info(f'URL: {url}')
options = {
'webdav_hostname': url,
'webdav_login' : nodeuser,
'webdav_password' : nodepwd,
'webdav_timeout': g_WebDavPerformance_timeout
}
client = Client(options)
logger.info(client.list())
client.mkdir('performance')
logger.info(f'Generate local files')
files = []
for i in range(0,numFiles):
filename = f'{fullnode}{str(i)}.bin'
pathname = f'{tempfile.gettempdir()}/{filename}'
fileSizeInBytes = 102400
with open(pathname, 'wb') as fout:
fout.write(os.urandom(fileSizeInBytes))
files.append(filename)
startTime = datetime.now()
logger.info(f'Async upload of {maxUploads} files concurrently')
try:
for i in range(0,numFiles,maxUploads):
x = i
logger.info(f'Batch upload {files[x:x+maxUploads]}')
for file in files[x:x+maxUploads]:
try:
g_testThreadsRunning += 1
client.upload_async(remote_path=f'performance/{file}',local_path=f'{tempfile.gettempdir()}/{file}', callback=decreaseUploadCount)
except WebDavException as exception:
logger.info(f'Error uploading {filename}: {exception}')
g_testThreadsRunning -= 1
while g_testThreadsRunning > 0:
time.sleep(0.01)
endTime = datetime.now()
except:
logger.error(f'Error during async upload')
# Calculate time to upload
uploadTime = (endTime - startTime).total_seconds()
# Remove the temporary files
logger.info(f'Remove temporary files')
for i in range(0,numFiles):
filename = f'{tempfile.gettempdir()}/{fullnode}{str(i)}.bin'
os.remove(filename)
davElements = client.list('performance')
logger.info(f'{davElements}')
davElements.pop(0)
startTime = datetime.now()
for i in range(0,len(davElements),maxDeletes):
x = i
logger.info(f'Batch delete {davElements[x:x+maxDeletes]}')
for element in davElements[x:x+maxDeletes]:
t = threading.Thread(target=client.clean, args=['performance/' + element])
t.start()
while threading.active_count() > 1:
time.sleep(0.01)
# This works for single threaded delete
# for element in davElements:
# logger.info(f'Delete {element}')
# try:
# client.clean('performance/' + element)
# except:
# logger.info(f'Error deleting {element}')
deleteTime = (datetime.now() - startTime).total_seconds()
lText = f'{fullnode} '
mText = f'Upload: {uploadTime:.1f}s at {uploadTime/numFiles:.2f} s/file'
rText = f'Delete: {deleteTime:.1f}s at {deleteTime/numFiles:.2f} s/file'
message = f'{lText : <16}{mText : <40}{rText : <40}'
# message = f'{fullnode} - Upload: {uploadTime:.1f}s at {uploadTime/numFiles:.2f} s/file - Delete: {deleteTime:.1f}s at {deleteTime/numFiles:.2f} s/file'
logger.info(f'{message}')
g_davPerformanceResults.append(message)
logger.info(f'Results for {numFiles} with max {maxUploads} concurrent uploads and max {maxDeletes} concurrent deletes')
for message in g_davPerformanceResults:
logger.info(f'{message}')
logger.info(f'Done')
pass
def test_file_sizes(self):
global logger, g_testThreadsRunning, g_davPerformanceResults
numFiles = 1
maxUploads = 1
maxDeletes = 1
# fileSizes=[1,10,100,1024,10240,102400,1024000,10240000,102400000,204800000]
fileSizes=[102400000,204800000]
drv = sunetnextcloud.TestTarget()
for fullnode in drv.fullnodes:
with self.subTest(mynode=fullnode):
logger.info(f'TestID: {fullnode}')
nodeuser = drv.get_seleniumuser(fullnode)
nodepwd = drv.get_seleniumuserpassword(fullnode)
url = drv.get_webdav_url(fullnode, nodeuser)
logger.info(f'URL: {url}')
options = {
'webdav_hostname': url,
'webdav_login' : nodeuser,
'webdav_password' : nodepwd,
'webdav_timeout': g_WebDavPerformance_timeout
}
client = Client(options)
logger.info(client.list())
targetDir='selenium-system/TestWebDavPerformance_file_sizes'
client.mkdir(targetDir)
for fileSize in fileSizes:
logger.info(f'Generate local files')
files = []
for i in range(0,numFiles):
filename = f'{fullnode}{str(i)}_{str(fileSize)}.bin'
pathname = f'{tempfile.gettempdir()}/{filename}'
fileSizeInBytes = fileSize
with open(pathname, 'wb') as fout:
fout.write(os.urandom(fileSizeInBytes))
files.append(filename)
startTime = datetime.now()
logger.info(f'Async upload of {maxUploads} files concurrently')
try:
for i in range(0,numFiles,maxUploads):
x = i
logger.info(f'Batch upload {files[x:x+maxUploads]}')
for file in files[x:x+maxUploads]:
try:
g_testThreadsRunning += 1
client.upload_async(remote_path=f'{targetDir}/{file}',local_path=f'{tempfile.gettempdir()}/{file}', callback=decreaseUploadCount)
# client.upload_sync(remote_path=f'{targetDir}/{file}',local_path=f'{tempfile.gettempdir()}/{file}', callback=decreaseUploadCount)
except WebDavException as exception:
logger.error(f'Error uploading {filename}: {exception}')
g_testThreadsRunning -= 1
while g_testThreadsRunning > 0:
time.sleep(0.01)
endTime = datetime.now()
except Exception as error:
logger.error(f'Error during async upload: {error}')
# Calculate time to upload
uploadTime = (endTime - startTime).total_seconds()
# Remove the temporary files
logger.info(f'Remove temporary files')
for i in range(0,numFiles):
filename = f'{tempfile.gettempdir()}/{fullnode}{str(i)}_{str(fileSize)}.bin'
os.remove(filename)
davElements = client.list(targetDir)
logger.info(f'{davElements}')
davElements.pop(0)
startTime = datetime.now()
# Batch delete files
# for i in range(0,len(davElements),maxDeletes):
# x = i
# logger.info(f'Batch delete {davElements[x:x+maxDeletes]}')
# for element in davElements[x:x+maxDeletes]:
# t = threading.Thread(target=client.clean, args=[f'{targetDir}/{element}'])
# t.start()
# while threading.active_count() > 1:
# time.sleep(0.01)
# This works for single threaded delete
# for element in davElements:
# logger.info(f'Delete {element}')
# try:
# client.clean('performance/' + element)
# except:
# logger.info(f'Error deleting {element}')
deleteTime = (datetime.now() - startTime).total_seconds()
lText = f'{fullnode} '
mText = f'Size: {fileSize}'
rText = f'Upload: {uploadTime:.1f}s'
message = f'{lText : <16}{mText : <40}{rText : <40}'
# message = f'{fullnode} - Upload: {uploadTime:.1f}s at {uploadTime/numFiles:.2f} s/file - Delete: {deleteTime:.1f}s at {deleteTime/numFiles:.2f} s/file'
logger.info(f'{message}')
g_davPerformanceResults.append(message)
logger.info(f'Results for {numFiles} with max {maxUploads} concurrent uploads and max {maxDeletes} concurrent deletes')
for message in g_davPerformanceResults:
logger.info(f'{message}')
logger.info(f'Done')
pass
if __name__ == '__main__':
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))