From 8d9bbe9da14421609e8ce2e2dacac3371ebdada4 Mon Sep 17 00:00:00 2001 From: Or Shoval Date: Tue, 13 Aug 2024 14:21:07 +0300 Subject: [PATCH] WIP: test artifacts Signed-off-by: Or Shoval --- .github/workflows/checks.yaml | 12 ++++++++++++ Makefile | 2 +- test/e2e/e2e_suite_test.go | 6 ++++++ test/e2e/persistentips_test.go | 18 ++++++++++++++++-- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 1c331bd8..d8debd66 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -71,8 +71,20 @@ jobs: - name: Run e2e tests run: make test-e2e + - name: Find and list the test file + run: | + echo "Searching for test file..." + find . -name "*.log" + - uses: actions/upload-artifact@v4 # upload test results if: success() || failure() # run this step even if previous step failed with: name: test-e2e-results path: .output/*.xml + + - name: Upload logs as artifacts + uses: actions/upload-artifact@v4 + if: failure() + with: + name: pod-logs + path: .output/*.log diff --git a/Makefile b/Makefile index f0c95663..d5fa408c 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ test-e2e: export PATH=$$(pwd)/.output/ovn-kubernetes/bin:$${PATH} && \ export REPORT_PATH=$$(pwd)/.output/ && \ cd test/e2e && \ - go test -test.v --ginkgo.v --test.timeout=${E2E_TEST_TIMEOUT} ${E2E_TEST_ARGS} --ginkgo.junit-report=$${REPORT_PATH}/test-e2e.junit.xml + go test -test.v --failfast --ginkgo.v --test.timeout=${E2E_TEST_TIMEOUT} ${E2E_TEST_ARGS} --ginkgo.junit-report=$${REPORT_PATH}/test-e2e.junit.xml .PHONY: lint lint: golangci-lint ## Run golangci-lint linter & yamllint diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index a02c338b..2d952b43 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -17,6 +17,8 @@ limitations under the License. package e2e import ( + "fmt" + "os" "testing" . "github.com/onsi/ginkgo/v2" @@ -36,6 +38,10 @@ var _ = BeforeSuite(func() { // Run e2e tests using the Ginkgo runner. func TestE2E(t *testing.T) { + if err := os.MkdirAll(".output", 0755); err != nil { + panic(fmt.Sprintf("Error creating directory: %v", err)) + } + RegisterFailHandler(Fail) RunSpecs(t, "kubevirt-ipam-controller e2e suite") } diff --git a/test/e2e/persistentips_test.go b/test/e2e/persistentips_test.go index 9e306ec4..24ba4085 100644 --- a/test/e2e/persistentips_test.go +++ b/test/e2e/persistentips_test.go @@ -42,12 +42,24 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +var failureCount int = 0 + var _ = Describe("Persistent IPs", func() { JustAfterEach(func() { - if CurrentGinkgoTestDescription().Failed { + if CurrentSpecReport().Failed() { + failureCount++ By("Test failed, collecting logs and artifacts") podsStatus, stderr, err := kubectl("get", "pods", "-A") - fmt.Printf("kubectl get pods:\n%v\nerror:\n%v\n", podsStatus+stderr, err) + fileName := fmt.Sprintf(".output/try_%d.log", failureCount) + file, err := os.Create(fileName) + if err != nil { + fmt.Println("Error creating file:", err) + return + } + defer file.Close() + + fmt.Fprintf(file, "kubectl get pods:\n%v\nerror:\n%v\n", podsStatus, stderr) + //fmt.Printf("kubectl get pods:\n%v\nerror:\n%v\n", podsStatus+stderr, err) } }) @@ -84,6 +96,8 @@ var _ = Describe("Persistent IPs", func() { WithTimeout(5 * time.Minute). Should(BeTrue()) + Expect(1).To(Equal(2)) + By("Wait for IPAMClaim to get created") Eventually(testenv.IPAMClaimsFromNamespace(vm.Namespace)). WithTimeout(time.Minute).