Skip to content

Commit

Permalink
File handeling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
damies13 committed Nov 3, 2019
1 parent d80232b commit 331d92b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 10 deletions.
46 changes: 46 additions & 0 deletions Robot_Resources/perftest.resource
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*** Settings ***
Library OperatingSystem
Library String

*** Variables ***
${STT_MIN} 15
Expand All @@ -7,4 +9,48 @@ ${STT_MAX} 45
*** Keywords ***
Standard Think Time
${number} Evaluate random.randint(${STT_MIN}, ${STT_MAX}) random
Log Standard Think Time (${number})
Sleep ${number}

Get Data Row
[Arguments] ${FileName} ${Row}="Random"
[Documentation] This keyword gets a row of data from a CSV or TSV file,
... takes 1-2 arguments:
... - FileName (Required)
... - Row (Optional) can be Random, Sequential or a number
... defaults to Random
# Log Get Data Row: \tFileName: ${FileName} \tRow: ${Row}
${RAW_FILE} = Get File ${FileName}
@{FILE_LINES} = Split To Lines ${RAW_FILE}
${LINE_COUNT} = Get Length ${FILE_LINES}

${FILE_SEQUENTIAL_NUM} = Get Variable Value ${FILE_SEQUENTIAL_NUM} 0

@{delim_cols} = Split String ${FILE_LINES}[0] ,
${delim_cols_len} = Get Length ${delim_cols}
${DELIMITER} = Set Variable If ${delim_cols_len} > 1 , \t
@{FILE_COLUMNS} = Split String ${FILE_LINES}[0] ${DELIMITER}
${COLUMNS_COUNT} = Get Length ${FILE_COLUMNS}

${ROW_NUM} = Set Variable ${Row}
${ROW_NUM} = Run Keyword If ${Row}=="Random" Evaluate random.randint(1, ${LINE_COUNT}-1) random
... ELSE Set Variable ${ROW_NUM}
${ROW_NUM} = Run Keyword If ${Row}=="Sequential" Evaluate ${FILE_SEQUENTIAL_NUM} + 1
... ELSE Set Variable ${ROW_NUM}

Set Test Variable \${FILE_SEQUENTIAL_NUM} ${FILE_SEQUENTIAL_NUM}

@{ROW_COLUMNS} = Split String ${FILE_LINES}[${ROW_NUM}] ${DELIMITER}
# :FOR ${I} Input Text locator text
FOR ${I} IN RANGE ${COLUMNS_COUNT}
# Log \${I} ${I}
${VAR_NAME} = Set Variable ${FILE_COLUMNS}[${I}]
${VAR_VALUE} = Set Variable ${ROW_COLUMNS}[${I}]
# Log \${VAR_NAME}: ${VAR_NAME}\t\${VAR_VALUE}: ${VAR_VALUE}
Set Test Variable ${${VAR_NAME}} ${VAR_VALUE}
END
# Log Variables

Get File Dir
${FILE_DIR} = Evaluate os.path.dirname("${SUITE_SOURCE}") os
[Return] ${FILE_DIR}
20 changes: 17 additions & 3 deletions rfswarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import sys
import os
import glob
import hashlib
import lzma
import base64
Expand Down Expand Up @@ -1414,12 +1415,12 @@ def find_dependancies(self, hash):
if checking:
# print("find_dependancies: line", line)
try:
if 'Resource' in line or 'Variables' in line:
if 'Resource' in line or 'Variables' in line or 'Metadata File' in line:
linearr = line.strip().split()
# print("find_dependancies: linearr", linearr)
if len(linearr)>1:
# print("find_dependancies: linearr[1]", linearr[1])
resfile = linearr[1]
resfile = linearr[-1]
localrespath = os.path.join(localdir, resfile)
# print("find_dependancies: localrespath", localrespath)
if os.path.isfile(localrespath):
Expand All @@ -1431,7 +1432,20 @@ def find_dependancies(self, hash):
'relpath': resfile,
'type': linearr[0]
}

else:
filelst = glob.glob(localrespath)
for file in filelst:
print("find_dependancies: file", file)
relpath = file.replace(localdir, "")[1:]
print("find_dependancies: relpath", relpath)
newhash = self.hash_file(file)
print("find_dependancies: newhash", newhash)
self.scriptfiles[newhash] = {
'id': newhash,
'localpath': file,
'relpath': relpath,
'type': linearr[0]
}

except Exception as e:
print("find_dependancies: line", line)
Expand Down
26 changes: 19 additions & 7 deletions rfswarm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def getfile(self, hash):
# print("getfile: jsonresp:", jsonresp)

# print('scriptdir', self.scriptdir)
localfile = os.path.join(self.scriptdir, jsonresp['File'])
localfile = os.path.abspath(os.path.join(self.scriptdir, jsonresp['File']))
print('getfile: localfile', localfile)
self.scriptlist[hash]['localfile'] = localfile
self.scriptlist[hash]['file'] = jsonresp['File']
Expand All @@ -283,18 +283,28 @@ def getfile(self, hash):

filedata = jsonresp['FileData']
# print("filedata:", filedata)
# print("getfile: filedata:")

decoded = base64.b64decode(filedata)
# print("b64decode: decoded:", decoded)
# print("getfile: b64decode:")

uncompressed = lzma.decompress(decoded)
# print("uncompressed:", uncompressed)
# print("getfile: uncompressed:")

localfiledir = os.path.dirname(localfile)
# print("getfile: localfiledir:", localfiledir)
self.ensuredir(localfiledir)
# print("getfile: ensuredir:")

with open(localfile, 'wb') as afile:
afile.write(uncompressed)
# print("getfile: afile:")
afile.write(uncompressed)
# print("getfile: write:")

except Exception as e:
print("getscripts: Exception:", e)
print("getfile: Exception:", e)

def getjobs(self):
# print("getjobs")
Expand Down Expand Up @@ -465,9 +475,10 @@ def run_process_output(self, outputFile, index, vuser, iter):
# print("root: '", root)
# .//kw/msg/..[not(@library='BuiltIn')]
for result in root.findall(".//kw/msg/..[@library]"):
# print("result: ", result)
# print("run_process_output: result: ", result)
library = result.get('library')
if library != "BuiltIn":
if library not in ["BuiltIn", "String", "OperatingSystem", "perftest"]:
# print("run_process_output: library: ", library)
seq += 1
# print("result: library:", library)
txn = result.find('msg').text
Expand Down Expand Up @@ -514,7 +525,7 @@ def run_process_output(self, outputFile, index, vuser, iter):
"Sequence": seq
}

print("run_proces_output: payload", payload)
# print("run_proces_output: payload", payload)
try:
r = requests.post(uri, json=payload)
# print("run_proces_output: ",r.status_code, r.text)
Expand Down Expand Up @@ -544,7 +555,8 @@ def ensuredir(self, dir):
os.mkdir(dir, mode=0o777)
# print("Directory Created: ", dir)
except FileExistsError:
print("Directory Exists: ", dir)
# print("Directory Exists: ", dir)
pass
except Exception as e:
print("Directory Create failed: ", dir)
print("with error: ", e)
Expand Down

0 comments on commit 331d92b

Please sign in to comment.