Skip to content

Commit ad322bc

Browse files
authored
Merge pull request #428 from shapeblue/fixup-log
Fixup e2e test func errorExistsInLog
2 parents 1b229ac + 6a561cc commit ad322bc

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

pkg/cloud/zone.go

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type ZoneIFace interface {
3030

3131
func (c *client) ResolveZone(zSpec *infrav1.CloudStackZoneSpec) (retErr error) {
3232
if zoneID, count, err := c.cs.Zone.GetZoneID(zSpec.Name); err != nil {
33-
retErr = multierror.Append(retErr, errors.Wrapf(err, "could not get Zone ID from %v", zSpec.Name))
3433
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(err)
3534
retErr = multierror.Append(retErr, errors.Wrapf(err, "could not get Zone ID from %v", zSpec.Name))
3635
} else if count != 1 {

test/e2e/invalid_resource.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"os"
2424
"path/filepath"
25+
"regexp"
2526
"strings"
2627

2728
. "github.com/onsi/ginkgo/v2"
@@ -46,6 +47,8 @@ var (
4647
cancelWatches context.CancelFunc
4748
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
4849
MachineInErrorMessage = "CloudStackMachine VM in error state. Deleting associated Machine"
50+
// Pattern that matches start of Kubernetes log entries
51+
logEntryPattern = `[IWEF]\d{4} \d{2}:\d{2}:\d{2}\.\d{6}`
4952
)
5053

5154
// InvalidResourceSpec implements a test that verifies that creating a new cluster fails when the specified resource does not exist
@@ -224,17 +227,21 @@ func errorExistsInLog(logFolder string, expectedError string) (bool, error) {
224227
}
225228

226229
if strings.Contains(path, "manager.log") {
227-
log, _ := os.ReadFile(path)
228-
logLines := strings.Split(string(log), "\n")
229-
for _, line := range logLines {
230-
if strings.Contains(line, expectedError) &&
231-
strings.Contains(line, clusterResources.Cluster.Namespace) {
230+
logContent, err := os.ReadFile(path)
231+
if err != nil {
232+
return err
233+
}
234+
235+
// Split log content by the log entry pattern
236+
entries := regexp.MustCompile(logEntryPattern).Split(string(logContent), -1)
237+
for _, entry := range entries {
238+
if strings.Contains(entry, expectedError) &&
239+
strings.Contains(entry, clusterResources.Cluster.Namespace) {
232240
Byf("Found %q error", expectedError)
233241
return expectedErrorFound
234242
}
235243
}
236244
}
237-
238245
return nil
239246
})
240247

0 commit comments

Comments
 (0)