Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locking tests rebasedmaster #133

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d6daf0e
Add pyocaction to the utilities to use pyocclient
jvillafanez Jun 8, 2015
2950647
Improved pyocaction method
jvillafanez Jun 8, 2015
fb1abe2
WIP: First approach to files_locking app testing
jvillafanez Jun 8, 2015
a96bdd3
Add support for the testsets
jvillafanez Jun 9, 2015
ac49516
Add some more test cases
jvillafanez Jun 9, 2015
c9f617e
Add documentation
jvillafanez Jun 10, 2015
ecff44a
Add extra cases
jvillafanez Jun 10, 2015
557957f
Updated documentation
jvillafanez Jun 10, 2015
6c672e5
Fixes for the experimental files locking feature
jvillafanez Jun 11, 2015
39281b9
Rename folder to make clear the are are for the new locking feature
jvillafanez Jun 11, 2015
11ef6a0
Modify log messages to "debug" level
jvillafanez Jun 11, 2015
d66a5f2
Fix typo
jvillafanez Jun 11, 2015
c293d48
Allow the test to run in several accounts
jvillafanez Jun 11, 2015
0ca410d
Fix issue with the users' account (each worker will access to their
jvillafanez Jun 11, 2015
525c018
Retry action after the download to check that the lock is released
jvillafanez Jun 12, 2015
ece6abf
Fix account access
jvillafanez Jun 12, 2015
652b321
Basic test for locking with overwrite
jvillafanez Jun 11, 2015
a9664b3
Support for multiple accounts in the test
jvillafanez Jun 11, 2015
2bc5f27
Add support for chunking in the file upload (need fixing)
jvillafanez Jun 12, 2015
9f9b009
Fix account access and remove chunked uploads from the tests for now
jvillafanez Jun 15, 2015
3cafd2e
Add test for the download
jvillafanez Jun 16, 2015
e22c4a0
Add test to download a directory and fix some local extra checks
jvillafanez Jun 16, 2015
0639107
Add a bunch of test
jvillafanez Jun 16, 2015
f1dfe43
Add documentation
jvillafanez Jun 17, 2015
64e0228
Cleanup tests
jvillafanez Jun 18, 2015
d1e66d0
Clean duplicated code
jvillafanez Jun 19, 2015
ff62fe4
Fix parameters and add documentation
jvillafanez Jun 19, 2015
8e45d7f
Make sure temporal files are removed regardless of the outcome
jvillafanez Jun 22, 2015
6d6c63b
Add test for uploads (unreliable tests commented out)
jvillafanez Jun 22, 2015
3607b72
Fix variable name and change docs
jvillafanez Jun 22, 2015
974f206
Remove commented out tests and unused function
jvillafanez Jun 24, 2015
f43b2f1
Move pyocaction code from init to pyocclient_wrapper
jvillafanez Sep 1, 2015
c18dbe1
Fix imported function
jvillafanez Sep 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions lib/oc-tests/new_locking/test_downloadFilePlusAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
__doc__ = """
Test locking feature. The test will download a file big enough and perform an operation
while the download is running. Each test set will run a different operation.

Test sets:
* download + overwrite
* download + delete
* download + info (propfind)
* download + rename
* download + move
* download + delete parent folder
* download + rename folder
* download + move folder

+-------------+---------------------------+----------------+
| step number | downloader | doer |
+-------------+---------------------------+----------------+
| 2 | upload big file | |
+-------------+---------------------------+----------------+
| 3 | download big file (async) | |
+-------------+---------------------------+----------------+
| 4 | | perform action |
+-------------+---------------------------+----------------+
| 5 | check result and cleanup | check result |
+-------------+---------------------------+----------------+

"""
import time
import os
import re
import tempfile
import owncloud
import smashbox.utilities.pyocclient_wrapper
from smashbox.utilities import *
from smashbox.script import config as sconf

def parse_worker_number(worker_name):
match = re.search(r'(\d+)$', worker_name)
if match is not None:
return int(match.group())
else:
return None

