Skip to content

Commit

Permalink
Merge branch 'master' into ah/RobReus/feature/issue-359/use-previous-…
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
alex-harvey-z3q authored Aug 3, 2024
2 parents 4624444 + deef08e commit aa3cf2c
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 326 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/comment-integration-tests.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/awslabs/cfn-python-lint
rev: v1.2.5a9
rev: v1.8.2
hooks:
- id: cfn-python-lint
args:
Expand Down Expand Up @@ -47,7 +47,7 @@ repos:
language_version: python3.10
args: ['--check']
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.28.4
rev: 0.29.1
hooks:
- id: check-github-workflows
- id: check-github-actions
15 changes: 12 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,23 @@ during development.
to work with an AWS account that you have access to. You can use the same user
or role that you use for Github actions.

#### run all tests

```bash
$ AWS_DEFAULT_REGION=eu-west-1 poetry run behave integration-tests/features --junit --junit-directory build/behave
```

_Note_: All integration tests are set up to run in `eu-west-*` region. If you prefer
to run in a different region you must update the region in each test before running it
to run in a different region, you must update the region in each test before running it:

```bash
$ grep -r eu-west integration-tests
```

#### run all tests
Edit the files.

```bash
$ AWS_PROFILE=<profile> AWS_DEFAULT_REGION=<region> poetry run behave integration-tests/features --junit --junit-directory build/behave
$ AWS_PROFILE=<your-profile> AWS_DEFAULT_REGION=<your-preferred-default-region> poetry run behave integration-tests/features --junit --junit-directory build/behave
```

#### run a specific feature
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/features/create-change-set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Feature: Create change set
Given stack "1/A" does not exist
and the template for stack "1/A" is "valid_template.json"
When the user creates change set "A" for stack "1/A"
Then a "ClientError" is raised
and the user is told "stack does not exist"
Then stack "1/A" has change set "A" in "CREATE_COMPLETE" state

Scenario: create new change set with updated template and ignore dependencies
Given stack "1/A" exists in "CREATE_COMPLETE" state
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/features/describe-change-set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Feature: Describe change sets
Given stack "1/A" exists in "CREATE_COMPLETE" state
and stack "1/A" has no change sets
When the user describes change set "A" for stack "1/A"
Then a "ClientError" is raised
and the user is told "change set does not exist"
Then the user is told "Failed describing Change Set"

Scenario: describe a change set that exists with ignore dependencies
Given stack "1/A" exists in "CREATE_COMPLETE" state
Expand Down
23 changes: 0 additions & 23 deletions integration-tests/features/describe-stack-group-resources.feature

This file was deleted.

25 changes: 0 additions & 25 deletions integration-tests/features/describe-stack-group.feature

This file was deleted.

11 changes: 0 additions & 11 deletions integration-tests/features/describe-stack-resources.feature

This file was deleted.

3 changes: 1 addition & 2 deletions integration-tests/features/execute-change-set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Feature: Execute change set
Given stack "1/A" exists in "CREATE_COMPLETE" state
And stack "1/A" does not have change set "A"
When the user executes change set "A" for stack "1/A"
Then a "ClientError" is raised
And the user is told "change set does not exist"
Then the user is told "change set does not exist"

Scenario: execute a change set that exists with ignore dependencies
Given stack "1/A" exists in "CREATE_COMPLETE" state
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/steps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ def step_impl(context, message):
msg = context.error.response["Error"]["Message"]
assert msg.endswith("does not exist")
elif message == "change set does not exist":
msg = context.error.response["Error"]["Message"]
assert msg.endswith("does not exist")
assert context.log_capture.find_event("does not exist")
elif message == "the template is valid":
for stack, status in context.response.items():
assert status["ResponseMetadata"]["HTTPStatusCode"] == 200
elif message == "the template is malformed":
msg = context.error.response["Error"]["Message"]
assert msg.startswith("Template format error")
elif message == "Failed describing Change Set":
assert context.log_capture.find_event(message)
else:
raise Exception("Step has incorrect message")

Expand Down
122 changes: 0 additions & 122 deletions integration-tests/steps/stack_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,68 +97,6 @@ def step_impl(context, stack_group_name):
sceptre_plan.delete()


@when('the user describes stack_group "{stack_group_name}"')
def step_impl(context, stack_group_name):
sceptre_context = SceptreContext(
command_path=stack_group_name, project_path=context.sceptre_dir
)

sceptre_plan = SceptrePlan(sceptre_context)
responses = sceptre_plan.describe()

stack_names = get_full_stack_names(context, stack_group_name)
cfn_stacks = {}

for response in responses.values():
if response is None:
continue
for stack in response["Stacks"]:
cfn_stacks[stack["StackName"]] = stack["StackStatus"]

context.response = [
{short_name: cfn_stacks[full_name]}
for short_name, full_name in stack_names.items()
if cfn_stacks.get(full_name)
]


@when('the user describes stack_group "{stack_group_name}" with ignore dependencies')
def step_impl(context, stack_group_name):
sceptre_context = SceptreContext(
command_path=stack_group_name,
project_path=context.sceptre_dir,
ignore_dependencies=True,
)

