Exemplo n.º 1
0
def step_impl(context, first_stack, second_stack):
    stacks = [
        get_cloudformation_stack_name(context, first_stack),
        get_cloudformation_stack_name(context, second_stack)
    ]
    creation_times = get_stack_creation_times(context, stacks)

    assert creation_times[stacks[0]] < creation_times[stacks[1]]
Exemplo n.º 2
0
def step_impl(context, first_stack, second_stack):
    stacks = [
        get_cloudformation_stack_name(context, first_stack),
        get_cloudformation_stack_name(context, second_stack)
    ]
    creation_times = get_stack_creation_times(context, stacks)

    assert creation_times[stacks[0]] < creation_times[stacks[1]]
Exemplo n.º 3
0
def step_impl(context, stack_name, dependant_stack_name, desired_state):
    full_name = get_cloudformation_stack_name(context, stack_name)
    status = get_stack_status(context, full_name)
    assert (status is None)

    dep_full_name = get_cloudformation_stack_name(context,
                                                  dependant_stack_name)
    sceptre_context = SceptreContext(command_path=stack_name + '.yaml',
                                     project_path=context.sceptre_dir)

    sceptre_plan = SceptrePlan(sceptre_context)
    dep_status = sceptre_plan.get_status()
    dep_status = get_stack_status(context, dep_full_name)
    assert (dep_status == desired_state)
Exemplo n.º 4
0
def step_impl(context, stack_name, desired_status):
    full_name = get_cloudformation_stack_name(context, stack_name)

    status = get_stack_status(context, full_name)
    if status != desired_status:
        delete_stack(context, full_name)
        if desired_status == "CREATE_COMPLETE":
            body = read_template_file(context, "valid_template.json")
            create_stack(context, full_name, body)
        elif desired_status == "CREATE_FAILED":
            body = read_template_file(context, "invalid_template.json")
            kwargs = {"OnFailure": "DO_NOTHING"}
            create_stack(context, full_name, body, **kwargs)
        elif desired_status == "UPDATE_COMPLETE":
            body = read_template_file(context, "valid_template.json")
            create_stack(context, full_name, body)
            body = read_template_file(context, "updated_template.json")
            update_stack(context, full_name, body)
        elif desired_status == "ROLLBACK_COMPLETE":
            body = read_template_file(context, "invalid_template.json")
            kwargs = {"OnFailure": "ROLLBACK"}
            create_stack(context, full_name, body, **kwargs)

    status = get_stack_status(context, full_name)
    assert (status == desired_status)
Exemplo n.º 5
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    topic_arn = _get_output("TopicName", full_name)
    client = boto3.client("sns")
    client.set_topic_attributes(TopicArn=topic_arn,
                                AttributeName="DisplayName",
                                AttributeValue="WrongName")
Exemplo n.º 6
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    status = get_stack_status(context, full_name)
    if status is not None:
        delete_stack(context, full_name)
    status = get_stack_status(context, full_name)
    assert (status is None)
Exemplo n.º 7
0
def step_impl(context, stack_name, change_set_name, filename):
    full_name = get_cloudformation_stack_name(context, stack_name)
    retry_boto_call(context.client.create_change_set,
                    StackName=full_name,
                    ChangeSetName=change_set_name,
                    TemplateBody=read_template_file(context, filename))
    wait_for_final_state(context, stack_name, change_set_name)
Exemplo n.º 8
0
def step_impl(context, aws_stack_name, stack_name, template_name):
    full_aws_stack_name = get_cloudformation_stack_name(
        context, aws_stack_name)
    env = Environment(context.sceptre_dir, os.path.dirname(stack_name))
    stack_base_name = os.path.basename(stack_name)
    context.response = env.import_stack(full_aws_stack_name, stack_base_name,
                                        template_name)
Exemplo n.º 9
0
def step_impl(context, stack_name, state):
    full_name = get_cloudformation_stack_name(context, stack_name)
    retry_boto_call(
        context.client.set_stack_policy,
        StackName=full_name,
        StackPolicyBody=generate_stack_policy(state)
    )
Exemplo n.º 10
0
def get_full_stack_names(context, environment_name):
    stack_names = get_stack_names(context, environment_name)

    return {
        stack_name: get_cloudformation_stack_name(context, stack_name)
        for stack_name in stack_names
    }
Exemplo n.º 11
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    status = get_stack_status(context, full_name)
    if status is not None:
        delete_stack(context, full_name)
    status = get_stack_status(context, full_name)
    assert (status is None)
