From 0534509a2039b125b83b2f7766d5ec38e73ebdc4 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Mon, 22 Jan 2018 13:21:16 +0100 Subject: [PATCH] sftp task: verify return code of sftp get command - add short configurable timeout for, e.g. echo commands, or equal --- invenio_uploadbyurl/config.py | 5 ++++- invenio_uploadbyurl/tasks.py | 12 +++++++++--- tests/conftest.py | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/invenio_uploadbyurl/config.py b/invenio_uploadbyurl/config.py index d44f167..849b519 100644 --- a/invenio_uploadbyurl/config.py +++ b/invenio_uploadbyurl/config.py @@ -57,7 +57,10 @@ UPLOADBYURL_COMMENT = 'key@uploadbyurl.de' """Name of key to be added in authorized_keys.""" UPLOADBYURL_TIMEOUT = 60 * 60 # 1 hour -"""Timeout after which upload task should be quit.""" +"""Timeout in s after which upload task should be quit.""" + +UPLOADBYURL_SHORT_TIMEOUT = 30 +"""Timeout in s after which short tasks, e.g. echo, should be quit.""" UPLOADBYURL_SENDER_EMAIL = 'rodare@hzdr.de' """Email address for sending mails.""" diff --git a/invenio_uploadbyurl/tasks.py b/invenio_uploadbyurl/tasks.py index acd7a65..78163b0 100644 --- a/invenio_uploadbyurl/tasks.py +++ b/invenio_uploadbyurl/tasks.py @@ -141,16 +141,22 @@ def download_via_sftp(bucket_id, remote_server_id, user_id, filepath): '/usr/bin/sftp', arguments.split(), timeout=current_app.config['UPLOADBYURL_TIMEOUT'] ) - sftp_proc.expect('Enter passphrase for key .*', timeout=60) + sftp_proc.expect( + 'Enter passphrase for key .*', + timeout=current_app.config['UPLOADBYURL_SHORT_TIMEOUT']) sftp_proc.sendline(secret) - sftp_proc.expect('sftp>', timeout=60) + sftp_proc.expect( + 'sftp>', + timeout=current_app.config['UPLOADBYURL_SHORT_TIMEOUT']) # download file with timeout specified in configuration sftp_proc.sendline(cmd_get) sftp_proc.expect( 'sftp>', timeout=current_app.config['UPLOADBYURL_TIMEOUT'] ) sftp_proc.sendline('exit') - sftp_proc.expect(pexpect.EOF) + sftp_proc.expect( + pexpect.EOF, + timeout=current_app.config['UPLOADBYURL_SHORT_TIMEOUT']) sftp_proc.close() except (pexpect.EOF, pexpect.TIMEOUT): # clean up in case of failure diff --git a/tests/conftest.py b/tests/conftest.py index f2d3f13..988a645 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -82,6 +82,8 @@ def base_app(instance_path): UPLOADBYURL_NOTIFICATION_ENABLED=False, UPLOADBYURL_REDISSTORE_URL=os.getenv('UPLOADBYURL_REDISSTORE_URL', 'redis://localhost:6379/0'), + UPLOADBYURL_TIMEOUT=30, + UPLOADBYURL_SHORT_TIMEOUT=10, FILES_REST_DEFAULT_QUOTA_SIZE=100 * 1024 * 1024, MAIL_SUPPRESS_SEND=True, ) -- GitLab