コード例 #1
0
ファイル: test_kumo_aws.py プロジェクト: webratz/gcdt-kumo
def cleanup_stack_ec2(awsclient):
    """Remove the ec2 stack to cleanup after test run.

    This is intended to be called during test teardown"""
    yield
    # cleanup
    exit_code = delete_stack(awsclient, config_ec2)
    # check whether delete was completed!
    assert not exit_code, ('delete_stack was not completed\n' +
                 'please make sure to clean up the stack manually')
コード例 #2
0
ファイル: test_kumo_aws.py プロジェクト: webratz/gcdt-kumo
def simple_cloudformation_stack_with_rds(awsclient):
    # create a stack we use for the test lifecycle
    stack_name = "infra-dev-kumo-sample-stack-with-rds"
    are_credentials_still_valid(awsclient)
    cloudformation_simple_stack_with_rds, _ = load_cloudformation_template(
        here('resources/simple_cloudformation_stack_with_rds/cloudformation.py')
    )
    exit_code = deploy_stack(awsclient, {}, config_rds_stack,
                             cloudformation_simple_stack_with_rds,
                             override_stack_policy=False)
    assert not exit_code

    yield stack_name
    # cleanup
    exit_code = delete_stack(awsclient, config_rds_stack)
    # check whether delete was completed!
    assert not exit_code, 'delete_stack was not completed please make sure to clean up the stack manually'
コード例 #3
0
ファイル: test_kumo_aws.py プロジェクト: webratz/gcdt-kumo
def test_kumo_context_contains_stack_output(awsclient):
    cloudformation_simple_stack, _ = load_cloudformation_template(
        here('resources/simple_cloudformation_stack/cloudformation.py')
    )
    context = {}
    exit_code = deploy_stack(awsclient, context, config_simple_stack,
                             cloudformation_simple_stack,
                             override_stack_policy=False)
    assert exit_code == 0
    assert 'stack_output' in context
    assert len(context['stack_output']) == 1
    assert context['stack_output'][0]['Description'] == 'Name of S3 bucket'
    assert context['stack_output'][0]['OutputKey'] == 'BucketName'
    assert context['stack_output'][0]['OutputValue'].startswith('infra-dev-kumo-sample-stack-s3bucket1')

    # cleanup
    exit_code = delete_stack(awsclient, config_simple_stack)
    assert exit_code == 0
コード例 #4
0
ファイル: test_kumo_aws.py プロジェクト: webratz/gcdt-kumo
def sample_cloudformation_stack_with_hooks(awsclient):
    # create a stack we use for the test lifecycle
    are_credentials_still_valid(awsclient)
    cloudformation_stack, _ = load_cloudformation_template(
        here('resources/sample_cloudformation_stack_with_hooks/cloudformation.py')
    )
    config_stack = fix_deprecated_kumo_config(read_json_config(
        here('resources/sample_cloudformation_stack_with_hooks/gcdt_dev.json')
    ))['kumo']
    exit_code = deploy_stack(awsclient, {}, config_stack,
                             cloudformation_stack,
                             override_stack_policy=False)
    assert not exit_code

    yield 'infra-dev-kumo-sample-stack-with-hooks'
    # cleanup
    exit_code = delete_stack(awsclient, config_stack)
    # check whether delete was completed!
    assert not exit_code, 'delete_stack was not completed please make sure to clean up the stack manually'
コード例 #5
0
ファイル: test_kumo_aws.py プロジェクト: webratz/gcdt-kumo
def test_create_update_stack_artifactbucket(awsclient, temp_cloudformation_policy,
                                     cleanup_roles, cleanup_buckets):
    # create a stack we use for the test lifecycle
    cloudformation_simple_stack, _ = load_cloudformation_template(
        here('resources/simple_cloudformation_stack/cloudformation.py')
    )

    upload_conf = {
        'stack': {
            'StackName': "infra-dev-kumo-sample-stack",
            'artifactBucket': "unittest-kumo-artifact-bucket"
        },
        'parameters': {
            'InstanceType': "t2.micro",
        }
    }

    region = awsclient.get_client('s3').meta.region_name
    account = os.getenv('ACCOUNT', None)
    # add account prefix to artifact bucket config
    if account:
        upload_conf['stack']['artifactBucket'] = \
            '%s-unittest-kumo-artifact-bucket' % account

    artifact_bucket = _get_artifact_bucket(upload_conf)
    prepare_artifacts_bucket(awsclient, artifact_bucket)
    cleanup_buckets.append(artifact_bucket)
    dest_key = 'kumo/%s/%s-cloudformation.json' % (region,
                                                   _get_stack_name(upload_conf))
    expected_s3url = 'https://s3-%s.amazonaws.com/%s/%s' % (region,
                                                            artifact_bucket,
                                                            dest_key)
    actual_s3url = _s3_upload(awsclient, upload_conf,
                              generate_template({}, upload_conf, cloudformation_simple_stack))
    assert expected_s3url == actual_s3url

    # create role to use for cloudformation update
    role = create_role_helper(
        awsclient,
        'unittest_%s_kumo' % utils.random_string(),
        policies=[
            temp_cloudformation_policy,
            'arn:aws:iam::aws:policy/AWSCodeDeployReadOnlyAccess',
            'arn:aws:iam::aws:policy/AmazonS3FullAccess'
        ],
        principal_service=['cloudformation.amazonaws.com']
    )
    cleanup_roles.append(role['RoleName'])

    # create
    exit_code = deploy_stack(awsclient, {}, upload_conf,
                             cloudformation_simple_stack,
                             override_stack_policy=False)
    assert exit_code == 0
    stack_id = get_stack_id(awsclient, upload_conf['stack']['StackName'])
    wait_for_stack_create_complete(awsclient, stack_id)

    # update (as a change we add the RoleARN)
    upload_conf['stack']['RoleARN'] = role['Arn']

    # update the stack
    changed = get_parameter_diff(awsclient, upload_conf)
    assert not changed
    exit_code = deploy_stack(awsclient, {}, upload_conf,
                             cloudformation_simple_stack,
                             override_stack_policy=False)
    assert exit_code == 0
    wait_for_stack_update_complete(awsclient, stack_id)

    # cleanup
    exit_code = delete_stack(awsclient, upload_conf)
    assert exit_code == 0
    wait_for_stack_delete_complete(awsclient, stack_id)