Skip to content

Commit

Permalink
Merge f67c4a3 into eea657d
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed Jul 16, 2018
2 parents eea657d + f67c4a3 commit 74b90ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
13 changes: 5 additions & 8 deletions reana_workflow_controller/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@
import traceback
from uuid import UUID, uuid4

from flask import (Blueprint, abort, current_app, jsonify, request,
send_from_directory)
from flask import Blueprint, abort, jsonify, request, send_from_directory
from reana_commons.database import Session
from reana_commons.models import (Job, Run, RunJobs, User, UserOrganization,
Workflow, WorkflowStatus)
from werkzeug.exceptions import NotFound
from werkzeug.utils import secure_filename

from reana_workflow_controller.config import (DEFAULT_NAME_FOR_WORKFLOWS,
SHARED_VOLUME_PATH,
WORKFLOW_TIME_FORMAT)
from reana_workflow_controller.errors import (REANAWorkflowControllerError,
UploadPathError,
Expand All @@ -45,7 +42,7 @@
run_serial_workflow,
run_yadage_workflow)
from reana_workflow_controller.utils import (create_workflow_workspace,
get_analysis_files_dir,
get_workflow_files_dir,
list_directory_files)

START = 'start'
Expand Down Expand Up @@ -451,7 +448,7 @@ def seed_workflow_workspace(workflow_id_or_name):
full_file_name = full_file_name[1:]
elif '..' in full_file_name.split("/"):
raise UploadPathError('Path cannot contain "..".')
path = get_analysis_files_dir(workflow, file_type,
path = get_workflow_files_dir(workflow, file_type,
'seed')
if len(full_file_name.split("/")) > 1:
dirs = full_file_name.split("/")[:-1]
Expand Down Expand Up @@ -545,7 +542,7 @@ def get_workflow_outputs_file(workflow_id_or_name, file_name): # noqa

workflow = _get_workflow_with_uuid_or_name(workflow_id_or_name,
user_uuid)
outputs_directory = get_analysis_files_dir(workflow, 'output')
outputs_directory = get_workflow_files_dir(workflow, 'output')
return send_from_directory(outputs_directory,
file_name,
mimetype='multipart/form-data',
Expand Down Expand Up @@ -657,7 +654,7 @@ def get_workflow_files(workflow_id_or_name): # noqa
user_uuid)

file_list = list_directory_files(
get_analysis_files_dir(workflow, file_type))
get_workflow_files_dir(workflow, file_type))
return jsonify(file_list), 200

except WorkflowInexistentError:
Expand Down
14 changes: 7 additions & 7 deletions reana_workflow_controller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import fs
import fs.path as fs_path
from flask import current_app as app
from reana_commons.utils import get_user_analyses_dir
from reana_commons.utils import get_user_workflows_dir