testsets = [
{ 'action_method': 'put_file_contents',
'action_args': ('/folder/bigfile.dat', '123'*50),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_filesize',
'extra_check_params': ('/folder/bigfile.dat', 3*50)
},
{ 'action_method': 'delete',
'action_args': ('/folder/bigfile.dat',),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_file_not_exists',
'extra_check_params': ('/folder/bigfile.dat',)
},
{ 'action_method': 'file_info',
'action_args': ('/folder/bigfile.dat',),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': None,
'extra_check_params': ()
},
{ 'action_method': 'move',
'action_args': ('/folder/bigfile.dat', '/folder/bigrenamed.dat'),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_first_exists_second_not',
'extra_check_params': ('/folder/bigrenamed.dat', '/folder/bigfile.dat')
},
{ 'action_method': 'move',
'action_args': ('/folder/bigfile.dat', '/folder2/bigfile.dat'),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_first_exists_second_not',
'extra_check_params': ('/folder2/bigfile.dat', '/folder/bigfile.dat')
},
{ 'action_method': 'delete',
'action_args': ('/folder',),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_all_files_not_exists',
'extra_check_params': ('/folder/bigfile.dat', '/folder')
},
{ 'action_method': 'move',
'action_args': ('/folder', '/folder-renamed'),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_first_list_exists_second_list_not',
'extra_check_params': (('/folder-renamed', '/folder-renamed/bigfile.dat'),
('/folder', '/folder/bigfile.dat'))
},
{ 'action_method': 'move',
'action_args': ('/folder', '/folder2/folder'),
'action_kwargs': {},
'accounts': sconf.oc_number_test_users,
'extra_check': 'check_first_list_exists_second_list_not',
'extra_check_params': (('/folder2', '/folder2/folder', '/folder2/folder/bigfile.dat'),
('/folder', '/folder/bigfile.dat'))
},
]

@add_worker
def setup(step):
step(1, 'setup')
reset_owncloud_account(num_test_users=config.get('accounts', 1))
reset_rundir()

def downloader(step):
process_number = parse_worker_number(reflection.getProcessName())
user_account = sconf.oc_account_name if process_number <= 0 else '%s%i' % (sconf.oc_account_name, process_number)

step(2, 'create big file')

client_wrapper = pyocclient_wrapper.pyocclient_wrapper(pyocclient_wrapper.pyocclient_basic_url(), user_account, sconf.oc_account_password, debug=True)

d = make_workdir()

list_files(d)
run_ocsync(d, user_num=None if process_number <= 0 else process_number)

# sync a big file
target_filename = os.path.join(d, 'folder', 'bigfile.dat')
mkdir(os.path.join(d, 'folder'))
mkdir(os.path.join(d, 'folder2'))
createfile(target_filename,'10',count=1000,bs=10000)
sum5 = md5sum(target_filename)

run_ocsync(d, user_num=None if process_number <= 0 else process_number)
list_files(d)

step(3, 'download file async')

try:
tmpfile = tempfile.mkstemp()
# download the file asynchronously
download_thread = client_wrapper.do_action_async('get_file', '/folder/bigfile.dat', tmpfile[1])

step(5, 'check result and cleanup')

# wait until the download finish
download_thread[0].join()
download_result = download_thread[1].get()
if isinstance(download_result, Exception):
raise download_result
else:
error_check(download_result, 'download file failed')

sum5_2 = md5sum(tmpfile[1])
# check both md5 matches
logger.debug('checking md5sum of the downloaded files')
error_check(sum5 == sum5_2, 'uploaded file is different than the downloaded file [%s] - [%s]' % (sum5, sum5_2))
finally:
# remove temporal file
os.remove(tmpfile[1])

def doer(step):
method = config.get('action_method', 'put_file_contents')
args = config.get('action_args', ('/folder/bigfile.dat', '123'*50))
kwargs = config.get('action_kwargs', {})

process_number = parse_worker_number(reflection.getProcessName())
user_account = sconf.oc_account_name if process_number <= 0 else '%s%i' % (sconf.oc_account_name, process_number)

step(2, 'synced setup')

client_wrapper = pyocclient_wrapper.pyocclient_wrapper(pyocclient_wrapper.pyocclient_basic_url(), user_account, sconf.oc_account_password, debug=True)

step(4, 'action over file')

retry_action = False
# perform the action
try:
result = client_wrapper.do_action(method, *args, **kwargs)
except owncloud.ResponseError as e:
logger.debug('%s action failed. Checking the status to know if the file is locked' % (method,))
error_check(e.status_code == 423, 'unexpected status code [%i] : %s' % (e.status_code, e.get_resource_body()))
retry_action = True

step(6, 'check results')
if retry_action:
result = client_wrapper.do_action(method, *args, **kwargs)

# check successful result
logger.debug('check %s method finished correctly' % method)
error_check(result, method + ' action didn\'t finish correctly')

# perform extra check
check = config.get('extra_check', None)
if check:
logger.debug('additional check %s' % check)
check_params = config.get('extra_check_params', ())
error_check(getattr(client_wrapper, check)(*check_params), 'extra check failed: %s %s' % (check, check_params))

# add workers
for i in range(1, config.get('accounts', 1) + 1):
add_worker(downloader, name='downloader_%s' % (i,))
add_worker(doer, name='doer_%s' % (i,))
Loading