def test_ec2_exception_coordinator8(): """ec2 exceptions with 'other_instance_types' with both instance_type and mem/cpu specified""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'instance_type': 't2.micro', 'mem': 1, 'cpu': 1, 'behavior_on_capacity_limit': 'other_instance_types' }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) assert execution.cfg.instance_type == 't2.micro' execution.userdata = execution.create_userdata() res = execution.ec2_exception_coordinator(fun)() assert res == 'continue' assert execution.cfg.instance_type == 't3.micro' execution.userdata = execution.create_userdata() res = execution.ec2_exception_coordinator(fun)() assert res == 'continue' assert execution.cfg.instance_type == 't3.small' # skill t2.micro since it was already tried
def test_ec2_exception_coordinator6(): """ec2 exceptions with 'retry_without_spot'""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'instance_type': 't2.micro', 'spot_instance': True, 'behavior_on_capacity_limit': 'retry_without_spot' }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) execution.userdata = execution.create_userdata() res = execution.ec2_exception_coordinator(fun)() assert res == 'continue' assert execution.cfg.spot_instance is False # changed to non-spot assert execution.cfg.behavior_on_capacity_limit == 'fail' # changed to non-spot with pytest.raises(EC2InstanceLimitException) as exec_info: res = execution.ec2_exception_coordinator(fun)() # this time, it fails assert exec_info
def test_launch_and_get_instance_id(): """test dryrun of ec2 launch""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'mem': 1, 'cpu': 1, 'spot_instance': True }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) # userdata is required before launch_args is created execution.userdata = execution.create_userdata() with pytest.raises(Exception) as ex: execution.launch_and_get_instance_id() assert 'Request would have succeeded, but DryRun flag is set' in str( ex.value)
def test_launch_args(): """test creating launch arguments - also test spot_instance""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'mem': 1, 'cpu': 1, 'spot_instance': True }, 'jobid': jobid } execution = Execution(input_dict) # userdata is required before launch_args is created execution.userdata = execution.create_userdata() launch_args = execution.launch_args print(launch_args) assert launch_args assert 't3.micro' in str(launch_args) assert 'InstanceMarketOptions' in str(launch_args)
def test_ec2_exception_coordinator2(): """ec2 limit exceptions with 'fail'""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'instance_type': 'c5.4xlarge', 'spot_instance': True }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) execution.userdata = execution.create_userdata() with pytest.raises(EC2InstanceLimitException) as exec_info: execution.ec2_exception_coordinator(fun)() assert exec_info
def test_ec2_exception_coordinator7(): """ec2 exceptions with 'retry_without_spot' without spot instance""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'instance_type': 't2.micro', 'behavior_on_capacity_limit': 'retry_without_spot' }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) assert execution.cfg.spot_instance is False execution.userdata = execution.create_userdata() with pytest.raises(Exception) as exec_info: execution.ec2_exception_coordinator(fun)() assert "'retry_without_spot' works only with 'spot_instance'" in str( exec_info.value)
def test_ec2_exception_coordinator5(): """ec2 exceptions with 'other_instance_types' but had only one option""" jobid = create_jobid() log_bucket = 'tibanna-output' input_dict = { 'args': { 'output_S3_bucket': 'somebucket', 'cwl_main_filename': 'md5.cwl', 'cwl_directory_url': 'someurl' }, 'config': { 'log_bucket': log_bucket, 'instance_type': 't2.micro', 'spot_instance': True, 'behavior_on_capacity_limit': 'other_instance_types' }, 'jobid': jobid } execution = Execution(input_dict, dryrun=True) assert execution.cfg.instance_type == 't2.micro' execution.userdata = execution.create_userdata() with pytest.raises(EC2InstanceLimitException) as exec_info: execution.ec2_exception_coordinator(fun)() assert 'No more instance type available' in str(exec_info.value)