Skip to content

Commit

Permalink
test: Retina e2e scale test
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Castilio dos Santos <[email protected]>
  • Loading branch information
alexcastilio committed Sep 10, 2024
1 parent 6d9050c commit a853797
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 15 deletions.
7 changes: 6 additions & 1 deletion test/e2e/framework/types/background_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"context"
"fmt"
"log"
"sync"
Expand All @@ -9,9 +10,13 @@ import (
)

func TestFramework(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

job := NewJob("Validate that drop metrics are present in the prometheus endpoint")
runner := NewRunner(t, job)
defer runner.Run()
defer runner.Run(ctx)

job.AddStep(&TestBackground{
CounterName: "Example Counter",
Expand Down
16 changes: 14 additions & 2 deletions test/e2e/framework/types/runner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"context"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -20,9 +21,20 @@ func NewRunner(t *testing.T, job *Job) *Runner {
}
}

func (r *Runner) Run() {
func (r *Runner) Run(ctx context.Context) {
if r.t.Failed() {
return
}
require.NoError(r.t, r.Job.Run())
runComplete := make(chan struct{})

go func() {
require.NoError(r.t, r.Job.Run())
runComplete <- struct{}{}
}()
select {
case <-ctx.Done():
r.t.Fatal("Timeout")
case <-runComplete:
return
}
}
19 changes: 16 additions & 3 deletions test/e2e/framework/types/scenarios_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"context"
"fmt"
"testing"
)
Expand All @@ -9,9 +10,13 @@ import (
// create a pod with a deny all network policy and validate
// that the drop metrics are present in the prometheus endpoint
func TestScenarioValues(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

job := NewJob("Validate that drop metrics are present in the prometheus endpoint")
runner := NewRunner(t, job)
defer runner.Run()
defer runner.Run(ctx)

// Add top level step
job.AddStep(&DummyStep{
Expand All @@ -30,9 +35,13 @@ func TestScenarioValues(t *testing.T) {
// create a pod with a deny all network policy and validate
// that the drop metrics are present in the prometheus endpoint
func TestScenarioValuesWithSkip(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

job := NewJob("Validate that drop metrics are present in the prometheus endpoint")
runner := NewRunner(t, job)
defer runner.Run()
defer runner.Run(ctx)

// Add top level step
job.AddStep(&DummyStep{
Expand All @@ -53,9 +62,13 @@ func TestScenarioValuesWithSkip(t *testing.T) {
}

func TestScenarioValuesWithScenarioSkip(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

job := NewJob("Validate that drop metrics are present in the prometheus endpoint")
runner := NewRunner(t, job)
defer runner.Run()
defer runner.Run(ctx)

// Add top level step
job.AddStep(&DummyStep{
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func DeleteTestInfra(subID, clusterName, location string) *types.Job {
return job
}

func InstallRetina(kubeConfigFilePath, chartPath string) *types.Job {
job := types.NewJob("Install and test Retina with basic metrics")

job.AddStep(&kubernetes.InstallHelmChart{
Namespace: "kube-system",
ReleaseName: "retina",
KubeConfigFilePath: kubeConfigFilePath,
ChartPath: chartPath,
TagEnv: generic.DefaultTagEnv,
}, nil)

return job
}

func InstallAndTestRetinaBasicMetrics(kubeConfigFilePath, chartPath string) *types.Job {
job := types.NewJob("Install and test Retina with basic metrics")

Expand Down
19 changes: 10 additions & 9 deletions test/e2e/retina_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package retina

import (
"context"
"crypto/rand"
"math/big"
"os"
Expand All @@ -20,6 +21,10 @@ var locations = []string{"eastus2", "centralus", "southcentralus", "uksouth", "c

// TestE2ERetina tests all e2e scenarios for retina
func TestE2ERetina(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

curuser, err := user.Current()
require.NoError(t, err)

Expand Down Expand Up @@ -50,21 +55,17 @@ func TestE2ERetina(t *testing.T) {

// CreateTestInfra
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, clusterName, location, kubeConfigFilePath))
createTestInfra.Run()
createTestInfra.Run(ctx)

// Hacky way to ensure that the test infra is deleted even if the test panics
defer func() {
if r := recover(); r != nil {
t.Logf("Recovered in TestE2ERetina, %v", r)
}
t.Cleanup(func() {
_ = jobs.DeleteTestInfra(subID, clusterName, location).Run()
}()
})

// Install and test Retina basic metrics
basicMetricsE2E := types.NewRunner(t, jobs.InstallAndTestRetinaBasicMetrics(kubeConfigFilePath, chartPath))
basicMetricsE2E.Run()
basicMetricsE2E.Run(ctx)

// Upgrade and test Retina with advanced metrics
advanceMetricsE2E := types.NewRunner(t, jobs.UpgradeAndTestRetinaAdvancedMetrics(kubeConfigFilePath, chartPath, profilePath))
advanceMetricsE2E.Run()
advanceMetricsE2E.Run(ctx)
}
66 changes: 66 additions & 0 deletions test/e2e/scale_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package retina

import (
"context"
"crypto/rand"
"math/big"
"os"
"os/user"
"path/filepath"
"strconv"
"testing"
"time"

"github.com/microsoft/retina/test/e2e/common"
"github.com/microsoft/retina/test/e2e/framework/types"
jobs "github.com/microsoft/retina/test/e2e/jobs"
"github.com/stretchr/testify/require"
)

func TestE2ERetina_Scale(t *testing.T) {
deadline, _ := t.Deadline()
ctx, cancel := context.WithDeadline(context.Background(), deadline)
defer cancel()

curuser, err := user.Current()
require.NoError(t, err)

clusterName := curuser.Username + common.NetObsRGtag + strconv.FormatInt(time.Now().Unix(), 10)

subID := os.Getenv("AZURE_SUBSCRIPTION_ID")
require.NotEmpty(t, subID)

location := os.Getenv("AZURE_LOCATION")
if location == "" {
var nBig *big.Int
nBig, err = rand.Int(rand.Reader, big.NewInt(int64(len(locations))))
if err != nil {
t.Fatalf("Failed to generate a secure random index: %v", err)
}
location = locations[nBig.Int64()]
}
cwd, err := os.Getwd()
require.NoError(t, err)

// Get to root of the repo by going up two directories
rootDir := filepath.Dir(filepath.Dir(cwd))

chartPath := filepath.Join(rootDir, "deploy", "legacy", "manifests", "controller", "helm", "retina")
kubeConfigFilePath := filepath.Join(rootDir, "test", "e2e", "test.pem")

// CreateTestInfra
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, clusterName, location, kubeConfigFilePath))
createTestInfra.Run(ctx)

t.Cleanup(func() {
_ = jobs.DeleteTestInfra(subID, clusterName, location).Run()
})

// Install Retina
installRetina := types.NewRunner(t, jobs.InstallRetina(kubeConfigFilePath, chartPath))
installRetina.Run(ctx)

// TODO: Scale Cluster

// TODO: equivalent of github.com/Azure/azure-container-networking/test/scale/test-scale.sh
}

0 comments on commit a853797

Please sign in to comment.