Skip to content

Commit

Permalink
add base for skr-upgrade-test (#12142)
Browse files Browse the repository at this point in the history
  • Loading branch information
voigt authored Oct 20, 2021
1 parent 426d89c commit 93762dd
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ installation/versions-overrides.env

# Changelog temporary directory
.changelog/

# direnv files
.envrc
5 changes: 5 additions & 0 deletions tests/fast-integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ ci-skr-nightly:
npm install
npm run nightly-skr

.PHONY: ci-skr-kyma-to-kyma2-upgrade
ci-skr-kyma-to-kyma2-upgrade:
npm install
npm run test-skr-kyma-to-kyma2-upgrade

.PHONY: ci-skr-svcat-migration
ci-skr-svcat-migration:
npm install
Expand Down
1 change: 1 addition & 0 deletions tests/fast-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test-compass": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./compass-test/",
"test-skr": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-test/",
"nightly-skr": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-nightly/",
"test-skr-kyma-to-kyma2-upgrade": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-kyma-to-kyma2-upgrade/index.js",
"test-skr-svcat-migration": "mocha --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./skr-svcat-migration-test/",
"test-monitoring": "mocha --timeout 150000 --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./monitoring-test/",
"test-eventing": "DEBUG=true mocha --timeout 150000 --inline-diffs --check-leaks --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json ./eventing-test/",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
KEB_HOST=
KEB_CLIENT_ID=
KEB_CLIENT_SECRET=
KEB_GLOBALACCOUNT_ID=
KEB_SUBACCOUNT_ID=
KEB_USER_ID=
KEB_PLAN_ID=
GARDENER_KUBECONFIG=
AL_SERVICE_KEY=
250 changes: 250 additions & 0 deletions tests/fast-integration/skr-kyma-to-kyma2-upgrade/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
const uuid = require("uuid");
const fs = require('fs');
const {
DirectorConfig,
DirectorClient,
addScenarioInCompass,
assignRuntimeToScenario,
unregisterKymaFromCompass,
} = require("../compass");
const {
KEBConfig,
KEBClient,
provisionSKR,
deprovisionSKR,
} = require("../kyma-environment-broker");
const { GardenerConfig, GardenerClient } = require("../gardener");
const {
debug,
genRandom,
initializeK8sClient,
printRestartReport,
getContainerRestartsForAllNamespaces,
getEnvOrThrow,
switchDebug,
} = require("../utils");
const {
ensureCommerceMockWithCompassTestFixture,
checkInClusterEventDelivery,
checkFunctionResponse,
sendEventAndCheckResponse,
} = require("../test/fixtures/commerce-mock");
const {
checkServiceInstanceExistence,
ensureHelmBrokerTestFixture,
} = require("../upgrade-test/fixtures/helm-broker");
const {
cleanMockTestFixture,
} = require("../test/fixtures/commerce-mock");
const {
kcpLogin,
kcpUpgrade
} = require("./upgrade-helpers");
const {
saveKubeconfig,
} = require("../skr-svcat-migration-test/test-helpers");

describe("SKR-Upgrade-test", function () {
switchDebug(on = true)
let keb = new KEBClient(KEBConfig.fromEnv());
const gardener = new GardenerClient(GardenerConfig.fromEnv());

const suffix = genRandom(4);
const appName = `app-${suffix}`;
const runtimeName = `kyma-${suffix}`;
const scenarioName = `test-${suffix}`;
const runtimeID = uuid.v4();
const subAccountID = uuid.v4();

keb.subaccountID = subAccountID;

debug(
`PlanID ${getEnvOrThrow("KEB_PLAN_ID")}`,
`SubAccountID ${subAccountID}`,
`RuntimeID ${runtimeID}`,
`Scenario ${scenarioName}`,
`Runtime ${runtimeName}`,
`Application ${appName}`
);

// debug(
// `KEB_HOST: ${getEnvOrThrow("KEB_HOST")}`,
// `KEB_CLIENT_ID: ${getEnvOrThrow("KEB_CLIENT_ID")}`,
// `KEB_CLIENT_SECRET: ${getEnvOrThrow("KEB_CLIENT_SECRET")}`,
// `KEB_GLOBALACCOUNT_ID: ${getEnvOrThrow("KEB_GLOBALACCOUNT_ID")}`,
// `KEB_SUBACCOUNT_ID: ${getEnvOrThrow("KEB_SUBACCOUNT_ID")}`,
// `KEB_USER_ID: ${getEnvOrThrow("KEB_USER_ID")}`,
// `KEB_PLAN_ID: ${getEnvOrThrow("KEB_PLAN_ID")}`
// );

// debug(
// `COMPASS_HOST: ${getEnvOrThrow("COMPASS_HOST")}`,
// `COMPASS_CLIENT_ID: ${getEnvOrThrow("COMPASS_CLIENT_ID")}`,
// `COMPASS_CLIENT_SECRET: ${getEnvOrThrow("COMPASS_CLIENT_SECRET")}`,
// `COMPASS_TENANT: ${getEnvOrThrow("COMPASS_TENANT")}`,
// )

this.timeout(60 * 60 * 1000 * 3); // 3h
this.slow(5000);

let skr;

// SKR Provisioning

it(`Provision SKR with ID ${runtimeID}`, async function () {
skr = await provisionSKR(keb, gardener, runtimeID, runtimeName, null, null, null);
});

it(`Should save kubeconfig for the SKR to ~/.kube/config`, async function() {
saveKubeconfig(skr.shoot.kubeconfig);
});

it(`Should initialize K8s client`, async function() {
await initializeK8sClient({kubeconfig: skr.shoot.kubeconfig});
});

// Upgrade Test Praparation
const director = new DirectorClient(DirectorConfig.fromEnv());
const withCentralAppConnectivity = (process.env.WITH_CENTRAL_APP_CONNECTIVITY === "true");

const testNS = "test";

it("Assign SKR to scenario", async function () {
await addScenarioInCompass(director, scenarioName);
await assignRuntimeToScenario(director, skr.shoot.compassID, scenarioName);
});

it("CommerceMock test fixture should be ready", async function () {
await ensureCommerceMockWithCompassTestFixture(director, appName, scenarioName, "mocks", testNS, withCentralAppConnectivity);
});

it("Helm Broker test fixture should be ready", async function () {
await ensureHelmBrokerTestFixture(testNS).catch((err) => {
console.dir(err); // first error is logged
return ensureHelmBrokerTestFixture(testNS);
});
});

// Perform Tests before Upgrade

it("Listing all pods in cluster", async function () {
await getContainerRestartsForAllNamespaces();
});

let initialRestarts

it("in-cluster event should be delivered", async function () {
initialRestarts = await checkInClusterEventDelivery(testNS);
});

it("function should be reachable through secured API Rule", async function () {
await checkFunctionResponse(testNS);
});

it("order.created.v1 event should trigger the lastorder function", async function () {
await sendEventAndCheckResponse();
});

it("service instance provisioned by helm broker should be reachable", async function () {
await checkServiceInstanceExistence(testNS);
});

it("Should print report of restarted containers, skipped if no crashes happened", async function () {
const afterTestRestarts = await getContainerRestartsForAllNamespaces();
printRestartReport(initialRestarts, afterTestRestarts);
});

// Perform Upgrade

// Credentials for KCP ODIC Login
const KCP_TECH_USER_LOGIN = getEnvOrThrow("KCP_TECH_USER_LOGIN")
const KCP_TECH_USER_PASSWORD = getEnvOrThrow("KCP_TECH_USER_PASSWORD")
const KCP_OIDC_CLIENT_ID = getEnvOrThrow("KCP_OIDC_CLIENT_ID")
const KCP_OIDC_CLIENT_SECRET = getEnvOrThrow("KCP_OIDC_CLIENT_SECRET")
const KCP_KEB_API_URL = "https://kyma-env-broker.cp.dev.kyma.cloud.sap"
const KCP_OIDC_ISSUER_URL = "https://kymatest.accounts400.ondemand.com"
const kcpconfigPath = "dev.yaml"
const kymaUpgradeVersion = getEnvOrThrow("KYMA_UPGRADE_VERSION")

it(`Perform kcp login`, async function () {

// debug(
// `KCP_TECH_USER_LOGIN: ${KCP_TECH_USER_LOGIN}\n`,
// `KCP_TECH_USER_PASSWORD: ${KCP_TECH_USER_PASSWORD}\n`,
// `KCP_OIDC_CLIENT_ID: ${KCP_OIDC_CLIENT_ID}\n`,
// `KCP_OIDC_CLIENT_SECRET: ${KCP_OIDC_CLIENT_SECRET}\n`,
// `KCP_KEB_API_URL: ${KCP_KEB_API_URL}\n`,
// `KCP_OIDC_ISSUER_URL: ${KCP_OIDC_ISSUER_URL}\n`
// )

let stream = fs.createWriteStream(kcpconfigPath);
stream.once('open', function(fd) {
stream.write(`gardener-namespace: garden-kyma-dev\n`);
stream.write(`oidc-client-id: ${KCP_OIDC_CLIENT_ID}\n`);
stream.write(`oidc-client-secret: ${KCP_OIDC_CLIENT_SECRET}\n`);
stream.write(`keb-api-url: ${KCP_KEB_API_URL}\n`);
stream.write(`oidc-issuer-url: ${KCP_OIDC_ISSUER_URL}\n`);;
stream.end();
});

let loginOutput = await kcpLogin(kcpconfigPath, KCP_TECH_USER_LOGIN, KCP_TECH_USER_PASSWORD);
// debug(loginOutput)
});

it(`Perform Upgrade`, async function () {
let kcpUpgradeStatus = await kcpUpgrade(kcpconfigPath, subAccountID, runtimeID, kymaUpgradeVersion);
debug("Upgrade Done!")
});

// Perform Tests after Upgrade

it("Listing all pods in cluster", async function () {
await getContainerRestartsForAllNamespaces();
});

initialRestarts = undefined

it("in-cluster event should be delivered", async function () {
initialRestarts = await checkInClusterEventDelivery(testNS);
});

it("function should be reachable through secured API Rule", async function () {
await checkFunctionResponse(testNS);
});

it("order.created.v1 event should trigger the lastorder function", async function () {
await sendEventAndCheckResponse();
});

it("service instance provisioned by helm broker should be reachable", async function () {
await checkServiceInstanceExistence(testNS);
});

it("Should print report of restarted containers, skipped if no crashes happened", async function () {
const afterTestRestarts = await getContainerRestartsForAllNamespaces();
printRestartReport(initialRestarts, afterTestRestarts);
});


// Cleanup
const skip_cleanup = getEnvOrThrow("SKIP_CLEANUP")

if (skip_cleanup === "FALSE") {
it("Unregister Kyma resources from Compass", async function() {
await unregisterKymaFromCompass(director, scenarioName);
});

it("Test fixtures should be deleted", async function () {
await cleanMockTestFixture("mocks", testNS, true)
});

it("Deprovision SKR", async function () {
await deprovisionSKR(keb, runtimeID);
});

it("Unregister SKR resources from Compass", async function () {
await unregisterKymaFromCompass(director, scenarioName);
});
}

});
20 changes: 20 additions & 0 deletions tests/fast-integration/skr-kyma-to-kyma2-upgrade/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SKR test

This test covers SKR (SAP Kyma Runtime).

## Usage

Prepare the `.env` file based on the `.env.template`. Run the following command to set up the environment variables in your system:

```bash
export $(xargs < .env)
```

Run the test scenario:

```bash
npm run test-skr
```

## Environment variables
`AL_SERVICE_KEY` must be a cloud foundry service key with the info about `UAA (User Account and Authentication)`. Learn more about [Managing Service Keys in Cloud Foundry](https://docs.cloudfoundry.org/devguide/services/service-keys.html).
Loading

0 comments on commit 93762dd

Please sign in to comment.