Skip to content

Commit

Permalink
test/e2e: Swap some Fatal for Error
Browse files Browse the repository at this point in the history
If we just hit timeout whilst waiting for pods to get to
into the expected state, or during testing/clean-up
of resources, then `Error` instead of `Fatal`
as we don't want to skip the logging and cleanup.

Signed-off-by: stevenhorsman <[email protected]>
  • Loading branch information
stevenhorsman committed Dec 20, 2024
1 parent fec1d1e commit 7f48ac3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/cloud-api-adaptor/test/e2e/assessment_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,19 @@ func (tc *TestCase) Run() {
t.Fatal(err)
}
if err = wait.For(conditions.New(client.Resources()).PodPhaseMatch(tc.pod, tc.podState), wait.WithTimeout(WAIT_POD_RUNNING_TIMEOUT)); err != nil {
t.Fatal(err)
t.Error(err)
}
if tc.podState == v1.PodRunning || len(tc.testCommands) > 0 {
t.Logf("Waiting for containers in pod: %v are ready", tc.pod.Name)
if err = wait.For(conditions.New(client.Resources()).ContainersReady(tc.pod), wait.WithTimeout(WAIT_POD_RUNNING_TIMEOUT)); err != nil {
//Added logs for debugging nightly tests
clientset, err := kubernetes.NewForConfig(client.RESTConfig())
if err != nil {
t.Fatal(err)
t.Error(err)
}
pod, err := clientset.CoreV1().Pods(tc.pod.Namespace).Get(ctx, tc.pod.Name, metav1.GetOptions{})
if err != nil {
t.Fatal(err)
t.Error(err)
}
t.Logf("Expected Pod State: %v", tc.podState)
yamlData, err := yaml.Marshal(pod.Status)
Expand All @@ -304,7 +304,7 @@ func (tc *TestCase) Run() {
t.Log(podLogString)
t.Logf("===================\n")
}
t.Fatal(err)
t.Error(err)
}
}
}
Expand Down Expand Up @@ -439,13 +439,13 @@ func (tc *TestCase) Run() {
for _, extraPod := range tc.extraPods {
if extraPod.imagePullTimer {
// TBD
t.Fatal("Please implement assess logic for imagePullTimer")
t.Error("Please implement assess logic for imagePullTimer")
}
if extraPod.expectedPodLogString != "" {
LogString, err := ComparePodLogString(ctx, client, extraPod.pod, extraPod.expectedPodLogString)
if err != nil {
t.Logf("Output:%s", LogString)
t.Fatal(err)
t.Error(err)
}
t.Logf("Log output of peer pod:%s", LogString)
}
Expand All @@ -454,15 +454,15 @@ func (tc *TestCase) Run() {
logString, err := AssessPodTestCommands(ctx, client, extraPod.pod, extraPod.testCommands)
t.Logf("Output when execute test commands:%s", logString)
if err != nil {
t.Fatal(err)
t.Error(err)
}
}
tc.assert.HasPodVM(t, extraPod.pod.Name)
}

if tc.isNydusSnapshotter {
// TBD
t.Fatal("Error: isNydusSnapshotter hasn't been implemented in extraPods. Please implement assess function for isNydusSnapshotter.")
t.Error("Error: isNydusSnapshotter hasn't been implemented in extraPods. Please implement assess function for isNydusSnapshotter.")
}
}
}
Expand All @@ -476,15 +476,15 @@ func (tc *TestCase) Run() {

if tc.configMap != nil {
if err = client.Resources().Delete(ctx, tc.configMap); err != nil {
t.Fatal(err)
t.Error(err)
}

t.Logf("Deleting Configmap... %s", tc.configMap.Name)
}

if tc.secret != nil {
if err = client.Resources().Delete(ctx, tc.secret); err != nil {
t.Fatal(err)
t.Error(err)
} else {
t.Logf("Deleting Secret... %s", tc.secret.Name)
}
Expand All @@ -496,14 +496,14 @@ func (tc *TestCase) Run() {
t.Fatal(err)
}
if err = clientSet.CoreV1().Secrets(E2eNamespace).Delete(ctx, DEFAULT_AUTH_SECRET, metav1.DeleteOptions{}); err != nil {
t.Fatal(err)
t.Error(err)
}
}

if tc.extraSecrets != nil {
for _, extraSecret := range tc.extraSecrets {
if err = client.Resources().Delete(ctx, extraSecret); err != nil {
t.Fatal(err)
t.Error(err)
} else {
t.Logf("Deleting extra Secret... %s", extraSecret.Name)
}
Expand All @@ -525,13 +525,13 @@ func (tc *TestCase) Run() {
}

if err = client.Resources().Delete(ctx, tc.job); err != nil {
t.Fatal(err)
t.Error(err)
} else {
t.Logf("Deleting Job... %s", tc.job.Name)
}
for _, pod := range podList.Items {
if err = client.Resources().Delete(ctx, &pod); err != nil {
t.Fatal(err)
t.Error(err)
}
t.Logf("Deleting pods created by job... %s", pod.ObjectMeta.Name)
}
Expand All @@ -544,14 +544,14 @@ func (tc *TestCase) Run() {
}

if err = client.Resources().Delete(ctx, tc.pod); err != nil {
t.Fatal(err)
t.Error(err)
}
t.Logf("Deleting pod %s...", tc.pod.Name)
if err = wait.For(conditions.New(
client.Resources()).ResourceDeleted(tc.pod),
wait.WithInterval(5*time.Second),
wait.WithTimeout(tc.deletionWithin)); err != nil {
t.Fatal(err)
t.Error(err)
}
t.Logf("Pod %s has been successfully deleted within %.0fs", tc.pod.Name, tc.deletionWithin.Seconds())
}
Expand All @@ -563,23 +563,23 @@ func (tc *TestCase) Run() {
err := DeletePod(ctx, client, pod, &tc.deletionWithin)
if err != nil {
t.Logf("Error occurs when delete pod: %s", extraPod.pod.Name)
t.Fatal(err)
t.Error(err)
}
t.Logf("Pod %s has been successfully deleted within %.0fs", pod.Name, tc.deletionWithin.Seconds())
}
}

if tc.pvc != nil {
if err = client.Resources().Delete(ctx, tc.pvc); err != nil {
t.Fatal(err)
t.Error(err)
} else {
t.Logf("Deleting PVC... %s", tc.pvc.Name)
}
}

if tc.service != nil {
if err = client.Resources().Delete(ctx, tc.service); err != nil {
t.Fatal(err)
t.Error(err)
} else {
t.Logf("Deleting Service... %s", tc.service.Name)
}
Expand Down

0 comments on commit 7f48ac3

Please sign in to comment.