Skip to content

Commit a2373e5

Browse files
authored
test: cleanup leftover logs from db management E2Es (cloudnative-pg#7217)
Closes cloudnative-pg#6411 Usually, at the end of a green test, `cleanupNamespace()` will take care of deleting the testing logs captured and issuing an `objects.Delete` request (we do not actually wait for the namespace to be gone though). This Database management E2E is an exception to the usual way we create/destroy testing namespaces. Here we want to test that Database object finalizers do not prevent the deletion of a namespace, hence we need to ensure the namespace is properly gone before declaring that the test succeded. After doing that, we now cleanup the testing logs. Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
1 parent 19e0a64 commit a2373e5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

tests/e2e/declarative_database_management_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ var _ = Describe("Declarative database management", Label(tests.LabelSmoke, test
226226
By("deleting the namespace and making sure it succeeds before timeout", func() {
227227
err := namespaces.DeleteNamespaceAndWait(env.Ctx, env.Client, namespace, 120)
228228
Expect(err).ToNot(HaveOccurred())
229+
// we need to cleanup testing logs adhoc since we are not using a testingNamespace for this test
230+
err = namespaces.CleanupClusterLogs(namespace, CurrentSpecReport().Failed())
231+
Expect(err).ToNot(HaveOccurred())
229232
})
230233
})
231234
})

tests/utils/namespaces/namespace.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ func getPreserveNamespaces() []string {
6464
return preserveNamespacesList
6565
}
6666

67+
// CleanupClusterLogs cleans up the cluster logs of a given namespace
68+
func CleanupClusterLogs(namespace string, testFailed bool) error {
69+
exists, _ := fileutils.FileExists(path.Join(SternLogDirectory, namespace))
70+
if exists && !testFailed {
71+
if err := fileutils.RemoveDirectory(path.Join(SternLogDirectory, namespace)); err != nil {
72+
return err
73+
}
74+
}
75+
76+
return nil
77+
}
78+
6779
// cleanupNamespace does cleanup duty related to the tear-down of a namespace,
6880
// and is intended to be called in a DeferCleanup clause
6981
func cleanupNamespace(
@@ -79,12 +91,9 @@ func cleanupNamespace(
7991
if len(namespace) == 0 {
8092
return fmt.Errorf("namespace is empty")
8193
}
82-
exists, _ := fileutils.FileExists(path.Join(SternLogDirectory, namespace))
83-
if exists && !testFailed {
84-
err := fileutils.RemoveDirectory(path.Join(SternLogDirectory, namespace))
85-
if err != nil {
86-
return err
87-
}
94+
95+
if err := CleanupClusterLogs(namespace, testFailed); err != nil {
96+
return err
8897
}
8998

9099
return deleteNamespace(ctx, crudClient, namespace)

0 commit comments

Comments
 (0)