Skip to content

Commit 280402a

Browse files
NRL-1824 Fix persistent environment deploy and improve documentation
1 parent 3ef1892 commit 280402a

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ test-features-integration: check-warn ## Run the BDD feature tests in the integr
106106
--define="env=$(TF_WORKSPACE_NAME)" \
107107
--define="account_name=$(ENV)" \
108108
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
109+
--define="host=$(HOST)" \
109110
$(FEATURE_TEST_ARGS)
110111

111112
integration-test-with-custom_tag:
@@ -114,6 +115,7 @@ integration-test-with-custom_tag:
114115
--define="env=$(TF_WORKSPACE_NAME)" \
115116
--define="account_name=$(ENV)" \
116117
--define="use_shared_resources=${USE_SHARED_RESOURCES}" \
118+
--define="host=$(HOST)" \
117119
$(FEATURE_TEST_ARGS)
118120

119121
test-features-integration-report: check-warn ## Run the BDD feature tests in the integration environment and generate allure report therafter

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ To run all the feature integration tests and generate an interactive Allure repo
140140
make test-features-integration-report
141141
```
142142

143+
#### Persistent environment testing
144+
145+
To run feature tests against a persistent environment:
146+
147+
1. Select the appropriate Terraform workspace, ensure you are logged in the AWS mgmt account (see `terraform/infrastructure/README.md`), for example to test the `qa-1` environment:
148+
149+
```
150+
cd terraform/infrastructure
151+
make ENV=qa TF_WORKSPACE_NAME=qa-1 init
152+
cd ../..
153+
```
154+
155+
2. Switch to the relevant AWS account (e.g., test), then run:
156+
157+
```
158+
make ENV=qa TF_WORKSPACE_NAME=qa-1 HOST=qa-1.qa.record-locator.national.nhs.uk test-features-integration
159+
```
160+
143161
### Debugging Behave Integration Tests in VS Code
144162

145163
Integration tests can be debugged directly in **VS Code** using a launch configuration. Instructions on how to set this up for the first time and run the debugger are below.

terraform/infrastructure/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ This project has a number of "persistent environments", similar to traditional d
1616
| qa-sandbox | qa-sandbox-N | `etc/qa.tfvars` | test | `qa.record-locator.national.nhs.uk` | `internal-qa-sandbox.api.service.nhs.uk` |
1717
| int | int-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `int.api.service.nhs.uk` |
1818
| sandbox | int-sandbox-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `sandbox.api.service.nhs.uk` |
19-
| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `perftest.api.service.nhs.uk` |
19+
| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `internal-qa.api.service.nhs.uk` |
2020
| ref | ref-N | `etc/ref.tfvars` | test | `record-locator.ref.national.nhs.uk` | `ref.api.service.nhs.uk` |
2121
| prod | prod-N | `etc/prod.tfvars` | prod | `record-locator.national.nhs.uk` | `api.service.nhs.uk` |
2222

2323
The `N` in the TF workspace name repesents the stack id in that environment. So, for example, the internal-dev environment might have two stacks, `dev-1` and `dev-2` with TF workspace names matching their stack names. All resources for the `dev-1` stack will be contained within the `dev-1` TF workspace.
2424

2525
CI pipeline creates infrastructure in the dev AWS account. These will have workspace id of `nrl<jira-id>-<first six char of commit hash>` and use variables in `etc/dev.tfvars`
2626

27+
Please note: There is currently no dedicated APIGEE proxy for the perftest environment. As a temporary measure, `internal-qa.api.service.nhs.uk` points to perftest. You can switch the `internal-qa` APIGEE proxy between QA and perftest by running the `persistent environment deploy` or `switch active stack` GitHub Actions.
28+
2729
## Table of Contents
2830

2931
1. [Prerequisites](#prerequisites)

tests/features/environment.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ def before_all(context: Context):
1717

1818
context.env = context.config.userdata.get("env")
1919
context.account_name = context.config.userdata.get("account_name")
20-
context.is_shared_resources = context.config.userdata.get("is_shared_resources")
20+
context.use_shared_resources = context.config.userdata.get("use_shared_resources")
21+
context.host = context.config.userdata.get(
22+
"host", default=f"https://{context.env}.api.record-locator.dev.national.nhs.uk/"
23+
)
2124

2225
context.stack_name = (
23-
context.account_name if context.is_shared_resources else context.env
26+
context.account_name if context.use_shared_resources else context.env
2427
)
2528

26-
context.base_url = f"https://{context.env}.api.record-locator.dev.national.nhs.uk/"
29+
context.base_url = f"https://{context.host}/"
2730
context.request_id = "feature-test-request-id"
2831
context.correlation_id = "feature-test-correlation-id"
2932

tests/features/utils/certificates.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ def get_cert_path_for_environment(environment: Optional[str]) -> Tuple[str, str]
1212
if not environment:
1313
raise ValueError("Environment (env) not provided")
1414

15-
cert_path: Optional[Path] = None
16-
key_path: Optional[Path] = None
17-
18-
match environment:
19-
case "dev":
20-
cert_path = CLIENT_CERT_PATH / "dev.crt"
21-
key_path = CLIENT_CERT_PATH / "dev.key"
22-
23-
case _:
24-
cert_path = CLIENT_CERT_PATH / "dev.crt"
25-
key_path = CLIENT_CERT_PATH / "dev.key"
15+
# List only non-sandbox environments
16+
# Sandbox uses the same certs as their non-sandbox equivalents.
17+
ENVIRONMENTS = ["dev", "qa", "int", "ref", "perftest", "prod"]
18+
19+
selected_env = "dev" # default to dev (e.g: ci environments)
20+
for env in ENVIRONMENTS:
21+
# match dev-1, qa-2, etc. it works for sandbox too
22+
if environment == env or environment.startswith(f"{env}-"):
23+
selected_env = env
24+
break
25+
26+
cert_path = CLIENT_CERT_PATH / f"{selected_env}.crt"
27+
key_path = CLIENT_CERT_PATH / f"{selected_env}.key"
2628

2729
if not cert_path.exists() or not key_path.exists():
2830
raise FileNotFoundError(

0 commit comments

Comments
 (0)