def create_workflow_workspace(org, user, workflow_uuid):
Expand All @@ -40,7 +40,7 @@ def create_workflow_workspace(org, user, workflow_uuid):
:return: Workflow and analysis workspace path.
"""
reana_fs = fs.open_fs(app.config['SHARED_VOLUME_PATH'])
analysis_workspace = fs_path.join(get_user_analyses_dir(org, user),
analysis_workspace = fs_path.join(get_user_workflows_dir(org, user),
workflow_uuid)

if not reana_fs.exists(analysis_workspace):
Expand All @@ -62,22 +62,22 @@ def create_workflow_workspace(org, user, workflow_uuid):
return workflow_workspace, analysis_workspace


def get_analysis_dir(workflow):
def get_workflow_dir(workflow):
"""Given a workflow, returns its analysis directory."""
# remove workflow workspace (/workspace) directory from path
analysis_workspace = fs_path.dirname(workflow.workspace_path)
return fs_path.join(app.config['SHARED_VOLUME_PATH'],
analysis_workspace)


def get_analysis_files_dir(workflow, file_type, action='list'):
def get_workflow_files_dir(workflow, file_type, action='list'):
"""Given a workflow and a file type, returns path to the file type dir."""
analysis_workspace = get_analysis_dir(workflow)
workspace = get_workflow_dir(workflow)
if action == 'list':
return fs_path.join(analysis_workspace,
return fs_path.join(workspace,
app.config['ALLOWED_LIST_DIRECTORIES'][file_type])
elif action == 'seed':
return fs_path.join(analysis_workspace,
return fs_path.join(workspace,
app.config['ALLOWED_SEED_DIRECTORIES'][file_type])


Expand Down
22 changes: 11 additions & 11 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from reana_workflow_controller.config import (ALLOWED_LIST_DIRECTORIES,
ALLOWED_SEED_DIRECTORIES)
from reana_workflow_controller.rest import START, STOP
from reana_workflow_controller.utils import (get_analysis_files_dir,
get_user_analyses_dir)
from reana_workflow_controller.utils import (get_user_workflows_dir,
get_workflow_files_dir)

status_dict = {
START: WorkflowStatus.running,
Expand Down Expand Up @@ -160,11 +160,11 @@ def test_create_workflow_with_name(app, session, default_user,
workflow.type_ == cwl_workflow_with_name['type']

# Check that workflow workspace exist
user_analyses_workspace = get_user_analyses_dir(
user_workflows_dir = get_user_workflows_dir(
organization, str(default_user.id_))
workflow_workspace = os.path.join(
tmp_shared_volume_path,
user_analyses_workspace,
user_workflows_dir,
str(workflow.id_))
assert os.path.exists(workflow_workspace)

Expand Down Expand Up @@ -209,11 +209,11 @@ def test_create_workflow_without_name(app, session, default_user,
workflow.type_ == cwl_workflow_without_name['type']

# Check that workflow workspace exist
user_analyses_workspace = get_user_analyses_dir(
user_workflows_dir = get_user_workflows_dir(
organization, str(default_user.id_))
workflow_workspace = os.path.join(
tmp_shared_volume_path,
user_analyses_workspace,
user_workflows_dir,
str(workflow.id_))
assert os.path.exists(workflow_workspace)

Expand All @@ -238,11 +238,11 @@ def test_create_workflow_wrong_user(app, session, tmp_shared_volume_path,
# workflow exist in DB
assert not workflow
# workflow workspace exist
user_analyses_workspace = get_user_analyses_dir(
user_workflows_dir = get_user_workflows_dir(
organization, str(random_user_uuid))
workflow_workspace = os.path.join(
tmp_shared_volume_path,
user_analyses_workspace)
user_workflows_dir)
assert not os.path.exists(workflow_workspace)


Expand Down Expand Up @@ -297,7 +297,7 @@ def test_get_workflow_outputs_file(app, session, default_user,
# create file
file_name = 'output name.csv'
file_binary_content = b'1,2,3,4\n5,6,7,8'
outputs_directory = get_analysis_files_dir(workflow, 'output')
outputs_directory = get_workflow_files_dir(workflow, 'output')
# write file in the workflow workspace under `outputs` directory:
# we use `secure_filename` here because
# we use it in server side when adding
Expand Down Expand Up @@ -338,7 +338,7 @@ def test_get_workflow_outputs_file_with_path(app, session, default_user,
# create file
file_name = 'first/1991/output.csv'
file_binary_content = b'1,2,3,4\n5,6,7,8'
outputs_directory = get_analysis_files_dir(workflow, 'output')
outputs_directory = get_workflow_files_dir(workflow, 'output')
# write file in the workflow workspace under `outputs` directory:
# we use `secure_filename` here because
# we use it in server side when adding
Expand Down Expand Up @@ -743,7 +743,7 @@ def test_seed_workflow_workspace(app, session, default_user, file_type,
file_name)})
assert res.status_code == 200
# remove workspace directory from path
files_directory = get_analysis_files_dir(workflow, file_type, 'seed')
files_directory = get_workflow_files_dir(workflow, file_type, 'seed')

# we use `secure_filename` here because
# we use it in server side when adding
Expand Down

0 comments on commit 74b90ae

Please sign in to comment.