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