Skip to content
Snippets Groups Projects
Commit 97e09f41 authored by Anne Philipp's avatar Anne Philipp
Browse files

completed testing and adaptations of ecacces job-submit and file-put functions

parent f9f7b3f8
Branches
Tags
No related merge requests found
......@@ -176,7 +176,7 @@ def install_via_gateway(c):
target_dir = 'flex_extract_v' + _VERSION_STR
fortran_executable = 'CONVERT2'
if c.install_target.lower() != 'local':
if c.install_target.lower() != 'local': # ecgate or cca
mk_compilejob(ecd + 'python/compilejob.temp', c.makefile,
c.install_target, c.ecuid, c.ecgid,
......@@ -194,13 +194,13 @@ def install_via_gateway(c):
put_file_to_ecserver(ecd, tarball_name, c.install_target,
c.ecuid, c.ecgid)
result_code = submit_job_to_ecserver(ecd + '/python/', c.install_target,
'compilejob.ksh')
submit_job_to_ecserver(ecd + '/python/', c.install_target,
'compilejob.ksh')
print 'job compilation script has been submitted to ecgate for ' + \
'installation in ' + c.flexpart_root_scripts + \
'/' + target_dir
print 'You should get an email with subject flexcompile within ' + \
print 'You should get an email with subject "flexcompile" within ' + \
'the next few minutes!'
else: #local
......
{
"TestTools.py": true,
"TestTools.py::TestTools::test_init128": true,
"TestTools.py::TestTools::test_to_param_id": true
}
\ No newline at end of file
......@@ -116,8 +116,24 @@ class TestTools():
def test_make_dir(self):
assert True
@pytest.mark.msuser
def test_fail_put_file_to_ecserver(self):
ecuid=os.environ['ECUID']
ecgid=os.environ['ECGID']
with pytest.raises(SystemExit) as pytest_wrapped_e:
put_file_to_ecserver('TestData/', 'testfil.txt',
'ecgate', ecuid, ecgid)
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == '... ECACCESS-FILE-PUT FAILED!'
def test_success_put_file_to_ecserver(self):
ecuid=os.environ['ECUID']
ecgid=os.environ['ECGID']
result = put_file_to_ecserver('TestData/', 'testfile.txt',
'ecgate', ecuid, ecgid)
assert result == ''
@pytest.mark.msuser_pw
def test_fullsuccess_put_file_to_ecserver(self):
ecuid=os.environ['ECUID']
ecgid=os.environ['ECGID']
put_file_to_ecserver('TestData/', 'testfile.txt', 'ecgate', ecuid, ecgid)
......@@ -133,8 +149,7 @@ class TestTools():
def test_success_submit_job_to_ecserver(self):
result = submit_job_to_ecserver('ecgate', 'TestData/testfile.txt')
assert result == 0
assert result.strip().isdigit() == True
if __name__ == "__main__":
......
# content of pytest.ini
[pytest]
markers =
memberstate: Test that can be executed only as a member-state user. Password required.
\ No newline at end of file
msuser_pw: Test that can be executed only as a member-state user. Password required.
\ No newline at end of file
......@@ -445,18 +445,22 @@ def make_dir(directory):
def put_file_to_ecserver(ecd, filename, target, ecuid, ecgid):
'''
@Description:
Uses the ecaccess command to send a file to the ECMWF servers.
Catches and prints the error if it failed.
Uses the ecaccess-file-put command to send a file to the ECMWF servers.
NOTE:
The return value is just for testing reasons. It does not have
to be used from the calling function since the whole error handling
is done in here.
@Input:
ecd: string
The path were the file is to be stored.
The path were the file is stored.
filename: string
The name of the file to send to the ECMWF server.
target: string
The target where the file should be sent to, e.g. the queue.
The target queue where the file should be sent to.
ecuid: string
The user id on ECMWF server.
......@@ -465,28 +469,37 @@ def put_file_to_ecserver(ecd, filename, target, ecuid, ecgid):
The group id on ECMWF server.
@Return:
<nothing>
rcode: string
Resulting code of command execution. If successful the string
will be empty.
'''
try:
subprocess.check_call(['ecaccess-file-put',
ecd + '/' + filename,
target + ':/home/ms/' +
ecgid + '/' + ecuid +
'/' + filename])
rcode = subprocess.check_output(['ecaccess-file-put',
ecd + '/' + filename,
target + ':/home/ms/' +
ecgid + '/' + ecuid +
'/' + filename],
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print 'ERROR:'
print e
sys.exit('ecaccess-file-put failed!\n' + \
'Probably the eccert key has expired.')
print '... ERROR CODE:\n ... ', e.returncode
print '... ERROR MESSAGE:\n ... ', e
print '... COMMAND MESSAGE:\n ...', e.output
return
print '\nDo you have a valid eccert key?'
sys.exit('... ECACCESS-FILE-PUT FAILED!')
return rcode
def submit_job_to_ecserver(target, jobname):
'''
@Description:
Uses ecaccess to submit a job to the ECMWF server.
Catches and prints the error if one arise.
Uses ecaccess-job-submit command to submit a job to the ECMWF server.
NOTE:
The return value is just for testing reasons. It does not have
to be used from the calling function since the whole error handling
is done in here.
@Input:
target: string
......@@ -496,16 +509,22 @@ def submit_job_to_ecserver(target, jobname):
The name of the jobfile to be submitted to the ECMWF server.
@Return:
rcode: integer
Resulting code of subprocess.check_call.
rcode: string
Resulting code of command execution. If successful the string
will contain an integer number, representing the id of the job
at the ecmwf server.
'''
try:
rcode = subprocess.check_call(['ecaccess-job-submit',
'-queueName', target,
jobname])
rcode = subprocess.check_output(['ecaccess-job-submit',
'-queueName', target,
jobname])
except subprocess.CalledProcessError as e:
print '... ERROR CODE: ', e.returncode
print '... ERROR MESSAGE:\n ... ', e
print '... COMMAND MESSAGE:\n ...', e.output
print '\nDo you have a valid eccert key?'
sys.exit('... ECACCESS-JOB-SUBMIT FAILED!')
return rcode
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment