Skip to content

Instantly share code, notes, and snippets.

@mrWinston
Last active December 5, 2022 15:21
Show Gist options
  • Save mrWinston/26b876eb5df7dff3f8f7c678f8b86003 to your computer and use it in GitHub Desktop.
Save mrWinston/26b876eb5df7dff3f8f7c678f8b86003 to your computer and use it in GitHub Desktop.
Run osde2e tests locally

How to run the osde2e tests locally

This short guide shows you how to setup the e2e tests on your local machine. We won't go into detail on how all of the e2e stuff works, as this is covered in great detail in the osde2e documentation itelf. Instead, i'll just focus on the steps I took to get them running locally, without too many tangents.

Prerequisites

  1. Fork and clone the osde2e test repo: gh.com/openshift/osde2e
  2. Make sure you have an osd cluster ready
  3. golang version 1.16+

Test steps

We will need to create a couple of helper files to get the tests to run.

Step 1: Identifying the test to run

Find the Name of the test you want to run. I did this by looking at the go file associated with the specific e2e test. For example, looking at the osd-metrics-operator.go file, you can find the test name right at the top:

...
	"github.com/openshift/osde2e/pkg/common/alert"
	"github.com/openshift/osde2e/pkg/common/helper"
)

var (
	osdMetricsExporterTestPrefix = "[Suite: operators] [OSD] OSD Metrics Exporter" <<<<<<
	osdMetricsExporterBasicTest  = osdMetricsExporterTestPrefix + " Basic Test"
)

func init() {
...

In this case, the test name is [Suite: operators] [OSD] OSD Metrics Exporter.

Step 2: Create the e2e config file for this test

We will set up a new e2e test config file to specify that only the test identified earlier should be run. The configuration file needs to be created in the config subfolder of the osde2e test repo ( but don't commit or push the config file ). Run the following to create the file and name it localconfig.yaml

cd $OSDE2E_HOME/config

cat << EOF > ./localconfig.yaml
tests:
  testsToRun:
  - '\[Suite: operators\] \[OSD\] OSD Metrics Exporter'

Replace the string under testsToRun with the Name of the test you've identified earlier.

You need to Escape any [] in the Test name with backslashes \!

Create a script to setup the test environment

We will be using the following script to re-build and run the osde2e test binary:

#!/bin/bash

if [ -z "$CLUSTER_ID" ]; then
  echo -e "\$CLUSTER_ID needs to be set"
  echo -e "exiting..."
  exit 1
fi

echo -e "Running tests against $CLUSTER_ID"

export OSD_ENV="stage"
export CLOUD_PROVIDER_ID="aws"
export CLOUD_PROVIDER_REGION="us-east-1"
export DESTROY_CLUSTER="false"
export MUST_GATHER="false"
export HIBERNATE_AFTER_USE="false"

OCM_TOKEN="YOUR_TOKEN" # insert your OCM token here
export OCM_TOKEN
export CLUSTER_ID

make build

./out/osde2e test --configs "localconfig"

Double check the variables that are defined in the script. Especially make sure that you either set the OCM_TOKEN in the script itself, or remove it from the script and export it separately before running the script. Save the file as testLocal.sh in the root of the git repo.

Run the script

When done with the steps, you can go ahead and run the script. Make sure that you have exported the ID of the cluster you want to run the e2e tests in:

chmod +x ./testlocal.sh
export CLUSTER_ID=<internal-cluster-id>
./testlocal.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment