diff --git a/python/install.py b/python/install.py index b20df9ae3adaf3a9af20008559f7297423dc4d84..a1864ba97362d546076a598a4055f2ef041d2b6f 100755 --- a/python/install.py +++ b/python/install.py @@ -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 diff --git a/python/pythontest/.cache/v/cache/lastfailed b/python/pythontest/.cache/v/cache/lastfailed index 628a7499aab7afb001f0d5d3dc1b3e9933348e03..068d2ba10d0378b359dc283e618f2c1bcb82e0eb 100644 --- a/python/pythontest/.cache/v/cache/lastfailed +++ b/python/pythontest/.cache/v/cache/lastfailed @@ -1,4 +1,5 @@ { + "TestTools.py": true, "TestTools.py::TestTools::test_init128": true, "TestTools.py::TestTools::test_to_param_id": true } \ No newline at end of file diff --git a/python/pythontest/TestTools.py b/python/pythontest/TestTools.py index ad2dbff9ab5d820a1bec245d7dfd4cd97a62a4e7..5803036226ea05437e84021a942e55c9e6dded6b 100644 --- a/python/pythontest/TestTools.py +++ b/python/pythontest/TestTools.py @@ -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__": diff --git a/python/pythontest/pytest.ini b/python/pythontest/pytest.ini index 301a45e2e404f2fd007215f09ca56642c0cf67cb..fff665e6e68c39692076935031c96e80d55ab3bc 100644 --- a/python/pythontest/pytest.ini +++ b/python/pythontest/pytest.ini @@ -1,4 +1,4 @@ # 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 diff --git a/python/tools.py b/python/tools.py index b41036bb3e28eacba4d401bc6bf868d9f3c6933d..3c700639314b9aa6c12db9772022634f0c502a6d 100644 --- a/python/tools.py +++ b/python/tools.py @@ -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