Commit 0b323c1b authored by Nikos Psaromanolakis's avatar Nikos Psaromanolakis
Browse files

update README.md...Related to #6, #7, #8, #9, #10

parent 94ea13e6
Loading
Loading
Loading
Loading
+83 −6
Changes for README.md: 83 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -4,27 +4,100 @@ Integration testing suite for the HypO TMF API ecosystem using **Karate DSL**. T

## 🚀 Overview
This repository manages end-to-end (E2E) testing for TMF-compliant services. It includes logic for:
* **Smoke and independent**: Multiple Smoke and independent tests (feature files).  
* **Asynchronous Polling**: Tracking resource states from `INITIAL` to `COMPLETED`.
* **Smoke and independent tests**: Multiple smoke and independent tests (feature files).
* **Orchestrated E2E workflows**: Full lifecycle tests per cluster type (Private, Public, OCM, Portal) that create, poll, update, and terminate resources.
* **Asynchronous Polling**: Tracking resource states from `INITIAL`/`ACTIVE` to `TERMINATED`/`COMPLETED`.
* **Deep Extraction**: Parsing nested JSON strings.
* **Automated Cleanup**: Ensuring environment stability by deleting orphaned resources on failure.
* **Automated Cleanup**: Ensuring environment stability by deleting orphaned resources on failure, guaranteed to run even when an orchestrator fails mid-run.
* **Master Nightly Orchestration**: Single entry points that run all orchestrators sequentially and performs one consolidated cleanup pass at the end.

## 🛠 Prerequisites
* **Java 11** or higher
* **Maven 3.6+**
* The following environment variables must be set (validated at startup by `karate-config.js`, which fails fast if any are missing):
  * `KEYCLOAK_USERNAME`, `KEYCLOAK_PASSWORD`, `KEYCLOAK_SECRET`
  * `ZITI_USERNAME`, `ZITI_PASSWORD`
  * `REGISTRY_IMAGE_USERNAME`, `REGISTRY_IMAGE_PASSWORD`

## 📁 Project Structure
* `src/test/resources/hypo/`: Contains Karate `.feature` files and JUnit runners.
* `src/test/resources/env/`: Contains env. json files needed for setting up the proper enviroment (dev, staging, prod).
  * `hypo/orchestrators/`: Orchestrator feature files (Private, Public, OCM, Portal, master nightly, and shared init/setup helpers). Kept separate from the reusable API-level feature files (`organization.feature`, `fabric.feature`, `peering.feature`, `registry.feature`, `party.feature`, `service.feature`, `deleteAll.feature`, `cleanUp.feature`, `auth.feature`, `telemetry.feature`), which remain at the `hypo/` root since they're shared across orchestrators.
* `src/test/resources/env/`: Contains env. json files needed for setting up the proper environment (dev, staging, prod).
* `src/test/resources/payloads/`: Directory for JSON request templates.
* `pom.xml`: Maven configuration and dependency management.
* `.gitlab-ci.yml`:  Basic CI/CD for intergation.tests repo for validating and testing the code.
* `.gitlab-ci.yml`: Basic CI/CD for integration.tests repo for validating and testing the code.


## 🧩 Orchestrators

Each orchestrator runs a full E2E lifecycle for a given cluster type:

| Orchestrator | Purpose | Cluster type |
|---|---|---|
| `orchestratorPrivate.feature` | Private K8s cluster E2E workflow | `private-prek8s` |
| `orchestratorPublic.feature` | Public K8s cluster E2E workflow | `public-prek8s` |
| `orchestratorOCM.feature` | OCM cluster E2E workflow | `ocm-prek8s` |
| `orchestratorPortal.feature` | Portal / Selenium UI workflow | n/a |
| `orchestratorMasterNightly.feature` | Runs all of the above sequentially, once, with guaranteed cleanup | n/a |

Each individual orchestrator (Private/Public/OCM) follows the same general shape:
1. Authenticate and fetch the acting individual.
2. Run shared setup (org, peering, registry secrets, service specs) and fabric controller creation/polling — unless skipped (see **Skip Flags** below).
3. Create a K8s resource service order, poll until active.
4. Create an end-user service order on top of it, poll until active.
5. Validate service/resource inventory and telemetry (Grafana dashboards, Prometheus metrics — Public and Private only; OCM checks logs only).
6. Update the service (Helm package config / cluster metadata) and re-poll.
7. Terminate the end-user service, then the resource service, polling each down to `TERMINATED`.
8. Delete the two service orders created during the run.

## 🧹 Cleanup System

Cleanup logic lives in `cleanUp.feature` and `deleteAll.feature`, and is designed to be reusable both standalone and from any orchestrator.

