Skip to content

Commit

Permalink
Merge pull request #248 from datmo/data-option-message
Browse files Browse the repository at this point in the history
updating entities for run while using data option
  • Loading branch information
asampat3090 committed Jul 31, 2018
2 parents e61d3cc + 15077f5 commit 9fae433
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
16 changes: 13 additions & 3 deletions datmo/cli/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,34 @@ def task_run_helper(self, task_dict, snapshot_dict, error_identifier, data_paths
_, _, task_dict['data_file_path_map'], task_dict['data_directory_path_map'] = \
parse_paths(self.task_controller.home, data_paths, '/data')
except PathDoesNotExist as e:
status = "NOT STARTED"
workspace = task_dict.get('workspace', None)
command = task_dict.get('command', None)
command_list = task_dict.get('command_list', None)
interactive = task_dict.get('interactive', False)
self.task_controller.update(task_obj.id,
workspace=workspace,
command=command,
command_list=command_list,
interactive=interactive)
self.cli_helper.echo(__("error", "cli.run.parse.paths", str(e)))
return False

updated_task_obj = self.task_controller.run(
task_obj.id, snapshot_dict=snapshot_dict, task_dict=task_dict)
status = "SUCCESS"
self.cli_helper.echo(__("info", "cli.run.run.stop"))
except Exception as e:
status = "FAILED"
self.logger.error("%s %s" % (e, task_dict))
self.cli_helper.echo("%s" % e)
self.cli_helper.echo(__("error", error_identifier, task_obj.id))
return False
finally:
self.cli_helper.echo(__("info", "cli.run.run.stop"))
self.task_controller.stop(
task_id=updated_task_obj.id, status=status)
self.cli_helper.echo(
__("info", "cli.run.run.complete", updated_task_obj.id))
self.cli_helper.echo(
__("info", "cli.run.run.complete", updated_task_obj.id))

return updated_task_obj

Expand Down
11 changes: 10 additions & 1 deletion datmo/cli/command/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def to_bytes(val):
from datmo.cli.command.run import RunCommand
from datmo.core.entity.task import Task as CoreTask
from datmo.core.util.exceptions import SessionDoesNotExist, DoesNotExist, \
MutuallyExclusiveArguments, RequiredArgumentMissing
MutuallyExclusiveArguments, RequiredArgumentMissing, PathDoesNotExist
from datmo.core.util.misc_functions import pytest_docker_environment_failed_instantiation

# provide mountable tmp directory for docker
Expand Down Expand Up @@ -241,6 +241,15 @@ def test_run_data_dir(self):
# test when all is passed to stop all
self.run_command.execute()

# test failure
test_data_dir_dne = os.path.join(tempfile.mkdtemp(dir=test_datmo_dir), "data_dne")
self.run_command.parse([
"run", "--environment-paths", test_dockerfile,
"--data", test_data_dir_dne
])
result = self.run_command.execute()
assert not result

@pytest_docker_environment_failed_instantiation(test_datmo_dir)
def test_run_string_command(self):
# TODO: Adding test with `--interactive` argument and terminate inside container
Expand Down
35 changes: 35 additions & 0 deletions datmo/core/controller/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,41 @@ def get_files(self, task_id, mode="r"):
# Error because the task does not have any files associated with it
raise PathDoesNotExist()

def update(self,
task_id,
workspace=None,
command=None,
command_list=None,
interactive=False):
"""Update the task metadata"""
if not task_id:
raise RequiredArgumentMissing(
__("error", "controller.task.delete.arg", "id"))
if command_list:
command = " ".join(command_list)
elif command:
command_list = shlex.split(command)

validate(
"update_task", {
"workspace": workspace,
"command": command,
"command_list": command_list,
"interactive": interactive
})
update_task_input_dict = {'id': task_id}

if workspace is not None:
update_task_input_dict['workspace'] = workspace
if command is not None:
update_task_input_dict['command'] = command
if command_list is not None:
update_task_input_dict['command_list'] = command_list
if interactive:
update_task_input_dict['interactive'] = interactive

return self.dal.task.update(update_task_input_dict)

def delete(self, task_id):
if not task_id:
raise RequiredArgumentMissing(
Expand Down
33 changes: 33 additions & 0 deletions datmo/core/controller/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,39 @@ def test_get_files(self):

self.task_controller.stop(task_obj.id)

def test_update(self):
self.__setup()
# Create task in the project
task_obj = self.task_controller.create()
assert isinstance(task_obj, Task)

# Test 1: When no meta data is passed
updated_task_obj = self.task_controller.update(task_obj.id)
assert updated_task_obj.workspace is None

# Test 2: When meta data for workspace is passed
test_workspace = "notebook"
test_command = "python script.py"
updated_task_obj = self.task_controller.update(task_obj.id,
workspace=test_workspace,
command=test_command)
assert updated_task_obj.workspace == test_workspace
assert updated_task_obj.command == test_command
assert updated_task_obj.command_list == ["python", "script.py"]

# Test 3: When meta data for workspace is passed
test_interactive = True
updated_task_obj = self.task_controller.update(task_obj.id,
interactive=test_interactive)
assert updated_task_obj.interactive == test_interactive

# Test 4: When meta data for workspace is passed
test_command_list = ["python", "script.py"]
updated_task_obj = self.task_controller.update(task_obj.id,
command_list=test_command_list)
assert updated_task_obj.command_list == ["python", "script.py"]


@pytest_docker_environment_failed_instantiation(test_datmo_dir)
def test_delete(self):
self.__setup()
Expand Down
15 changes: 14 additions & 1 deletion datmo/core/util/validation/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,17 @@ create_task:
type: list
data_directory_path_map:
nullable: true
type: list
type: list

update_task:
workspace:
nullable: true
type: string
command:
nullable: true
type: string
command_list:
nullable: true
type: list
interactive:
type: boolean

0 comments on commit 9fae433

Please sign in to comment.