Skip to content

Commit

Permalink
Add an E2E test framework to test Velero across cloud platforms (vmwa…
Browse files Browse the repository at this point in the history
…re-tanzu#3060)

* Basic end-to-end tests, generate data/backup/remove/restore/verify
Uses distributed data generator

Signed-off-by: Dave Smith-Uchida <[email protected]>

* Moved backup/restore into velero_utils, started using a name for the restore

Signed-off-by: Dave Smith-Uchida <[email protected]>

* remove checked in binary and update test/e2e Makefile

Signed-off-by: Ashish Amarnath <[email protected]>

* Ran make update

Signed-off-by: Dave Smith-Uchida <[email protected]>

* Save

Signed-off-by: Ashish Amarnath <[email protected]>

* Ran make update

Signed-off-by: Dave Smith-Uchida <[email protected]>

* Basic end-to-end test, generate data/backup/remove/restore/verify
Uses distributed data generator

Signed-off-by: Dave Smith-Uchida <[email protected]>

* Changed tests/e2e Makefile to just use go get to install ginkgo in the GOPATH/bin
Updated to ginkgo 1.14.2
Put cobra back to v0.0.7

Signed-off-by: Dave Smith-Uchida <[email protected]>

* Added CLOUD_PLATFORM env variable to Makefile, updated README, removed ginkgo from .gitignore

Signed-off-by: Dave Smith-Uchida <[email protected]>

* choose velero CLI binary based on local env

Signed-off-by: Ashish Amarnath <[email protected]>

Co-authored-by: Ashish Amarnath <[email protected]>
  • Loading branch information
2 people authored and georgettica committed Dec 23, 2020
1 parent 1592c7a commit 3ac2fd5
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,7 @@ serve-docs: build-image-hugo
# Please read the documentation in the script for instructions on how to use it.
gen-docs:
@hack/release-tools/gen-docs.sh

.PHONY: test-e2e
test-e2e:
$(MAKE) -C test/e2e run
2 changes: 2 additions & 0 deletions changelogs/unreleased/3060-dsu-igeek
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Basic end-to-end tests, generate data/backup/remove/restore/verify
Uses distributed data generator
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ require (
github.com/gobwas/glob v0.2.3
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.1
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v0.0.0-20190610192547-a1bc61569a26
github.com/joho/godotenv v1.3.0
github.com/kubernetes-csi/external-snapshotter/v2 v2.2.0-rc1
github.com/onsi/ginkgo v1.13.0
github.com/onsi/gomega v1.10.1
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.5.1
github.com/robfig/cron v1.1.0
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.13.0 h1:M76yO2HkZASFjXL0HSoZJ1AYEmQxNJmY41Jx1zNUq1Y=
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M=
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand All @@ -522,6 +522,8 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.2 h1:aY/nuoWlKJud2J6U0E3NWsjlg+0GtwXxgEqthRdzlcs=
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down Expand Up @@ -579,7 +581,6 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v0.0.0-20180427012116-c95755e4bcd7/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
Expand Down
61 changes: 61 additions & 0 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# If you update this file, please follow:
# https://suva.sh/posts/well-documented-makefiles/

# Use GOPROXY environment variable if set

.DEFAULT_GOAL:=help

ARCH ?= $(shell go env GOOS)-$(shell go env GOARCH)
platform_temp = $(subst -, ,$(ARCH))
GOOS = $(word 1, $(platform_temp))
GOARCH = $(word 2, $(platform_temp))

GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY

REPO_ROOT := $(shell git rev-parse --show-toplevel)

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

## --------------------------------------
## Binaries
## --------------------------------------

TOOLS_DIR := $(REPO_ROOT)/hack/tools
BIN_DIR := bin
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
GINKGO := $(GOPATH)/bin/ginkgo
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin
GINKGO_FOCUS ?=
CLOUD_PLATFORM ?= kind

.PHONY:ginkgo
ginkgo: # Make sure ginkgo is in $GOPATH/bin
go get github.com/onsi/ginkgo/ginkgo

.PHONY: run
run: ginkgo
$(GINKGO) -v -focus="$(GINKGO_FOCUS)" . -- -velerocli=../../_output/bin/$(GOOS)/$(GOARCH)/velero -cloudplatform=$(CLOUD_PLATFORM)

build: ginkgo
mkdir -p $(OUTPUT_DIR)
$(GINKGO) build .
46 changes: 46 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# End-to-end tests

Document for running Velero end-to-end test suite.

## Command line flags for E2E tests

Command line flags can be set after
```
velerocli - the velero CLI to use
kibishiins - the namespace to install kibishii in
cloudplatform - the cloud platform the tests will be run against (aws, vsphere, azure)
```

## Running tests locally

1. From Velero repository root

```
make test-e2e
```
1. From `test/e2e/` directory
```
make run
```
## Running tests based on cloud platforms
1. Running Velero E2E tests on KinD
```
CLOUD_PLATFORM=kind make test-e2e
```
1. Running Velero E2E tests on AWS
```
CLOUD_PLATFORM=aws make test-e2e
```
1. Running Velero E2E tests on Azure
```
CLOUD_PLATFORM=azure make test-e2e
```
24 changes: 24 additions & 0 deletions test/e2e/aws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package e2e

import (
"context"
"flag"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Testing Velero on an aws cluster", func() {
BeforeEach(func() {
flag.Parse()
ctx := context.TODO()
err := EnsureClusterExists(ctx)
Expect(err).NotTo(HaveOccurred())
})
Describe("", func() {
Context("Dummy test", func() {
It("is a dummy test", func() {
})
})
})
})
24 changes: 24 additions & 0 deletions test/e2e/azure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package e2e

import (
"context"
"flag"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Testing Velero on an azure cluster", func() {
BeforeEach(func() {
flag.Parse()
ctx := context.TODO()
err := EnsureClusterExists(ctx)
Expect(err).NotTo(HaveOccurred())
})
Describe("Dummy test", func() {
Context("Dummy test", func() {
It("is a dummy test", func() {
})
})
})
})
83 changes: 83 additions & 0 deletions test/e2e/backup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package e2e