Exemplo n.º 12
0
def get_full_stack_names(context, environment_name):
    stack_names = get_stack_names(context, environment_name)

    return {
        stack_name: get_cloudformation_stack_name(context, stack_name)
        for stack_name in stack_names
    }
Exemplo n.º 13
0
def step_impl(context, stack_name, desired_status):
    full_name = get_cloudformation_stack_name(context, stack_name)

    status = get_stack_status(context, full_name)
    if status != desired_status:
        delete_stack(context, full_name)
        if desired_status == "CREATE_COMPLETE":
            body = read_template_file(context, "valid_template.json")
            create_stack(context, full_name, body)
        elif desired_status == "CREATE_FAILED":
            body = read_template_file(context, "invalid_template.json")
            kwargs = {"OnFailure": "DO_NOTHING"}
            create_stack(context, full_name, body, **kwargs)
        elif desired_status == "UPDATE_COMPLETE":
            body = read_template_file(context, "valid_template.json")
            create_stack(context, full_name, body)
            body = read_template_file(context, "updated_template.json")
            update_stack(context, full_name, body)
        elif desired_status == "ROLLBACK_COMPLETE":
            body = read_template_file(context, "invalid_template.json")
            kwargs = {"OnFailure": "ROLLBACK"}
            create_stack(context, full_name, body, **kwargs)

    status = get_stack_status(context, full_name)
    assert (status == desired_status)
Exemplo n.º 14
0
def step_impl(context, stack_name, state):
    full_name = get_cloudformation_stack_name(context, stack_name)
    retry_boto_call(
        context.client.set_stack_policy,
        StackName=full_name,
        StackPolicyBody=generate_stack_policy(state)
    )
Exemplo n.º 15
0
def get_full_stack_names(context, stack_group_name):
    stack_names = get_stack_names(context, stack_group_name)

    return {
        stack_name: get_cloudformation_stack_name(context, stack_name)
        for stack_name in stack_names
    }
Exemplo n.º 16
0
def step_impl(context, stack_name, change_set_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    retry_boto_call(
        context.client.delete_change_set,
        ChangeSetName=change_set_name,
        StackName=full_name
    )
Exemplo n.º 17
0
def step_impl(context, stack_name, tag_name, desired_tag_value):
    full_name = get_cloudformation_stack_name(context, stack_name)

    tags = get_stack_tags(context, full_name)
    tag = next((tag for tag in tags if tag['Key'] == tag_name),
               {'Value': None})

    assert (tag['Value'] == desired_tag_value)
Exemplo n.º 18
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.list_change_sets,
                               StackName=full_name)

    del response["ResponseMetadata"]
    for output in context.output:
        del output["ResponseMetadata"]
        assert response == output
Exemplo n.º 19
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.list_change_sets,
                               StackName=full_name)
    for change_set in response["Summaries"]:
        time.sleep(1)
        retry_boto_call(context.client.delete_change_set,
                        ChangeSetName=change_set['ChangeSetName'],
                        StackName=full_name)
Exemplo n.º 20
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.describe_stack_resources,
                               StackName=full_name)
    properties = {"LogicalResourceId", "PhysicalResourceId"}
    formatted_response = [{k: v
                           for k, v in item.items() if k in properties}
                          for item in response["StackResources"]]

    assert [{stack_name: formatted_response}] == context.output
Exemplo n.º 21
0
def step_impl(context, stack_name, change_set_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.describe_stacks,
                               StackName=full_name)

    change_set_id = response["Stacks"][0]["ChangeSetId"]
    stack_status = response["Stacks"][0]["StackStatus"]

    assert stack_status == "UPDATE_COMPLETE"
    assert change_set_name == change_set_id.split("/")[1]
Exemplo n.º 22
0
def step_impl(context, change_set_name, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.describe_change_set,
                               StackName=full_name,
                               ChangeSetName=change_set_name)

    del response["ResponseMetadata"]
    del context.output["ResponseMetadata"]

    assert response == context.output
Exemplo n.º 23
0
def step_impl(context, stack_name, template_name):
    full_name = get_cloudformation_stack_name(context, stack_name)

    status = get_stack_status(context, full_name)
    if status != "CREATE_COMPLETE":
        delete_stack(context, full_name)
        body = read_template_file(context, template_name)
        create_stack(context, full_name, body)

    status = get_stack_status(context, full_name)
    assert (status == "CREATE_COMPLETE")
Exemplo n.º 24
0
def step_impl(context, stack_name, template_name):
    full_name = get_cloudformation_stack_name(context, stack_name)

    status = get_stack_status(context, full_name)
    if status != "CREATE_COMPLETE":
        delete_stack(context, full_name)
        body = read_template_file(context, template_name)
        create_stack(context, full_name, body)

    status = get_stack_status(context, full_name)
    assert (status == "CREATE_COMPLETE")
