示例#1
0
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
示例#2
0
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
示例#3
0
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)
示例#4
0
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)
示例#5
0
def test_create_userdata_w_profile():
    randomstr = 'test-' + create_jobid()
    s3 = boto3.client('s3')
    s3.put_object(Body='haha'.encode('utf-8'),
                  Bucket='tibanna-output',
                  Key=randomstr)
    input_dict = {
        'args': {
            'input_files': {
                'input_file': {
                    'bucket_name': 'tibanna-output',
                    'object_key': randomstr
                }
            },
            'output_S3_bucket': 'somebucket',
            'app_name': 'md5',
            'cwl_main_filename': 'md5.cwl',
            'cwl_directory_url': 'someurl'
        },
        'config': {
            'log_bucket': 'tibanna-output'
        },
        'jobid': 'myjobid'
    }
    execution = Execution(input_dict)
    profile = {'access_key': 'haha', 'secret_key': 'lala'}
    userdata = execution.create_userdata(profile=profile)
    print(userdata)
    assert userdata
    assert '-a haha -s lala' in userdata
    # cleanup afterwards
    s3.delete_objects(Bucket='tibanna-output',
                      Delete={'Objects': [{
                          'Key': randomstr
                      }]})
示例#6
0
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
示例#7
0
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)
示例#8
0
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)