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

win tools and test_rw_lock #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions lib/filesystem/test_rwlock_smb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
__doc__ = """
This test is to reproduce the read write lock with samba on windows
"""

from smashbox.utilities import *
from smashbox.utilities.hash_files import *
import time

nfiles = int(config.get('rwlock_smb_nfiles',4)) # The number of files to be created should be 4-1000
delay = int(config.get('rwlock_smb_delay',1)) # this is the delay used to keep files open
smbpath = config.get('rwlock_smb_smbpath',"Z:/smb-rw-lock/")
leave_open = int(config.get('rwlock_leave_open',10))

clean_previous_run = True
path = smbpath + "/officeSimulation_word/"

config.expected_result = do_not_report_as_failure("smb implements a special locking mechanism that corrupts files when trying to open them in read/write mode... ")

restrict_execution(current_platform="Windows") # Restrict the execution to be run only in Windows

def count_office_files(path):
n=0
for filename in os.listdir(path):
if not filename.endswith("tmp"):
n = n + 1
return n

def open_office_files(mode):
try:
for filename in os.listdir(path):
if not filename.endswith("tmp"):
file = path + filename
process = subprocess.Popen(
os.getcwd()[:-3] + "\win-tools\KeepOfficeOpen\KeepItOpen.exe " + mode + " delay1" + " " + str(
delay) + " " + "s" + " " + "file" + " " + file)

except Exception as e:
logger.exception('Error opening the word file to ' + mode + 'on it ')


@add_worker
def worker0(step):

step(1, 'Preparation')
k0 = count_office_files(path)

step(2, 'Create nfiles office files and write some content on it')
process = subprocess.Popen(os.getcwd()[:-3] + "/win-tools/OfficeUsersSimulation/OfficeUsersSimulation_C.exe nof" + " " + str(nfiles) + " " + "crtfls usewd wrkdir " + smbpath)

k1=0
while(abs(k1-k0) != nfiles):
k1=count_office_files(path)
time.sleep(1)

process.kill() # Avoid this test to be locked by the execution of the program

step(4, 'Open the nfiles office files with delay to write on it')

open_office_files("w")

time.sleep(leave_open) # Leave the program open. If the process is killed office will leave the file in DENY_READ

step(5, 'Open the nfiles office files with delay to read on it')

open_office_files("r")

time.sleep(leave_open)

@add_worker
def worker1(step):

step(1, 'Preparation')

k0 = count_office_files(path)

step(3, 'Resync and check files added by worker0')

ncorrupt = analyse_hashfiles(path)[2]
k1 = count_office_files(path)

error_check(k1 - k0 == nfiles, 'Expecting to have %d files more: see k1=%d k0=%d' % (abs(k1 - 1), k1, k0))
fatal_check(ncorrupt == 0, 'Corrupted files (%d) found' % ncorrupt)
Binary file added win-tools/KeepOfficeOpen/KeepItOpen.exe
Binary file not shown.
37 changes: 37 additions & 0 deletions win-tools/KeepOfficeOpen/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
� In 'Debug' folder you can run the file "KeepItOpen.exe".

� In 'publish' folder you can find the installation file.
You do NOT need to install the software, I just include the files in case you want them.


Instructions:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Available arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1) r (or) w : file in 'read' or 'write' mode
2) file + <path> : path to word OR excel file to keep open
3) delay1 + <integer[1-3600]> : delay in seconds that file will be kept open
4) delay2 + <integer[0-3600]> : extra delay in seconds (ONLY in 'w' mode)
5) s : silent mode - no confirmation asked

1) Open the file in either READ (r) or WRITE (w) mode.
In READ mode, the file will be kept open for as many seconds as defined by
parameter 'delay1'. Parameter 'delay2' is ignored.
Then the file is closed and the software exits.

In WRITE mode, the file opens and stays open for as many seconds as defined
by parameter 'delay1'. Then some random Lorem Ipsum text is written.
Keep in mind that any text inside the file will be OVERWRITTEN!
If set, additional delay 'delay2' is applied in that point.
Then the file is closed and the software exits.

2) Give the path to the office file that will be kept open.
Accepted formats: .doc .docx .xls .xlsx

5) If this argument is added, the software will not ask for confirmation.
In case this argument is missing, you will be presented a sum of the arguments
and will be asked to confirm.

Arguments (1) , (2) & (3) are mandatory. Arguments (4) & (5) can be skipped.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check "args tests.txt" file for some examples.
45 changes: 45 additions & 0 deletions win-tools/KeepOfficeOpen/args tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
~~ Read mode word, delay 10 seconds

r delay1 10 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

~~ Read mode, delay 10 seconds, SILENT

r delay1 10 s file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~ Read mode word, delay 5 seconds, 2nd delay 10 seconds (software skips delay2)

r delay1 5 delay2 10 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

~~ Read mode word, delay 5 seconds, 2nd delay 10 seconds (software skips delay2), SILENT

r delay1 5 delay2 10 s file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~ Write mode word, delay 5 seconds

w delay1 5 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

~~ Write mode word, delay 5 seconds, 2nd delay 10 seconds

w delay1 5 delay2 10 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

~~ Write mode word, delay 5 seconds, 2nd delay 3 seconds, SILENT

w delay1 5 delay2 3 s file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testWord_1.docx"

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~ Write mode excel, delay 5 seconds

w delay1 5 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testExcel_1.xlsx"

~~ Write mode excel, delay 2 seconds, 2nd delay 5 seconds

w delay1 2 delay2 5 file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testExcel_1.xlsx"

~~ Write mode excel, delay 5 seconds, 2nd delay 3 seconds, SILENT

w delay1 5 delay2 3 s file "\\cernbox-smb.cern.ch\eos\user\a\asmyrnak\KeepOfficeOpen\testExcel_1.xlsx"
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions win-tools/OfficeUsersSimulation/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
� In the 'Debug' folder you can run the file "OfficeUsersSimulation_C.exe".

� In the 'publish' folder you can find the installation file.
You do NOT need to isntall the software, I just include the files in case you want them.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Version 2:
~ bug fix: - continuously loading defaults (or last) values
- could start empty files creation, even with no "use word/excel" selection
- while empty files running "use word/excel" could be changed
- if word/excel operations finish before "empty files" creation, button remains at "STOP" state
(restoreAfterRun() do not run before empty files creation is also completed)

~ add: - "autoDelete" option deletes also "empty files" folder (if user doesn't choose to open
the folder containing the files)

~ known issues: - at manual STOP (or Empty creation stop), excel instance remains (sometimes)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2 changes: 2 additions & 0 deletions win-tools/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/cernbox/wintools.git