Exemplo n.º 25
0
def step_impl(context, stack_name, change_set_name, filename):
    full_name = get_cloudformation_stack_name(context, stack_name)
    retry_boto_call(context.client.create_change_set,
                    StackName=full_name,
                    Capabilities=[
                        'CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM',
                        'CAPABILITY_AUTO_EXPAND'
                    ],
                    ChangeSetName=change_set_name,
                    TemplateBody=read_template_file(context, filename))
    wait_for_final_state(context, stack_name, change_set_name)
Exemplo n.º 26
0
def wait_for_final_state(context, stack_name, change_set_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    delay = 1
    max_retries = 10
    attempts = 0
    while attempts < max_retries:
        status = get_change_set_status(context, full_name, change_set_name)
        in_progress = "IN_PROGRESS" not in status and "PENDING" not in status
        if status is None or in_progress:
            return
        time.sleep(delay)
        attempts += 1
    raise Exception("Timeout waiting for change set to reach final state.")
Exemplo n.º 27
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(
        context.client.describe_stack_resources,
        StackName=full_name
    )

    properties = {"LogicalResourceId", "PhysicalResourceId"}
    formatted_response = [
            {k: v for k, v in item.items() if k in properties}
            for item in response["StackResources"]
    ]

    assert formatted_response == context.output
Exemplo n.º 28
0
def step_impl(context, stack_name):
    expected_resources = {}
    sceptre_response = []
    for stack_resources in context.response.values():
        for resource in stack_resources:
            sceptre_response.append(resource["PhysicalResourceId"])

    response = retry_boto_call(context.client.describe_stack_resources,
                               StackName=get_cloudformation_stack_name(
                                   context, stack_name))
    expected_resources[stack_name] = response["StackResources"]

    for short_name, resources in expected_resources.items():
        for resource in resources:
            sceptre_response.remove(resource["PhysicalResourceId"])

    assert sceptre_response == []
Exemplo n.º 29
0
def step_impl(context, stack_name):
    expected_resources = {}
    sceptre_response = []
    for stack_resources in context.response.values():
        for resource in stack_resources:
            sceptre_response.append(resource["PhysicalResourceId"])

    response = retry_boto_call(
        context.client.describe_stack_resources,
        StackName=get_cloudformation_stack_name(context, stack_name)
    )
    expected_resources[stack_name] = response["StackResources"]

    for short_name, resources in expected_resources.items():
        for resource in resources:
            sceptre_response.remove(resource["PhysicalResourceId"])

    assert sceptre_response == []
Exemplo n.º 30
0
def get_stack_resources(context, stack_name):
    cf_stack_name = get_cloudformation_stack_name(context, stack_name)
    resources = retry_boto_call(context.client.describe_stack_resources,
                                StackName=cf_stack_name)
    return resources['StackResources']
Exemplo n.º 31
0
def step_impl(context, stack_name, state):
    full_name = get_cloudformation_stack_name(context, stack_name)
    policy = get_stack_policy(context, full_name)

    if state == 'not set':
        assert (policy is None)
Exemplo n.º 32
0
def step_impl(context, stack_name, change_set_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    status = get_change_set_status(context, full_name, change_set_name)

    assert status is None
Exemplo n.º 33
0
def step_impl(context, stack_name, state):
    full_name = get_cloudformation_stack_name(context, stack_name)
    policy = get_stack_policy(context, full_name)

    if state == 'not set':
        assert (policy is None)
Exemplo n.º 34
0
def step_impl(context, stack_name):
    full_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.list_change_sets,
                               StackName=full_name)
    for output in context.output:
        assert output == {stack_name: response.get("Summaries", {})}
Exemplo n.º 35
0
def step_impl(context, stack_name, region_name, desired_status):
    with region(region_name):
        full_name = get_cloudformation_stack_name(context, stack_name)
        status = get_stack_status(context, full_name, region_name)

        assert (status == desired_status)
Exemplo n.º 36
0
def describe_stack(context, stack_name) -> dict:
    cf_stack_name = get_cloudformation_stack_name(context, stack_name)
    response = retry_boto_call(context.client.describe_stacks,
                               StackName=cf_stack_name)
    return response['Stacks'][0]
Exemplo n.º 37
0
def step_impl(context, stack_name, desired_status):
    full_name = get_cloudformation_stack_name(context, stack_name)
    status = get_stack_status(context, full_name)
    assert (status == desired_status)