2017-04-28 08:02:37 -07:00
# Rook Test Framework
2017-06-26 21:52:06 -07:00
2018-06-09 15:40:08 +02:00
The Rook Test Framework is used to run end to end and integration tests on Rook. The framework depends on a running instance of Kubernetes.
The framework also provides scripts for starting Kubernetes using `kubeadm` or `minikube` so users can
quickly spin up a Kubernetes cluster.The Test framework is designed to install Rook, run tests, and uninstall Rook.
2017-06-26 21:52:06 -07:00
2017-05-03 16:43:33 -07:00
## Requirements
2019-10-25 17:40:33 +02:00
1. Docker version => 1.2 && < 17.0 (for other alternatives, see below)
2020-08-05 05:28:23 +00:00
1. Ubuntu 18 (the framework has only been tested on this version)
1. kernel >= 4.15
2020-04-17 21:47:50 +09:00
1. Kubernetes with kubectl configured
1. Rook
2017-06-26 21:52:06 -07:00
## Instructions
2017-05-03 16:43:33 -07:00
2018-02-17 19:36:10 -08:00
## Setup
2017-07-20 23:30:32 -07:00
2019-10-25 17:40:33 +02:00
### Container Runtime
By default, the test suite tries to use the `docker` command line tool. To use
an alternative container runtime tool, set the `DOCKERCMD` environment variable
to your command line tool of choice.
2018-02-17 19:36:10 -08:00
### Install Kubernetes
2018-06-09 15:40:08 +02:00
You can choose any Kubernetes flavor of your choice. The test framework only depends on kubectl being configured.
2017-07-20 23:30:32 -07:00
The framework also provides scripts to install Kubernetes. There are two scripts to start the cluster:
2018-02-17 19:36:10 -08:00
1. **Kubeadm** (recommended for Ubuntu): run [kubeadm.sh ](/tests/scripts/kubeadm.sh ) to setup a single-node K8s cluster using kubeadm
2020-10-15 20:11:31 +00:00
1. **Minikube** (recommended for non-Ubuntu): Run [minikube.sh ](/tests/scripts/minikube.sh ) to setup a single-node Minikube Kubernetes.
2017-08-09 17:34:10 -07:00
2020-10-15 20:11:31 +00:00
Minikube scripts only support "docker" and "none" as vm-driver.
#### Minikube (recommended for non-Ubuntu)
2018-02-17 19:36:10 -08:00
Starting the cluster on Minikube is as simple as running:
```console
tests/scripts/minikube.sh up
2017-08-09 17:34:10 -07:00
```
2018-02-17 19:36:10 -08:00
To copy Rook images generated from your local build into the Minikube VM, run the following commands after `minikube.sh up` succeeded:
2020-09-02 00:03:48 +09:00
```console
2017-09-06 23:36:13 -07:00
tests/scripts/minikube.sh update
tests/scripts/minikube.sh helm
2017-09-28 12:05:20 -07:00
```
2017-09-06 23:36:13 -07:00
2018-02-17 19:36:10 -08:00
Stopping the cluster and destroying the Minikube VM can be done with:
```console
2018-07-26 10:52:19 -06:00
tests/scripts/minikube.sh clean
2018-02-17 19:36:10 -08:00
```
#### Kubeadm (recommended for Ubuntu)
Starting the cluster using `kubeadm` is as simple as running:
```console
tests/scripts/kubeadm.sh up
```
`kubeadm.sh` starts Kubernetes on the host, so all the images generated by your local build should be available to the cluster without any additional commands.
2020-09-02 00:03:48 +09:00
You can change the Kubernetes version (default is v1.15.12) with `KUBE_VERSION` environment variable. Here is the example of using Kubernetes v1.19.0.
```console
export KUBE_VERSION=v1.19.0
tests/scripts/kubeadm.sh up
```
2018-02-17 19:36:10 -08:00
2020-05-05 23:14:07 +09:00
Please note that this script may downgrade the following deb packages.
- kubernetes-cni
- kubelet
- kubeadm
2018-02-17 19:36:10 -08:00
Stopping the cluster can be done with:
```console
tests/scripts/kubeadm.sh clean
```
#### Alternate Kubernetes Versions
These two scripts can install any version of Kubernetes you wish based on the `KUBE_VERSION` environment variable.
To use an alternate version, simply set this variable before running the relevant `up` command from above.
2018-12-19 23:42:01 -07:00
For example, if you wanted to use `v1.12.5` , you would run `export KUBE_VERSION=v1.12.5` first before running `up` .
2017-04-28 08:02:37 -07:00
2017-08-24 14:55:01 -07:00
### Install Helm
2018-08-22 16:14:59 +02:00
Use [helm.sh ](/tests/scripts/helm.sh ) to install Helm and set up Rook charts defined under `_output/charts` (generated by build):
2017-08-24 14:55:01 -07:00
2018-08-22 16:14:59 +02:00
- To install and set up Helm charts for Rook run `tests/scripts/helm.sh up` .
- To clean up `tests/scripts/helm.sh clean` .
**NOTE:** `*kubeadm.sh` , `minikube.sh` and `helm.sh` scripts depend on some artifacts under the `_output/` directory generated during build time,
2018-06-09 15:40:08 +02:00
these scripts should be run from project root. e.g., `tests/script/kubeadm.sh up` .
2017-04-28 08:02:37 -07:00
2018-08-22 16:14:59 +02:00
**NOTE** : If Helm is not available in your `PATH` , Helm will be downloaded to a temporary directory (`/tmp/rook-tests-scripts-helm` ) and used from that directory.
2017-09-19 01:10:50 -07:00
## Run Tests
From the project root do the following:
2020-04-13 16:10:39 -06:00
### 1. Build rook:
2018-06-09 15:40:08 +02:00
Run `make build`
2017-09-19 01:10:50 -07:00
2020-04-13 16:10:39 -06:00
### 2. Start Kubernetes
2018-06-09 15:40:08 +02:00
Using one of the following:
2017-06-26 21:52:06 -07:00
2018-06-09 15:40:08 +02:00
- Using Kubeadm
```
tests/scripts/kubeadm.sh up
2020-02-18 15:14:47 +09:00
export KUBECONFIG=~/admin.conf
2018-06-09 15:40:08 +02:00
tests/scripts/helm.sh up
```
- Using minikube
```
tests/scripts/minikube.sh up
tests/scripts/minikube.sh helm
tests/scripts/helm.sh up
```
2020-04-13 16:10:39 -06:00
### 3. Run integration tests:
2017-06-29 23:58:02 -07:00
2020-04-13 16:10:39 -06:00
Some settings are available to run the tests under different environments. The settings are all configured with environment variables.
See [environment.go ](/tests/framework/installer/environment.go ) for the available environment variables.
2020-09-02 00:03:48 +09:00
At least you should set the following variables.
```console
export TEST_HELM_PATH=/tmp/rook-tests-scripts-helm/linux-amd64/helm
export TEST_BASE_DIR=WORKING_DIR
export TEST_SCRATCH_DEVICE=<block device> # for example, TEST_SCRATCH_DEVICE=/dev/sdb
```
2020-09-02 00:38:24 +09:00
Please note that the integration test erases the contents of TEST_SCRATCH_DEVICE.
2020-04-13 16:10:39 -06:00
To run all integration tests:
2020-09-02 00:38:24 +09:00
```console
2021-01-08 10:45:48 +00:00
go test -v -timeout 7200s github.com/rook/rook/tests/integration
2017-05-17 23:23:05 -07:00
```
2020-09-02 00:38:24 +09:00
2020-10-09 16:58:25 +00:00
In addition, you can choose to test only one storage provider. For example, you can run Ceph tests as follows.
2020-09-02 00:03:48 +09:00
```console
export STORAGE_PROVIDER_TESTS=ceph
2021-01-08 10:45:48 +00:00
go test -v -timeout 7200s github.com/rook/rook/tests/integration
2020-09-02 00:03:48 +09:00
```
2017-05-17 23:23:05 -07:00
2020-04-13 16:10:39 -06:00
To run a specific suite (uses regex):
2020-09-02 00:38:24 +09:00
```console
2020-10-09 16:58:25 +00:00
go test -v -timeout 1800s -run CephSmokeSuite github.com/rook/rook/tests/integration
2017-05-17 23:23:05 -07:00
```
2017-06-29 23:58:02 -07:00
2020-04-13 16:10:39 -06:00
To run specific tests inside a suite:
2020-09-02 00:38:24 +09:00
```console
2020-11-27 22:35:24 +09:00
go test -v -timeout 1800s -run CephSmokeSuite github.com/rook/rook/tests/integration -testify.m TestARookClusterInstallation_SmokeTest
2017-06-29 23:58:02 -07:00
```
2020-08-31 12:33:57 +05:30
### To run tests on OpenShift environment
- Setup OpenShift environment and export KUBECONFIG before executing the tests.
- Make sure `oc` executable file is in the PATH.
- Only `CephSmokeSuite` is currently supported on OpenShift.
- Set few environment variables:
```
export TEST_ENV_NAME=openshift
export TEST_STORAGE_CLASS=gp2
export TEST_BASE_DIR=/tmp
export RETRY_MAX=40
```
To run a `CephSmokeSuite` (uses regex):
```console
$ go test -v -timeout 1800s -run CephSmokeSuite github.com/rook/rook/tests/integration
```