Skip to content

Commit

Permalink
Incorporated changes from review, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcburns committed Dec 6, 2023
1 parent ebab84a commit de61fa1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,19 @@ func (c *Client) FirmwareInstallUploadAndInitiate(ctx context.Context, component

// GetSystemEventLog queries for the SEL and returns the entries in an opinionated format.
func (c *Client) GetSystemEventLog(ctx context.Context) (entries bmc.SystemEventLogEntries, err error) {

Check warning on line 672 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L670-L672

Added lines #L670 - L672 were not covered by tests
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetSystemEventLog")
defer span.End()

entries, metadata, err := bmc.GetSystemEventLogFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())

Check warning on line 676 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L674-L676

Added lines #L674 - L676 were not covered by tests
c.setMetadata(metadata)
return entries, err

Check warning on line 678 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L678

Added line #L678 was not covered by tests
}

// GetSystemEventLogRaw queries for the SEL and returns the raw response.
func (c *Client) GetSystemEventLogRaw(ctx context.Context) (eventlog string, err error) {
ctx, span := c.traceprovider.Tracer(pkgName).Start(ctx, "GetSystemEventLogRaw")

Check warning on line 683 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L681-L683

Added lines #L681 - L683 were not covered by tests
defer span.End()

eventlog, metadata, err := bmc.GetSystemEventLogRawFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces())
c.setMetadata(metadata)

Check warning on line 687 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L685-L687

Added lines #L685 - L687 were not covered by tests
return eventlog, err
Expand Down
11 changes: 6 additions & 5 deletions examples/sel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,29 @@ func main() {
}
defer cl.Close(ctx)

if *action == "get" {
switch *action {
case "get":
entries, err := cl.GetSystemEventLog(ctx)
if err != nil {
l.WithError(err).Fatal(err, "failed to get System Event Log")
}
l.Info("System Event Log entries", "entries", entries)
return
} else if *action == "get-raw" {
case "get-raw":
eventlog, err := cl.GetSystemEventLogRaw(ctx)
if err != nil {
l.WithError(err).Fatal(err, "failed to get System Event Log Raw")
}
l.Info("System Event Log", "eventlog", eventlog)
return
} else if *action == "clear" {

case "clear":
err = cl.ClearSystemEventLog(ctx)
if err != nil {
l.WithError(err).Fatal(err, "failed to clear System Event Log")
}
l.Info("System Event Log cleared")
} else {
return
default:
l.Fatal("invalid action")
}
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stmcginnis/gofish v0.14.1-0.20231018151402-dddaff9168fb h1:+BpzUuFIEAs71bTshedsUHAAq21VZWvuokbN9ABEQeQ=
github.com/stmcginnis/gofish v0.14.1-0.20231018151402-dddaff9168fb/go.mod h1:BLDSFTp8pDlf/xDbLZa+F7f7eW0E/CHCboggsu8CznI=
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91 h1:WmABtU8y6kTgzoVUn3FWCQGAfyodve3uz3xno28BrRs=
github.com/stmcginnis/gofish v0.15.1-0.20231121142100-22a60a77be91/go.mod h1:BLDSFTp8pDlf/xDbLZa+F7f7eW0E/CHCboggsu8CznI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
15 changes: 11 additions & 4 deletions internal/ipmi/ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,18 @@ func (i *Ipmi) GetSystemEventLog(ctx context.Context) (entries [][]string, err e
return nil, errors.Wrap(err, "error getting system event log")
}

scanner := bufio.NewScanner(strings.NewReader(output))
entries = parseSystemEventLog(output)

return entries, nil
}

// parseSystemEventLogRaw parses the raw output of the system event log. Helper
// function for GetSystemEventLog to make testing the parser easier.
func parseSystemEventLog(raw string) (entries [][]string) {
scanner := bufio.NewScanner(strings.NewReader(raw))
for scanner.Scan() {
line := strings.Split(scanner.Text(), "|")
if len(line) < 3 {
if len(line) < 6 {
continue
}
if line[0] == "ID" {
Expand All @@ -403,12 +411,11 @@ func (i *Ipmi) GetSystemEventLog(ctx context.Context) (entries [][]string, err e
for i := range line {
line[i] = strings.TrimSpace(line[i])
}

// ID, Timestamp (date time), Description, Message (message : assertion)
entries = append(entries, []string{line[0], fmt.Sprintf("%s %s", line[1], line[2]), line[3], fmt.Sprintf("%s : %s", line[4], line[5])})
}

return entries, nil
return entries
}

// GetSystemEventLogRaw returns the raw SEL output
Expand Down
3 changes: 0 additions & 3 deletions internal/redfishwrapper/sel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package redfishwrapper
import (
"context"
"encoding/json"
"log"

bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors"
"github.com/pkg/errors"
Expand Down Expand Up @@ -55,8 +54,6 @@ func (c *Client) GetSystemEventLog(ctx context.Context) (entries [][]string, err
return nil, err

Check warning on line 54 in internal/redfishwrapper/sel.go

View check run for this annotation

Codecov / codecov/patch

internal/redfishwrapper/sel.go#L51-L54

Added lines #L51 - L54 were not covered by tests
}

log.Println(len(logServices))

for _, logService := range logServices {
lentries, err := logService.Entries()
if err != nil {
Expand Down

0 comments on commit de61fa1

Please sign in to comment.