sceptre_plan = SceptrePlan(sceptre_context)
responses = sceptre_plan.describe()

stack_names = get_full_stack_names(context, stack_group_name)
cfn_stacks = {}

for response in responses.values():
if response is None:
continue
for stack in response["Stacks"]:
cfn_stacks[stack["StackName"]] = stack["StackStatus"]

context.response = [
{short_name: cfn_stacks[full_name]}
for short_name, full_name in stack_names.items()
if cfn_stacks.get(full_name)
]


@when('the user describes resources in stack_group "{stack_group_name}"')
def step_impl(context, stack_group_name):
sceptre_context = SceptreContext(
command_path=stack_group_name, project_path=context.sceptre_dir
)

sceptre_plan = SceptrePlan(sceptre_context)
context.response = sceptre_plan.describe_resources().values()


@when(
'the user describes resources in stack_group "{stack_group_name}" with ignore dependencies'
)
Expand Down Expand Up @@ -196,21 +134,6 @@ def step_impl(context, stack_group_name):
check_stack_status(context, full_stack_names, None)


@then('all stacks in stack_group "{stack_group_name}" are described as "{status}"')
def step_impl(context, stack_group_name, status):
stacks_names = get_stack_names(context, stack_group_name)
expected_response = [{stack_name: status} for stack_name in stacks_names]
for response in context.response:
assert response in expected_response


@then("no resources are described")
def step_impl(context):
for stack_resources in context.response:
stack_name = next(iter(stack_resources))
assert stack_resources == {stack_name: []}


@then('stack "{stack_name}" is described as "{status}"')
def step_impl(context, stack_name, status):
response = next(
Expand All @@ -221,51 +144,6 @@ def step_impl(context, stack_name, status):
assert response[stack_name] == status


@then('only all resources in stack_group "{stack_group_name}" are described')
def step_impl(context, stack_group_name):
stacks_names = get_full_stack_names(context, stack_group_name)
expected_resources = {}
sceptre_response = []
for stack_resources in context.response:
for resource in stack_resources.values():
sceptre_response.append(resource[0]["PhysicalResourceId"])

for short_name, full_name in stacks_names.items():
time.sleep(1)
response = retry_boto_call(
context.client.describe_stack_resources, StackName=full_name
)
expected_resources[short_name] = response["StackResources"]

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

assert sceptre_response == []


@then('only resources in stack "{stack_name}" are described')
def step_impl(context, stack_name):
expected_resources = {}
sceptre_response = []
for stack_resources in context.response:
for resource in stack_resources.values():
if resource:
sceptre_response.append(resource[0].get("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 == []


@then('that stack "{first_stack}" was created before "{second_stack}"')
def step_impl(context, first_stack, second_stack):
stacks = [
Expand Down
39 changes: 0 additions & 39 deletions integration-tests/steps/stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,30 +310,6 @@ def step_impl(context, stack_name):
launch_stack(context, stack_name, False, True)


@when('the user describes the resources of stack "{stack_name}"')
def step_impl(context, stack_name):
sceptre_context = SceptreContext(
command_path=stack_name + ".yaml", project_path=context.sceptre_dir
)

sceptre_plan = SceptrePlan(sceptre_context)
context.output = list(sceptre_plan.describe_resources().values())


@when(
'the user describes the resources of stack "{stack_name}" with ignore dependencies'
)
def step_impl(context, stack_name):
sceptre_context = SceptreContext(
command_path=stack_name + ".yaml",
project_path=context.sceptre_dir,
ignore_dependencies=True,
)

sceptre_plan = SceptrePlan(sceptre_context)
context.output = list(sceptre_plan.describe_resources().values())


@when('the user diffs stack "{stack_name}" with "{diff_type}"')
def step_impl(context, stack_name, diff_type):
sceptre_context = SceptreContext(
Expand Down Expand Up @@ -381,21 +357,6 @@ def step_impl(context, stack_name):
assert status is None


@then('the resources of stack "{stack_name}" are described')
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


@then(
'stack "{stack_name}" does not exist and stack "{dependant_stack_name}" exists in "{desired_state}"'
)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [

[tool.poetry.plugins."sceptre.hooks"]
"asg_scheduled_actions" = "sceptre.hooks.asg_scaling_processes:ASGScalingProcesses"
"asg_scaling_processes" = "sceptre.hooks.asg_scaling_processes:ASGScalingProcesses"
"cmd" = "sceptre.hooks.cmd:Cmd"

[tool.poetry.plugins."sceptre.resolvers"]
Expand Down
3 changes: 3 additions & 0 deletions sceptre/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ def simplify_change_set_description(response):
:returns: A more concise description of the change set.
:rtype: dict
"""
if not response:
return {"ChangeSetName": "ChangeSetNotFound"}

desired_response_items = [
"ChangeSetName",
"CreationTime",
Expand Down
Loading

0 comments on commit aa3cf2c

Please sign in to comment.