* **`deleteAll.feature`**: Contains the low-level, single-resource delete scenarios (`@deleteOrganizationbyId`, `@deletePeeringbyId`, `@deleteFabricNetwork`, `@deleteRegistryImagebyId`, `@deleteRegistryPackagebyId`, `@deleteServicebyId`, `@deleteServiceOrder`, etc.). Each accepts the relevant id as a parameter and tolerates `404` (already deleted) as a pass, so cleanup is idempotent and safe to re-run.
* **`cleanUp.feature`**: Contains the higher-level workflows:
  * `@cleanupTerminate` — terminates any services currently `ACTIVE` or `FEASIBILITY_CHECKED` (both CFS and OSL-named services) before deletion is attempted, since a service generally can't be deleted while still active.
  * `@cleanupAll` — loops over arrays of ids (organizations, peerings, network controllers, registry image/package secrets, services, orders) and deletes each one via `karate.forEach`, calling the matching `deleteAll.feature` scenario per item with a short sleep between calls.
  * `@clean-up-workflow` — the full, self-contained cleanup entry point: authenticates, fetches the current state of every resource type (`getOrganizations`, `getControllers`, `getPeerings`, `getRegistries`, `getAllServices`, `getAllCfsandOslServices`, `getAllServiceOrders`), then calls `@cleanupTerminate` followed by `@cleanupAll` with the resulting id arrays.

### How cleanup is triggered
* **Individual orchestrators** (Private/Public/OCM/Portal) each configure `afterScenario` in their own `Background` to call `afterScenario.js`, so running any one of them standalone always leaves the environment clean, pass or fail.
* **The master nightly orchestrator** does **not** rely on Karate's `afterScenario` hook for its own cleanup. Because `configure afterScenario` is shared, mutable state across a call chain, a sub-orchestrator's own `Background` will silently overwrite whatever the master configured — so relying on the hook at the master level is unreliable once sub-orchestrators are involved. Instead, the master:
  1. Calls each sub-orchestrator with `{ skipCleanup: true }`, so their individual `afterScenario` hooks defer instead of running.
  2. Wraps the whole sequence in a JS `try / catch / finally`, calling `cleanUp.feature@clean-up-workflow` unconditionally inside `finally`.
  3. Re-throws the original error (if any) after cleanup completes, so the test still correctly reports as failed — cleanup happening doesn't hide a real failure.

  This guarantees **exactly one cleanup pass**, at the very end of the run, whether every orchestrator passed or one of them failed partway through.

## 🚦 Skip Flags

Some orchestrator steps can be skipped by passing flags into the `call read(...)` config object. Each flag defaults to `false` (via `karate.get('flagName', false)`) when not explicitly passed, so standalone runs behave exactly as before.

| Flag | Effect when `true` |
|---|---|
| `skipCleanup` | Skips that orchestrator's own `afterScenario` cleanup (used when a master orchestrator will handle cleanup itself, once, at the end). |
| `skipInitSteps` | Skips org/peering/registry/fabric-controller setup steps, reusing values passed in instead (used when a prior orchestrator in the same run already did this setup). |
| `skipTerminateSteps` | Skips the end-of-run service termination steps. |

Example — calling Private normally, then Public/OCM reusing Private's setup and deferring cleanup to the master:
```karate
* call read('classpath:hypo/orchestrators/orchestratorPrivate.feature') { skipCleanup: true }
* call read('classpath:hypo/orchestrators/orchestratorPublic.feature') { skipCleanup: true, skipInitSteps: true }
* call read('classpath:hypo/orchestrators/orchestratorOCM.feature') { skipCleanup: true, skipInitSteps: true }
```

## 🏃 Running Tests
**For smoke tests run:**

**For smoke tests run (using private workflow as example):**
```bash
mvn test "-Dkarate.env=dev-etsi" "-Dkarate.options=--tags @smoke-e2e-workflow-private"
```

**For the full nightly run (all orchestrators + single consolidated cleanup):**
```bash
mvn test "-Dkarate.env=dev-etsi" "-Dkarate.options=--tags @nightly-workflow-with-clean-up"
```

**For independent tests run:**
- Run by File Path:
```bash
@@ -38,6 +111,10 @@ mvn test "-Dkarate.options=--tags @smoke-auth"
```bash
mvn test "-Dkarate.options=src/test/resources/hypo/auth.feature --name 'Get Hypo access token'"
```

> Tags are resolved across the whole classpath regardless of folder structure.
> If a feature file was recently edited and the change doesn't seem to take effect, run with `mvn clean test` instead of `mvn test` — this guarantees a fresh copy of every resource file is used rather than a possibly stale one from a previous build in `target/`.

### Execute All Tests
Not recommended!
```bash