diff --git a/tests/tibanna/unicorn/test_ec2_utils.py b/tests/tibanna/unicorn/test_ec2_utils.py index 20ec3a5d0..65ed7db66 100644 --- a/tests/tibanna/unicorn/test_ec2_utils.py +++ b/tests/tibanna/unicorn/test_ec2_utils.py @@ -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', @@ -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', @@ -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"]}, @@ -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']) @@ -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') @@ -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') @@ -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() @@ -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() @@ -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', diff --git a/tibanna/ec2_utils.py b/tibanna/ec2_utils.py index 64ed21749..2d33b8216 100644 --- a/tibanna/ec2_utils.py +++ b/tibanna/ec2_utils.py @@ -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