Skip to content

Commit

Permalink
Running must gather after each tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakraj1997 committed Mar 11, 2022
1 parent 726af63 commit 0a19965
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ AZURE_RESOURCE_FILE ?= /var/run/secrets/ci.openshift.io/multi-stage/metadata.jso
OPENSHIFT_CI ?= true
VELERO_INSTANCE_NAME ?= velero-sample
E2E_TIMEOUT_MULTIPLIER ?= 1
ARTIFACT_DIR ?= /tmp

ifeq ($(CLUSTER_TYPE), gcp)
CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/gce.json
Expand Down Expand Up @@ -351,7 +352,8 @@ test-e2e: test-e2e-setup
-ci_cred_file=$(CI_CRED_FILE) \
-azure_resource_file=$(AZURE_RESOURCE_FILE) \
-provider=$(CLUSTER_TYPE) \
-creds_secret_ref=$(CREDS_SECRET_REF)
-creds_secret_ref=$(CREDS_SECRET_REF) \
-artifact_dir=$(ARTIFACT_DIR)

test-e2e-cleanup:
rm -rf $(SETTINGS_TMP)
13 changes: 12 additions & 1 deletion tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// Common vars obtained from flags passed in ginkgo.
var credFile, namespace, credSecretRef, instanceName, provider, azure_resource_file, openshift_ci, ci_cred_file, settings, bsl_profile string
var credFile, namespace, credSecretRef, instanceName, provider, azure_resource_file, openshift_ci, ci_cred_file, settings, bsl_profile, artifact_dir string
var timeoutMultiplier time.Duration

func init() {
Expand All @@ -30,6 +30,7 @@ func init() {
flag.StringVar(&azure_resource_file, "azure_resource_file", "azure resource file", "Resource Group Dir for azure")
flag.StringVar(&ci_cred_file, "ci_cred_file", credFile, "CI Cloud Cred File")
flag.StringVar(&openshift_ci, "openshift_ci", "false", "ENV for tests")
flag.StringVar(&artifact_dir, "artifact_dir", "/tmp", "Directory for storing must gather")

timeoutMultiplierInput := flag.Int64("timeout_multiplier", 1, "Customize timeout multiplier from default (1)")
timeoutMultiplier = 1
Expand Down Expand Up @@ -143,6 +144,16 @@ var _ = BeforeSuite(func() {
Expect(DoesNamespaceExist(namespace)).Should(BeTrue())
})

var _ = ReportAfterEach(func(report SpecReport) {
if report.Failed() {
log.Printf("Running must gather for failed test - " + report.LeafNodeText)
err := RunMustGather(artifact_dir + "/must-gather-" + report.LeafNodeText)
if err != nil {
log.Printf("Failed to run must gather: " + err.Error())
}
}
})

var _ = AfterSuite(func() {
log.Printf("Deleting Velero CR")
errs := DeleteSecret(namespace, GetSecretRef(credSecretRef))
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/lib/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"os/exec"

"github.com/onsi/ginkgo/v2"
ocpappsv1 "github.com/openshift/api/apps/v1"
Expand Down Expand Up @@ -182,3 +183,15 @@ func AreApplicationPodsRunning(namespace string) wait.ConditionFunc {
return true, err
}
}

func RunMustGather(artifact_dir string) error {
ocClient := "oc"
ocAdmin := "adm"
mustGatherCmd := "must-gather"
mustGatherImg := "--image=quay.io/konveyor/oadp-must-gather:latest"
destDir := "--dest-dir=" + artifact_dir

cmd := exec.Command(ocClient, ocAdmin, mustGatherCmd, mustGatherImg, destDir)
_, err := cmd.Output()
return err
}

0 comments on commit 0a19965

Please sign in to comment.