Skip to content

Commit

Permalink
command in input json can be a list
Browse files Browse the repository at this point in the history
  • Loading branch information
SooLee committed Jun 12, 2019
1 parent 549e374 commit 9d3ed42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/tibanna/unicorn/test_ec2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_args_parse_input_files2():
assert args.input_files['file1']['object_key'][1][1] == 'somekey4'


def test_args_parse_input_files2():
def test_args_parse_input_files3():
input_dict = {'args': {'input_files': {"file1": ["s3://somebucket/somekey1",
"s3://somebucket/somekey2"]},
'output_S3_bucket': 'somebucket',
Expand All @@ -101,6 +101,7 @@ def test_args_parse_input_files2():
assert args.input_files['file1']['object_key'][0] == 'somekey1'
assert args.input_files['file1']['object_key'][1] == 'somekey2'


def test_args_parse_input_files_format_error():
input_dict = {'args': {'input_files': {"file1": "somerandomstr"},
'output_S3_bucket': 'somebucket',
Expand All @@ -113,6 +114,7 @@ def test_args_parse_input_files_format_error():
assert ex
assert 'S3 url must begin with' in str(ex.value)


def test_args_parse_input_files_format_error2():
input_dict = {'args': {'input_files': {"file1": ["s3://somebucket/somekey1",
"s3://otherbucket/somekey2"]},
Expand All @@ -126,6 +128,18 @@ def test_args_parse_input_files_format_error2():
assert ex
assert 'bucket' in str(ex.value)


def test_parse_command():
input_dict = {'args': {'command': ['command1', 'command2', 'command3'],
'output_S3_bucket': 'somebucket',
'language': 'shell',
'container_image': 'someimage',
'app_name': 'someapp'}}
args = Args(**input_dict['args'])
args.fill_default()
assert args.command == 'command1; command2; command3'


def test_config():
input_dict = {'config': {'log_bucket': 'tibanna-output', 'shutdown_min': 30}}
cfg = Config(**input_dict['config'])
Expand Down Expand Up @@ -213,6 +227,7 @@ def test_execution_benchmark():
s3.delete_objects(Bucket='tibanna-output',
Delete={'Objects': [{'Key': randomstr}]})


def test_get_file_size():
randomstr = 'test-' + create_jobid()
s3 = boto3.client('s3')
Expand All @@ -224,6 +239,7 @@ def test_get_file_size():
s3.delete_objects(Bucket='tibanna-output',
Delete={'Objects': [{'Key': randomstr}]})


def test_get_input_size_in_bytes():
randomstr = 'test-' + create_jobid()
s3 = boto3.client('s3')
Expand All @@ -244,6 +260,7 @@ def test_get_input_size_in_bytes():
s3.delete_objects(Bucket='tibanna-output',
Delete={'Objects': [{'Key': randomstr}]})


def test_update_config_ebs_size():
"""ebs_size is given as the 'x' format. The total estimated ebs_size is smaller than 10"""
randomstr = 'test-' + create_jobid()
Expand All @@ -265,6 +282,7 @@ def test_update_config_ebs_size():
s3.delete_objects(Bucket='tibanna-output',
Delete={'Objects': [{'Key': randomstr}]})


def test_update_config_ebs_size2():
"""ebs_size is given as the 'x' format. The total estimated ebs_size is larger than 10"""
randomstr = 'test-' + create_jobid()
Expand All @@ -286,6 +304,7 @@ def test_update_config_ebs_size2():
s3.delete_objects(Bucket='tibanna-output',
Delete={'Objects': [{'Key': randomstr}]})


def test_unicorn_input_missing_field():
"""app_name that doesn't exist in benchmark, without instance type, mem, cpu info"""
input_dict = {'args': {'input_files': {}, 'app_name': 'app_name_not_in_benchmark',
Expand Down
10 changes: 10 additions & 0 deletions tibanna/ec2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ def fill_default(self):
if not self.cwl_directory_local and not self.cwl_directory_url:
errmsg = "either %s or %s must be provided in args" % ('cwl_directory_url', 'cwl_directory_local')
raise MissingFieldInInputJsonException(errmsg)
# reformat command
self.parse_command()

def parse_command(self):
"""if command is a list, conert it to a string"""
if hasattr(self, 'command'):
if isinstance(self.command, list):
self.command = '; '.join(self.command)
elif not isinstance(self.command, str):
raise MalFormattedInputJsonException("command must be either a string or a list")

def parse_input_files(self):
"""checking format for input files and converting s3:// style string into
Expand Down

0 comments on commit 9d3ed42

Please sign in to comment.