We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution, this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.
You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again.
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
An essential part of getting your change through is to make sure all existing tests pass.
- Maven to build and run tests.
- A GCP project to test on with the compute engine API enabled with all relevant permissions enabled, especially billing. Running integration tests will also incur billing.
- For development, IntelliJ is recommended.
- For Windows Images/VM's, have Java and OpenSSH pre-installed. We have suggested startup-scripts for installing both if you do not want to pre-install, but pre-installing is advised.
- Write/change tests as necessary based on the code changes you made.
- Make sure you are at the directory where pom.xml is located.
- Run the following:
mvn test
Integration tests actually provision instances in a GCP project, run pipeline, take snapshot etc. Therefore, they are disabled in the CI and expected to be executed by contributors in their laptop itself.
Reasons for disabling integration test in CI,
- getting provisioning GCP infra is not possible
- even if we did get a GCP infra setup in the CI, it is risky to expose that, as someone can abuse the CI.
By default, integration tests are skipped from the maven goals, need to enable using the skipITs
property.
Steps to execute integration test
-
Prepare VM images
(ideally we should automate this see idea here)
The jenkins agent images need to have java installed. We have a packer script to create the image and upload to your configured GCP project. The scripts are located in testimages/linux Navigate to the directory and execute,bash setup-gce-image.sh
If you want to execute the integration tests for
non-standard-java
location, then create non-standard-java image as,bash setup-gce-image.sh non-standard-java
If you want to delete the images or recreate them, use the arguments
--recreate
or--delete
. -
Create a service account with relevant access - See Refer to IAM Credentials
-
Export these mandatory environment variable
export GOOGLE_PROJECT_ID=your-project-id export GOOGLE_CREDENTIALS=/path/to/sa-key.json export GOOGLE_REGION=us-central1 export GOOGLE_ZONE=us-central1-a export GOOGLE_SA_NAME=jenkins-agent-sa
-
Run the integration tests as,
- Run all the tests
mvn verify -DskipITs=false -Djenkins.test.timeout=1200
- Run a specific test class
mvn clean test -Dtest=ComputeEngineCloudRestartPreemptedIT
- Run a specific test method
mvn clean test -Dtest=ComputeEngineCloudRestartPreemptedIT#testIfNodeWasPreempted
You can also debug the tests with surefire by passing
-Dmaven.surefire.debug=true
and in your IDE connect to remote debug port8000
. - Run all the tests
- By default, the integration tests only use linux based agents for testing. If you make a
windows-related change, or otherwise want to test that a change still works for windows agents,
run the tests with the flag
-Dit.windows=true
like this:mvn verify -Dit.windows=true
- You need to prepare the windows image before running the tests.
- More information on building your baseline windows image can be found here
and an example powershell script for setup can be found here. - In addition to the environment variables mentioned in the previous section, also export these variables too,
export GOOGLE_BOOT_DISK_PROJECT_ID=your-project-id # will be the same as your project id expot GOOGLE_BOOT_DISK_IMAGE_NAME=windows-image-name # will be the name of the image you created using packer in Google cloud console export GOOGLE_JENKINS_PASSWORD=password # will be the password you set when creating the image with packer, used for password based ssh authentication.
- More information on building your baseline windows image can be found here