import (
"flag"
"time"

"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"golang.org/x/net/context"

velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)

var (
backupName string
restoreName string
)

var _ = Describe("Backup Restore test using Kibishii to generate/verify data", func() {

BeforeEach(func() {
flag.Parse()
})
Describe("backing up and restoring namespace with data", func() {
Context("when the backup is successful", func() {
It("generates data, backups up the namespace, deletes the namespace, restores the namespace and verifies data", func() {
backupUUID, err := uuid.NewRandom()
Expect(err).NotTo(HaveOccurred())
backupName = "backup-" + backupUUID.String()
restoreName = "restore-" + backupUUID.String()
println("backupName = " + backupName)
println("creating namespace " + kibishiNamespace)
timeoutCTX, _ := context.WithTimeout(context.Background(), time.Minute)
err = CreateNamespace(timeoutCTX, kibishiNamespace)
Expect(err).NotTo(HaveOccurred())

println("installing kibishii in namespace " + kibishiNamespace)
timeoutCTX, _ = context.WithTimeout(context.Background(), 30*time.Minute)
err = InstallKibishii(timeoutCTX, kibishiNamespace, cloudPlatform)
Expect(err).NotTo(HaveOccurred())

println("running kibishii generate")
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute*60)

err = GenerateData(timeoutCTX, kibishiNamespace, 2, 10, 10, 1024, 1024, 0, 2)
Expect(err).NotTo(HaveOccurred())

println("executing backup")
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute*30)

err = BackupNamespace(timeoutCTX, veleroCLI, backupName, kibishiNamespace)
Expect(err).NotTo(HaveOccurred())
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute)
err = CheckBackupPhase(timeoutCTX, veleroCLI, backupName, velerov1.BackupPhaseCompleted)

Expect(err).NotTo(HaveOccurred())

println("removing namespace " + kibishiNamespace)
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute)
err = RemoveNamespace(timeoutCTX, kibishiNamespace)
Expect(err).NotTo(HaveOccurred())

println("restoring namespace")
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute*30)
err = RestoreNamespace(timeoutCTX, veleroCLI, restoreName, backupName)
Expect(err).NotTo(HaveOccurred())
println("Checking that namespace is present")
// TODO - check that namespace exists
println("running kibishii verify")
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute*60)

err = VerifyData(timeoutCTX, kibishiNamespace, 2, 10, 10, 1024, 1024, 0, 2)
Expect(err).NotTo(HaveOccurred())

println("removing namespace " + kibishiNamespace)
timeoutCTX, _ = context.WithTimeout(context.Background(), time.Minute)
err = RemoveNamespace(timeoutCTX, kibishiNamespace)
Expect(err).NotTo(HaveOccurred())
})
})
})
})
27 changes: 27 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package e2e

import (
"os/exec"

"golang.org/x/net/context"
)

func EnsureClusterExists(ctx context.Context) error {
return exec.CommandContext(ctx, "kubectl", "cluster-info").Run()
}

func CreateNamespace(ctx context.Context, namespace string) error {
// TODO - should we talk directly to the API server?
err := exec.CommandContext(ctx, "kubectl", "create", "namespace", namespace).Run()
return err
}

func RemoveNamespace(ctx context.Context, namespace string) error {
// TODO - should we talk directly to the API server?
err := exec.CommandContext(ctx, "kubectl", "delete", "namespace", namespace).Run()
return err
}

func NamespaceExists(ctx context.Context, namespace string) (bool, error) {
return false, nil
}
26 changes: 26 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package e2e

import (
"flag"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var (
veleroCLI string
kibishiNamespace string
cloudPlatform string // aws, vsphere, azure
)

func init() {
flag.StringVar(&veleroCLI, "velerocli", "velero", "path to the velero application to use")
flag.StringVar(&kibishiNamespace, "kibishiins", "kibishii", "namespace to use for Kibishii distributed data generator")
flag.StringVar(&cloudPlatform, "cloudplatform", "aws", "cloud platform we are deploying on (aws, vsphere, azure)")
}

func TestE2e(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "E2e Suite")
}
Loading

0 comments on commit 3ac2fd5

Please sign in to comment.