From 1438a7d57baf7fe7a18e42ef2fdb74b061d7e7e5 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Tue, 5 Mar 2024 12:17:20 -0800 Subject: [PATCH] Improve E2E Aftersuite cleanup Signed-off-by: Derek Nola --- tests/e2e/btrfs/btrfs_test.go | 4 +--- tests/e2e/dualstack/dualstack_test.go | 6 +++--- tests/e2e/embeddedmirror/embeddedmirror_test.go | 9 ++++----- tests/e2e/externalip/externalip_test.go | 6 +++--- tests/e2e/privateregistry/privateregistry_test.go | 8 ++++---- tests/e2e/rotateca/rotateca_test.go | 6 +++--- tests/e2e/s3/s3_test.go | 15 ++++++++------- .../secretsencryption/secretsencryption_test.go | 6 +++--- .../secretsencryption_test.go | 6 +++--- tests/e2e/snapshotrestore/snapshotrestore_test.go | 6 +++--- tests/e2e/splitserver/splitserver_test.go | 4 +--- tests/e2e/startup/startup_test.go | 6 +++--- tests/e2e/tailscale/tailscale_test.go | 6 +++--- tests/e2e/token/token_test.go | 6 +++--- tests/e2e/upgradecluster/upgradecluster_test.go | 6 +++--- tests/e2e/validatecluster/validatecluster_test.go | 6 +++--- 16 files changed, 51 insertions(+), 55 deletions(-) diff --git a/tests/e2e/btrfs/btrfs_test.go b/tests/e2e/btrfs/btrfs_test.go index e45a979586..4311dd65bc 100644 --- a/tests/e2e/btrfs/btrfs_test.go +++ b/tests/e2e/btrfs/btrfs_test.go @@ -90,9 +90,7 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/dualstack/dualstack_test.go b/tests/e2e/dualstack/dualstack_test.go index be13a7c788..11b4e49ecc 100644 --- a/tests/e2e/dualstack/dualstack_test.go +++ b/tests/e2e/dualstack/dualstack_test.go @@ -195,10 +195,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/embeddedmirror/embeddedmirror_test.go b/tests/e2e/embeddedmirror/embeddedmirror_test.go index d7695cef51..f91aa2043c 100644 --- a/tests/e2e/embeddedmirror/embeddedmirror_test.go +++ b/tests/e2e/embeddedmirror/embeddedmirror_test.go @@ -142,14 +142,13 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { + Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { r2, err := e2e.RunCmdOnNode("kubectl delete deployment my-webpage-1 my-webpage-2 my-webpage-3", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), r2) Expect(err).NotTo(HaveOccurred()) - Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/externalip/externalip_test.go b/tests/e2e/externalip/externalip_test.go index 4557296d1c..948c4f387b 100644 --- a/tests/e2e/externalip/externalip_test.go +++ b/tests/e2e/externalip/externalip_test.go @@ -165,10 +165,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/privateregistry/privateregistry_test.go b/tests/e2e/privateregistry/privateregistry_test.go index c4a5c99883..e3dbd1a1de 100644 --- a/tests/e2e/privateregistry/privateregistry_test.go +++ b/tests/e2e/privateregistry/privateregistry_test.go @@ -146,15 +146,15 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { + Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { r1, err := e2e.RunCmdOnNode("docker rm -f registry", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), r1) r2, err := e2e.RunCmdOnNode("kubectl delete deployment my-webpage", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred(), r2) Expect(err).NotTo(HaveOccurred()) - Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/rotateca/rotateca_test.go b/tests/e2e/rotateca/rotateca_test.go index 9c201c8e71..35db8358fd 100644 --- a/tests/e2e/rotateca/rotateca_test.go +++ b/tests/e2e/rotateca/rotateca_test.go @@ -138,10 +138,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/s3/s3_test.go b/tests/e2e/s3/s3_test.go index e109235e00..4b08faf8e5 100644 --- a/tests/e2e/s3/s3_test.go +++ b/tests/e2e/s3/s3_test.go @@ -130,17 +130,18 @@ var _ = Describe("Verify Create", Ordered, func() { // https://github.com/rancher/rke2/issues/3714 // Once fixed, ensure that the snapshots list are actually reduced to 2 It("prunes s3 snapshots", func() { - res, err := e2e.RunCmdOnNode("k3s etcd-snapshot save", serverNodeNames[0]) + _, err := e2e.RunCmdOnNode("k3s etcd-snapshot save", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred()) - res, err = e2e.RunCmdOnNode("k3s etcd-snapshot save", serverNodeNames[0]) + _, err = e2e.RunCmdOnNode("k3s etcd-snapshot save", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred()) - _, err = e2e.RunCmdOnNode("k3s etcd-snapshot prune --snapshot-retention 2", serverNodeNames[0]) - res, err = e2e.RunCmdOnNode("sudo k3s etcd-snapshot prune --snapshot-retention 2", serverNodeNames[0]) + res, err := e2e.RunCmdOnNode("k3s etcd-snapshot prune --snapshot-retention 2", serverNodeNames[0]) Expect(err).NotTo(HaveOccurred()) Expect(res).To(ContainSubstring("Reconciliation of ETCDSnapshotFile resources complete")) _, err = e2e.RunCmdOnNode("k3s etcd-snapshot ls|grep 'on-demand'|wc -l>count", serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) res, err = e2e.RunCmdOnNode("grep '^[4]$' ./count", serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) Expect(strings.TrimSpace(res)).To(Equal("4")) }) }) @@ -153,10 +154,10 @@ var _ = AfterEach(func() { var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/secretsencryption/secretsencryption_test.go b/tests/e2e/secretsencryption/secretsencryption_test.go index 4764aad0fb..3e25e2b9a4 100644 --- a/tests/e2e/secretsencryption/secretsencryption_test.go +++ b/tests/e2e/secretsencryption/secretsencryption_test.go @@ -221,10 +221,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(serverNodeNames)).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/secretsencryption_old/secretsencryption_test.go b/tests/e2e/secretsencryption_old/secretsencryption_test.go index b527268348..c64d133e9f 100644 --- a/tests/e2e/secretsencryption_old/secretsencryption_test.go +++ b/tests/e2e/secretsencryption_old/secretsencryption_test.go @@ -306,10 +306,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(serverNodeNames)).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/snapshotrestore/snapshotrestore_test.go b/tests/e2e/snapshotrestore/snapshotrestore_test.go index 4cf9b4c754..c1ece20a8e 100644 --- a/tests/e2e/snapshotrestore/snapshotrestore_test.go +++ b/tests/e2e/snapshotrestore/snapshotrestore_test.go @@ -317,10 +317,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/splitserver/splitserver_test.go b/tests/e2e/splitserver/splitserver_test.go index 7c774da900..9fb80e9180 100644 --- a/tests/e2e/splitserver/splitserver_test.go +++ b/tests/e2e/splitserver/splitserver_test.go @@ -229,9 +229,7 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/startup/startup_test.go b/tests/e2e/startup/startup_test.go index 6a408ebdf7..ac6c5bd9f5 100644 --- a/tests/e2e/startup/startup_test.go +++ b/tests/e2e/startup/startup_test.go @@ -277,10 +277,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/tailscale/tailscale_test.go b/tests/e2e/tailscale/tailscale_test.go index 2779baf2b5..91b89b6e91 100644 --- a/tests/e2e/tailscale/tailscale_test.go +++ b/tests/e2e/tailscale/tailscale_test.go @@ -117,10 +117,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/token/token_test.go b/tests/e2e/token/token_test.go index 1e9885838f..fe117a0060 100644 --- a/tests/e2e/token/token_test.go +++ b/tests/e2e/token/token_test.go @@ -201,10 +201,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/upgradecluster/upgradecluster_test.go b/tests/e2e/upgradecluster/upgradecluster_test.go index 0da2e039ba..dfea74ec84 100644 --- a/tests/e2e/upgradecluster/upgradecluster_test.go +++ b/tests/e2e/upgradecluster/upgradecluster_test.go @@ -385,10 +385,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) } diff --git a/tests/e2e/validatecluster/validatecluster_test.go b/tests/e2e/validatecluster/validatecluster_test.go index 9ca35b814b..486af3cee4 100644 --- a/tests/e2e/validatecluster/validatecluster_test.go +++ b/tests/e2e/validatecluster/validatecluster_test.go @@ -382,10 +382,10 @@ var _ = AfterEach(func() { }) var _ = AfterSuite(func() { - if failed && !*ci { - fmt.Println("FAILED!") - } else { + if !failed { Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed()) + } + if !failed || *ci { Expect(e2e.DestroyCluster()).To(Succeed()) Expect(os.Remove(kubeConfigFile)).To(Succeed()) }