示例#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]]
示例#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]]
示例#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)
示例#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)
示例#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")
示例#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)
示例#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)
示例#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)
示例#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)
    )
示例#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
    }
示例#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)
示例#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
    }
示例#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)
示例#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)
    )
示例#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
    }
示例#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
    )
示例#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)
示例#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
示例#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)
示例#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
示例#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]
示例#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
示例#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")
示例#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")
示例#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)
示例#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.")
示例#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
示例#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 == []
示例#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 == []
示例#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']
示例#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)
示例#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
示例#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)
示例#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", {})}
示例#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)
示例#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]
示例#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)