From 280402a083b54d31f8c246b2d191130ee3126ed6 Mon Sep 17 00:00:00 2001 From: "Axel Garcia K." Date: Mon, 17 Nov 2025 22:59:00 +0000 Subject: [PATCH 1/2] NRL-1824 Fix persistent environment deploy and improve documentation --- Makefile | 2 ++ README.md | 18 ++++++++++++++++++ terraform/infrastructure/README.md | 4 +++- tests/features/environment.py | 9 ++++++--- tests/features/utils/certificates.py | 24 +++++++++++++----------- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 00104a48c..77876bb03 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ test-features-integration: check-warn ## Run the BDD feature tests in the integr --define="env=$(TF_WORKSPACE_NAME)" \ --define="account_name=$(ENV)" \ --define="use_shared_resources=${USE_SHARED_RESOURCES}" \ + --define="host=$(HOST)" \ $(FEATURE_TEST_ARGS) integration-test-with-custom_tag: @@ -114,6 +115,7 @@ integration-test-with-custom_tag: --define="env=$(TF_WORKSPACE_NAME)" \ --define="account_name=$(ENV)" \ --define="use_shared_resources=${USE_SHARED_RESOURCES}" \ + --define="host=$(HOST)" \ $(FEATURE_TEST_ARGS) test-features-integration-report: check-warn ## Run the BDD feature tests in the integration environment and generate allure report therafter diff --git a/README.md b/README.md index 1ebb41ab9..1a0c0e443 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,24 @@ To run all the feature integration tests and generate an interactive Allure repo make test-features-integration-report ``` +#### Persistent environment testing + +To run feature tests against a persistent environment: + +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: + + ``` + cd terraform/infrastructure + make ENV=qa TF_WORKSPACE_NAME=qa-1 init + cd ../.. + ``` + +2. Switch to the relevant AWS account (e.g., test), then run: + + ``` + make ENV=qa TF_WORKSPACE_NAME=qa-1 HOST=qa-1.qa.record-locator.national.nhs.uk test-features-integration + ``` + ### Debugging Behave Integration Tests in VS Code 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. diff --git a/terraform/infrastructure/README.md b/terraform/infrastructure/README.md index a78ac05b8..dee0e17ff 100644 --- a/terraform/infrastructure/README.md +++ b/terraform/infrastructure/README.md @@ -16,7 +16,7 @@ This project has a number of "persistent environments", similar to traditional d | qa-sandbox | qa-sandbox-N | `etc/qa.tfvars` | test | `qa.record-locator.national.nhs.uk` | `internal-qa-sandbox.api.service.nhs.uk` | | int | int-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `int.api.service.nhs.uk` | | sandbox | int-sandbox-N | `etc/int.tfvars` | test | `record-locator.int.national.nhs.uk` | `sandbox.api.service.nhs.uk` | -| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `perftest.api.service.nhs.uk` | +| perftest | perftest-N | `etc/perftest.tfvars` | test | `perftest.record-locator.national.nhs.uk` | `internal-qa.api.service.nhs.uk` | | ref | ref-N | `etc/ref.tfvars` | test | `record-locator.ref.national.nhs.uk` | `ref.api.service.nhs.uk` | | prod | prod-N | `etc/prod.tfvars` | prod | `record-locator.national.nhs.uk` | `api.service.nhs.uk` | @@ -24,6 +24,8 @@ The `N` in the TF workspace name repesents the stack id in that environment. So, CI pipeline creates infrastructure in the dev AWS account. These will have workspace id of `nrl-` and use variables in `etc/dev.tfvars` +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. + ## Table of Contents 1. [Prerequisites](#prerequisites) diff --git a/tests/features/environment.py b/tests/features/environment.py index 66249009b..76e5348e9 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -17,13 +17,16 @@ def before_all(context: Context): context.env = context.config.userdata.get("env") context.account_name = context.config.userdata.get("account_name") - context.is_shared_resources = context.config.userdata.get("is_shared_resources") + context.use_shared_resources = context.config.userdata.get("use_shared_resources") + context.host = context.config.userdata.get( + "host", default=f"https://{context.env}.api.record-locator.dev.national.nhs.uk/" + ) context.stack_name = ( - context.account_name if context.is_shared_resources else context.env + context.account_name if context.use_shared_resources else context.env ) - context.base_url = f"https://{context.env}.api.record-locator.dev.national.nhs.uk/" + context.base_url = f"https://{context.host}/" context.request_id = "feature-test-request-id" context.correlation_id = "feature-test-correlation-id" diff --git a/tests/features/utils/certificates.py b/tests/features/utils/certificates.py index b5501356e..75c5843b0 100644 --- a/tests/features/utils/certificates.py +++ b/tests/features/utils/certificates.py @@ -12,17 +12,19 @@ def get_cert_path_for_environment(environment: Optional[str]) -> Tuple[str, str] if not environment: raise ValueError("Environment (env) not provided") - cert_path: Optional[Path] = None - key_path: Optional[Path] = None - - match environment: - case "dev": - cert_path = CLIENT_CERT_PATH / "dev.crt" - key_path = CLIENT_CERT_PATH / "dev.key" - - case _: - cert_path = CLIENT_CERT_PATH / "dev.crt" - key_path = CLIENT_CERT_PATH / "dev.key" + # List only non-sandbox environments + # Sandbox uses the same certs as their non-sandbox equivalents. + ENVIRONMENTS = ["dev", "qa", "int", "ref", "perftest", "prod"] + + selected_env = "dev" # default to dev (e.g: ci environments) + for env in ENVIRONMENTS: + # match dev-1, qa-2, etc. it works for sandbox too + if environment == env or environment.startswith(f"{env}-"): + selected_env = env + break + + cert_path = CLIENT_CERT_PATH / f"{selected_env}.crt" + key_path = CLIENT_CERT_PATH / f"{selected_env}.key" if not cert_path.exists() or not key_path.exists(): raise FileNotFoundError( From 806681089e06436067f573b8480917756867f847 Mon Sep 17 00:00:00 2001 From: "Axel Garcia K." Date: Wed, 19 Nov 2025 17:26:13 +0000 Subject: [PATCH 2/2] NRL-1824 Fix failure --- tests/features/environment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/features/environment.py b/tests/features/environment.py index 76e5348e9..cd2926281 100644 --- a/tests/features/environment.py +++ b/tests/features/environment.py @@ -19,7 +19,7 @@ def before_all(context: Context): context.account_name = context.config.userdata.get("account_name") context.use_shared_resources = context.config.userdata.get("use_shared_resources") context.host = context.config.userdata.get( - "host", default=f"https://{context.env}.api.record-locator.dev.national.nhs.uk/" + "host", f"https://{context.env}.api.record-locator.dev.national.nhs.uk/" ) context.stack_name = (