Skip to content

SREP-1164 : Update README file for running E2E Tests for CAD #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ To do this, following steps are recommended

ocm get /api/clusters_mgmt/v1/clusters/(cluster-id)/credentials | jq -r .kubeconfig > /(path-to)/kubeconfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this PR, but the sentence above:

. Deploy your new version of operator in a test cluster

That doesn't seem to apply here.


5. Run test suite using
5. AWS Credentials
These are needed for interacting with the cluster. You can find them in the ~/.aws/credentials file.
export AWS_ACCESS_KEY_ID=<your AWS access key ID>
export AWS_SECRET_ACCESS_KEY=<your AWS secret access key>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this more generic to work on "target stage cluster"? The credentials in this file will not always match the cluster's AWS creds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another line to ensure cluster is created with a default profile and the credentials for the same profile are set in the environment variables in this step


6. Generate OCM Token
To authenticate with OCM, run the command below. It will return a token and also generate a configuration file.
Run: ocm token
Then export the token:
export OCM_TOKEN=$(ocm token)

7. Enable Debug Mode
This enables detailed logging during test execution:
export CAD_DEBUG=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this variable for if we're not running the cadctl afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is again required for local testing and can be removed if we are following the service account mode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAD_DEBUG? That variable doesn't even exist anymore, and it should have had no influence on e2e :)


8. OCM Configuration File Path
When you run ocm token, it creates a file at the default location ~/.config/ocm/ocm.json. Set the environment variable pointing to this file:
export CAD_OCM_FILE_PATH=~/.config/ocm/ocm.json

## ONLY FOR LOCAL TESTING, THIS CONFIGURATION HAS TO BE REVERTED BACK BEFORE COMMIT AND PUSHING TO THE REPOSITORY

Comment out #56,57 in configuration_anomaly_detection_tests.go and replace with the following code:

ocme2eCli, err = ocme2e.New(ctx, ocmToken, clientID, clientSecret, ocmEnv)
Expect(err).ShouldNot(HaveOccurred(), "Unable to setup E2E OCM Client")

ocmCli, err = ocm.New(cadOcmFilePath)
Expect(err).ShouldNot(HaveOccurred(), "Unable to setup ocm anomaly detection client")

Add below statements in #50,#53 respectively

ocmToken := os.Getenv("OCM_TOKEN")
Expect(ocmToken).NotTo(BeEmpty(), "OCM_TOKEN must be set")

## "!! PLEASE NOTE THAT SINCE OCM_TOKEN IS NOW DEPRECATED ABOVE LINES OF CODE HAVE TO BE REMOVED AND #56,57 HAVE TO BE UNCOMMENTED !!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure we don't need to modify the code to run this locally? That seems like a workaround ;) Ideally, running e2e tests with a target cluster should work programmatically. If you could provide a short script here, that would be very beneficial.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @typeid : The reason this workaround is being proposed from us is for OCM_CLIENT_ID and OCM_CLIENT_SECRET to work from a local machine a service account is required, if the service account is available we would not need to do this workaround and the test would work fine.

The script would not be required in that case, please let us know on how to proceed with this.

I can put a note in with a link to the SOP to create service account and enable it to be able to test the code in local.

Copy link
Member

@typeid typeid Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about attempting to load the existing ocm token, and falling back to clientid and clientsecret?
That way it would work for both envs, correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how do we do this change after building the e2e?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g.

import (
	ocmConfig "github.com/openshift-online/ocm-common/pkg/ocm/config"
	ocmConnBuilder "github.com/openshift-online/ocm-common/pkg/ocm/connection-builder"
)
...

		cfg, err := ocmConfig.Load()
		if err != nil {
			clientID := os.Getenv("OCM_CLIENT_ID")
			Expect(clusterID).NotTo(BeEmpty(), "OCM_CLIENT_ID must be set")

			clientSecret := os.Getenv("OCM_CLIENT_SECRET")
			Expect(clusterID).NotTo(BeEmpty(), "OCM_CLIENT_SECRET must be set")

			ocme2eCli, err = ocme2e.New(ctx, "", clientID, clientSecret, ocmEnv)
			Expect(err).ShouldNot(HaveOccurred(), "Unable to setup E2E OCM Client")
		} else {
			// Build connection based on local config
			connection, err := ocmConnBuilder.NewConnection().Config(cfg).AsAgent("cad-local-e2e-tests").Build()
			ocme2eCli = &ocme2e.Client{Connection: connection}
			Expect(err).ShouldNot(HaveOccurred(), "Unable to setup E2E OCM Client")
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @typeid, this has significantly reduced overhead, the README file is fairly simple now.

I made the code changes and carried out local testing and it ran fine.

Also in other news i was comparing the Pagerduty alerts that we received https://redhat.pagerduty.com/service-directory/P4BLYHK/activity to the runtimes of the E2E pipeline -> https://prow.ci.openshift.org/job-history/gs/test-platform-results/logs/periodic-ci-openshift-osde2e-main-nightly-4.19-rosa-classic-sts

It looks like they are matching, however i don't see any logs from our test cases niether passing nor failing, should be consider closing the task for the environment variables syncing with E2E?


9. Run test suite using

DISABLE_JUNIT_REPORT=true KUBECONFIG=/(path-to)/kubeconfig ./(path-to)/bin/ginkgo --tags=osde2e -v test/e2e