예제 #1
0
def needs_aws(test_item):
    """
    Use as a decorator before test classes or methods to only run them if AWS usable.
    """
    test_item = _mark_test('aws', test_item)
    keyName = os.getenv('TOIL_AWS_KEYNAME')
    if not keyName or keyName is None:
        return unittest.skip("Set TOIL_AWS_KEYNAME to include this test.")(
            test_item)

    try:
        # noinspection PyUnresolvedReferences
        from boto import config
    except ImportError:
        return unittest.skip(
            "Install Toil with the 'aws' extra to include this test.")(
                test_item)
    except:
        raise
    else:
        dot_aws_credentials_path = os.path.expanduser('~/.aws/credentials')
        boto_credentials = config.get('Credentials', 'aws_access_key_id')
        if boto_credentials:
            return test_item
        if os.path.exists(dot_aws_credentials_path) or runningOnEC2():
            # Assume that EC2 machines like the Jenkins slave that we run CI on will have IAM roles
            return test_item
        else:
            return unittest.skip(
                "Configure ~/.aws/credentials with AWS credentials to include "
                "this test.")(test_item)
예제 #2
0
 def awsRegion(cls):
     """
     Use us-west-2 unless running on EC2, in which case use the region in which
     the instance is located
     """
     if runningOnEC2():
         return cls._region()
     else:
         return 'us-west-2'
예제 #3
0
def needs_aws_s3(test_item):
    """Use as a decorator before test classes or methods to run only if AWS S3 is usable."""
    # TODO: we just check for generic access to the AWS account
    test_item = _mark_test('aws-s3', test_item)
    try:
        from boto import config
        boto_credentials = config.get('Credentials', 'aws_access_key_id')
    except ImportError:
        return unittest.skip(
            "Install Toil with the 'aws' extra to include this test.")(
                test_item)

    if not (boto_credentials or os.path.exists(
            os.path.expanduser('~/.aws/credentials')) or runningOnEC2()):
        return unittest.skip(
            "Configure AWS credentials to include this test.")(test_item)
    return test_item
예제 #4
0
def needs_aws(test_item):
    """Use as a decorator before test classes or methods to run only if AWS is usable."""
    test_item = _mark_test('aws', test_item)
    try:
        from boto import config
        boto_credentials = config.get('Credentials', 'aws_access_key_id')
    except ImportError:
        return unittest.skip(
            "Install Toil with the 'aws' extra to include this test.")(
                test_item)

    if not (boto_credentials or os.path.exists(
            os.path.expanduser('~/.aws/credentials')) or runningOnEC2()):
        return unittest.skip(
            "Configure AWS credentials to include this test.")(test_item)
    elif not os.getenv('TOIL_AWS_KEYNAME'):
        return unittest.skip("Set TOIL_AWS_KEYNAME to include this test.")(
            test_item)
    return test_item