Commit 90afe6e8 authored by Nikos Psaromanolakis's avatar Nikos Psaromanolakis
Browse files

added delete calls at the end of each workflow

parent e715f6b2
Loading
Loading
Loading
Loading
Loading
+17 −9
Changes for README.md: 17 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@ Each orchestrator runs a full E2E lifecycle for a given cluster type:

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).
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).
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.
@@ -56,16 +56,16 @@ Cleanup logic lives in `cleanUp.feature` and `deleteAll.feature`, and is designe

* **`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.
  * `@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:
* **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.
  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.

@@ -78,12 +78,14 @@ Some orchestrator steps can be skipped by passing flags into the `call read(...)
| `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. |
| `skipDeleteWorkflow` | Skips get and delete steps at the end of orcehstrator, in case you don't want to test get and delete methods. |

Example — calling Private normally, then Public/OCM reusing Private's setup and deferring cleanup to the master:
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 }
* call read('classpath:hypo/orchestrators/orchestratorPrivate.feature') { skipCleanup: true, skipInitSteps: true, skipDeleteWorkflow:true }
```

## 🏃 Running Tests
@@ -93,6 +95,12 @@ Example — calling Private normally, then Public/OCM reusing Private's setup an
mvn test "-Dkarate.env=dev-etsi" "-Dkarate.options=--tags @smoke-e2e-workflow-private"
```

**For smoke tests run (using private workflow as example) without clean-up at te end:**
```bash
mvn test "-Dkarate.env=dev-etsi" "-Dkarate.options=--tags @smoke-e2e-workflow-private" "-DskipCleanup=true"
```


**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"
@@ -123,7 +131,7 @@ mvn test "-Dkarate.options=src/test/resources/hypo/auth.feature --name 'Get Hypo
```

> 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/`.
> 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`  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!
+3 −4
Changes for src/test/resources/hypo/afterScenario.js: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
function() {
    karate.log('>>>> EXECUTION OF TESTS FINISHED <<<<');
    karate.log('>>>>>>>> STARTING TO EXECUTE CLEAN UP <<<<<<<<');
    karate.log('>>>>>>>> STARTING TO EXECUTE CLEAN UP (AFTER SCENARIO CASE) <<<<<<<<');

    var skipCleanup = karate.get('skipCleanup', false);
    if (skipCleanup) {
        karate.log('afterScenario: skipCleanup=true, skipping cleanup (handled by master orchestrator)');
        karate.log('afterScenario: skipCleanup=true, skipping cleanup (handled (probably) by master orchestrator)');
        return;
    }

    
    karate.call('classpath:hypo/cleanUp.feature@clean-up-workflow');

    karate.log('>>>> CLEAN UP FINISHED!!! <<<<');
    karate.log('>>>> CLEAN UP (AFTER SCENARIO CASE) FINISHED!!! <<<<');



−1
Changes for src/test/resources/hypo/auth.feature: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -22,4 +22,3 @@ Scenario: Get Hypo access token
  And match response.expires_in == '#number'

  * def accessToken = response.access_token
  * print infra
+2 −2
Changes for src/test/resources/hypo/cleanUp.feature: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -160,8 +160,8 @@ Scenario: Terminate active CFS and OSL services before cleanup

  }
  """
  * print 'CFS :', cfsActiveServiceIds
  * print 'OSL:', oslActiveServiceIds
  * if (cfsActiveServiceIds && cfsActiveServiceIds.length > 0) karate.log('CFS:', cfsActiveServiceIds)
  * if (oslActiveServiceIds && oslActiveServiceIds.length > 0) karate.log('OSL:', oslActiveServiceIds)


  * karate.log('--- STEP TERMINATE: TERMINATE ACTIVE CFS SERVICES ---')
+1
Changes for src/test/resources/hypo/deleteAll.feature: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ Scenario: Delete Registry Package
  Then match [200, 204, 404] contains responseStatus



@deleteServicebyId
Scenario: Delete Service by Id
  Given url baseUrl
Loading