From 7a0f8bd981900ff14a4bdcad398c0721744dcbdd Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Wed, 30 Aug 2023 21:26:54 -0700 Subject: [PATCH 1/6] ipmitool and redfish sel clear in place, now to wire it up --- internal/ipmi/ipmi.go | 6 ++++++ internal/redfishwrapper/sel.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 internal/redfishwrapper/sel.go diff --git a/internal/ipmi/ipmi.go b/internal/ipmi/ipmi.go index 8b036794..c79ea089 100644 --- a/internal/ipmi/ipmi.go +++ b/internal/ipmi/ipmi.go @@ -377,3 +377,9 @@ func (i *Ipmi) ReadUsers(ctx context.Context) (users []map[string]string, err er return users, err } + +// Clear SEL clears the SEL +func (i *Ipmi) ClearSEL(ctx context.Context) (err error) { + _, err = i.run(ctx, []string{"sel", "clear"}) + return err +} diff --git a/internal/redfishwrapper/sel.go b/internal/redfishwrapper/sel.go new file mode 100644 index 00000000..099abd31 --- /dev/null +++ b/internal/redfishwrapper/sel.go @@ -0,0 +1,36 @@ +package redfishwrapper + +import ( + "context" + + bmclibErrs "github.com/bmc-toolbox/bmclib/v2/errors" + "github.com/pkg/errors" +) + +// Clear SEL clears all of the LogServices logs +func (c *Client) ClearSEL(ctx context.Context) (err error) { + if err := c.SessionActive(); err != nil { + return errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) + } + + chassis, err := c.client.Service.Chassis() + if err != nil { + return err + } + + for _, c := range chassis { + logServices, err := c.LogServices() + if err != nil { + return err + } + + for _, logService := range logServices { + err = logService.ClearLog() + if err != nil { + return err + } + } + } + + return nil +} From 37ecdda0ba33b23cba525d7d100c3fae24fd8002 Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Tue, 5 Sep 2023 18:13:24 +0000 Subject: [PATCH 2/6] tests next --- bmc/sel.go | 69 ++++++++++++++++++++++++++++++++++ client.go | 6 +++ providers/ipmitool/ipmitool.go | 4 ++ providers/redfish/sel.go | 7 ++++ 4 files changed, 86 insertions(+) create mode 100644 bmc/sel.go create mode 100644 providers/redfish/sel.go diff --git a/bmc/sel.go b/bmc/sel.go new file mode 100644 index 00000000..584750da --- /dev/null +++ b/bmc/sel.go @@ -0,0 +1,69 @@ +package bmc + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-multierror" + "github.com/pkg/errors" +) + +// SELServices for various SEL related services +type SELService interface { + ClearSEL(ctx context.Context) (err error) +} + +type selProviders struct { + name string + selProvider SELService +} + +func clearSEL(ctx context.Context, timeout time.Duration, s []selProviders) (metadata Metadata, err error) { + var metadataLocal Metadata + + for _, elem := range s { + if elem.selProvider == nil { + continue + } + select { + case <-ctx.Done(): + err = multierror.Append(err, ctx.Err()) + + return metadata, err + default: + metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name) + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + selErr := elem.selProvider.ClearSEL(ctx) + if selErr != nil { + err = multierror.Append(err, errors.WithMessagef(selErr, "provider: %v", elem.name)) + continue + } + metadataLocal.SuccessfulProvider = elem.name + return metadataLocal, nil + } + + } + + return metadataLocal, multierror.Append(err, errors.New("failed to reset SEL")) +} + +func ClearSELFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (metadata Metadata, err error) { + selServices := make([]selProviders, 0) + for _, elem := range generic { + temp := selProviders{name: getProviderName(elem)} + switch p := elem.(type) { + case SELService: + temp.selProvider = p + selServices = append(selServices, temp) + default: + e := fmt.Sprintf("not a SELService implementation: %T", p) + err = multierror.Append(err, errors.New(e)) + } + } + if len(selServices) == 0 { + return metadata, multierror.Append(err, errors.New("no SelService implementations found")) + } + return clearSEL(ctx, timeout, selServices) +} diff --git a/client.go b/client.go index c5ecadde..604426e5 100644 --- a/client.go +++ b/client.go @@ -378,3 +378,9 @@ func (c *Client) Screenshot(ctx context.Context) (image []byte, fileType string, return image, fileType, err } + +func (c *Client) ClearSEL(ctx context.Context) (err error) { + metadata, err := bmc.ClearSELFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces()) + c.setMetadata(metadata) + return err +} diff --git a/providers/ipmitool/ipmitool.go b/providers/ipmitool/ipmitool.go index e104884e..2cd17b7d 100644 --- a/providers/ipmitool/ipmitool.go +++ b/providers/ipmitool/ipmitool.go @@ -180,3 +180,7 @@ func (c *Conn) PowerSet(ctx context.Context, state string) (ok bool, err error) return ok, err } + +func (c *Conn) ClearSEL(ctx context.Context) (err error) { + return c.ipmitool.ClearSEL(ctx) +} diff --git a/providers/redfish/sel.go b/providers/redfish/sel.go new file mode 100644 index 00000000..7501712d --- /dev/null +++ b/providers/redfish/sel.go @@ -0,0 +1,7 @@ +package redfish + +import "context" + +func (c *Conn) ClearSEL(ctx context.Context) (err error) { + return c.redfishwrapper.ClearSEL(ctx) +} From 78c3a1553ee194d7021fd73e9c8e1801749a7b19 Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Thu, 7 Sep 2023 18:31:06 +0000 Subject: [PATCH 3/6] tests added --- .devcontainer/devcontainer.json | 22 +++++++++++ bmc/sel_test.go | 61 +++++++++++++++++++++++++++++ providers/ipmitool/ipmitool_test.go | 18 +++++++++ 3 files changed, 101 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 bmc/sel_test.go diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..893a422f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go +{ + "name": "Go", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/go:1-1.21-bullseye" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "go version", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/bmc/sel_test.go b/bmc/sel_test.go new file mode 100644 index 00000000..14f3a96a --- /dev/null +++ b/bmc/sel_test.go @@ -0,0 +1,61 @@ +package bmc + +import ( + "context" + "testing" + "time" + + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" +) + +type mockSELService struct { + name string + err error +} + +func (m *mockSELService) ClearSEL(ctx context.Context) error { + return m.err +} + +func (m *mockSELService) Name() string { + return m.name +} + +func TestClearSEL(t *testing.T) { + ctx := context.Background() + timeout := 1 * time.Second + + // Test with a mock SELService that returns nil + mockService := &mockSELService{name: "mock1", err: nil} + metadata, err := clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}}) + assert.Nil(t, err) + assert.Equal(t, mockService.name, metadata.SuccessfulProvider) + + // Test with a mock SELService that returns an error + mockService = &mockSELService{name: "mock2", err: errors.New("mock error")} + metadata, err = clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}}) + assert.NotNil(t, err) + assert.NotEqual(t, mockService.name, metadata.SuccessfulProvider) +} + +func TestClearSELFromInterfaces(t *testing.T) { + ctx := context.Background() + timeout := 1 * time.Second + + // Test with an empty slice + metadata, err := ClearSELFromInterfaces(ctx, timeout, []interface{}{}) + assert.NotNil(t, err) + assert.Empty(t, metadata.SuccessfulProvider) + + // Test with a slice containing a non-SELService object + metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{"not a SELService"}) + assert.NotNil(t, err) + assert.Empty(t, metadata.SuccessfulProvider) + + // Test with a slice containing a mock SELService + mockService := &mockSELService{name: "mock1"} + metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{mockService}) + assert.Nil(t, err) + assert.Equal(t, mockService.name, metadata.SuccessfulProvider) +} diff --git a/providers/ipmitool/ipmitool_test.go b/providers/ipmitool/ipmitool_test.go index ffe8b7bb..324d8b1e 100644 --- a/providers/ipmitool/ipmitool_test.go +++ b/providers/ipmitool/ipmitool_test.go @@ -106,3 +106,21 @@ func TestBMCReset(t *testing.T) { t.Log(state) t.Fatal() } + +func TestSELClear(t *testing.T) { + t.Skip("need real ipmi server") + host := "127.0.0.1" + port := "623" + user := "ADMIN" + pass := "ADMIN" + i, err := New(host, user, pass, WithPort(port), WithLogger(logging.DefaultLogger())) + if err != nil { + t.Fatal(err) + } + err = i.ClearSEL(context.Background()) + if err != nil { + t.Fatal(err) + } + t.Log("SEL cleared") + t.Fatal() +} From 38f6d5e76cd67bd8bbea11b944b95fbc2f54d346 Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Mon, 18 Sep 2023 13:05:41 -0700 Subject: [PATCH 4/6] added feature var for selclear --- providers/ipmitool/ipmitool.go | 1 + providers/providers.go | 2 ++ providers/redfish/redfish.go | 1 + 3 files changed, 4 insertions(+) diff --git a/providers/ipmitool/ipmitool.go b/providers/ipmitool/ipmitool.go index 2cd17b7d..bf929ca2 100644 --- a/providers/ipmitool/ipmitool.go +++ b/providers/ipmitool/ipmitool.go @@ -27,6 +27,7 @@ var ( providers.FeatureUserRead, providers.FeatureBmcReset, providers.FeatureBootDeviceSet, + providers.FeatureSELClear, } ) diff --git a/providers/providers.go b/providers/providers.go index 64c587a4..45de269c 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -33,4 +33,6 @@ const ( FeaturePostCodeRead registrar.Feature = "postcoderead" // FeatureScreenshot means an implementation that returns a screenshot of the video. FeatureScreenshot registrar.Feature = "screenshot" + // FeatureSELClear means an implementation that clears the BMC SEL + FeatureSELClear registrar.Feature = "selclear" ) diff --git a/providers/redfish/redfish.go b/providers/redfish/redfish.go index 93bd6cec..c6d523b6 100644 --- a/providers/redfish/redfish.go +++ b/providers/redfish/redfish.go @@ -37,6 +37,7 @@ var ( providers.FeatureFirmwareInstall, providers.FeatureFirmwareInstallStatus, providers.FeatureBmcReset, + providers.FeatureSELClear, } ) From 3cca54a6eb2b7d010c3b97a38dbddb47f95300de Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Mon, 18 Sep 2023 15:47:00 -0700 Subject: [PATCH 5/6] added example --- examples/sel/main.go | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/sel/main.go diff --git a/examples/sel/main.go b/examples/sel/main.go new file mode 100644 index 00000000..803d38ff --- /dev/null +++ b/examples/sel/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "context" + "crypto/x509" + "flag" + "io/ioutil" + "time" + + "github.com/bmc-toolbox/bmclib/v2" + "github.com/bmc-toolbox/bmclib/v2/providers" + "github.com/bombsimon/logrusr/v2" + "github.com/sirupsen/logrus" +) + +func main() { + user := flag.String("user", "", "Username to login with") + pass := flag.String("password", "", "Username to login with") + host := flag.String("host", "", "BMC hostname to connect to") + withSecureTLS := flag.Bool("secure-tls", false, "Enable secure TLS") + certPoolFile := flag.String("cert-pool", "", "Path to an file containing x509 CAs. An empty string uses the system CAs. Only takes effect when --secure-tls=true") + flag.Parse() + + l := logrus.New() + l.Level = logrus.DebugLevel + logger := logrusr.New(l) + + if *host == "" || *user == "" || *pass == "" { + l.Fatal("required host/user/pass parameters not defined") + } + + clientOpts := []bmclib.Option{ + bmclib.WithLogger(logger), + bmclib.WithRedfishUseBasicAuth(true), + } + + if *withSecureTLS { + var pool *x509.CertPool + if *certPoolFile != "" { + pool = x509.NewCertPool() + data, err := ioutil.ReadFile(*certPoolFile) + if err != nil { + l.Fatal(err) + } + pool.AppendCertsFromPEM(data) + } + // a nil pool uses the system certs + clientOpts = append(clientOpts, bmclib.WithSecureTLS(pool)) + } + + cl := bmclib.NewClient(*host, *user, *pass, clientOpts...) + cl.Registry.Drivers = cl.Registry.Supports(providers.FeatureSELClear) + + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + + err := cl.Open(ctx) + if err != nil { + l.WithError(err).Fatal(err, "BMC login failed") + } + defer cl.Close(ctx) + + err = cl.ClearSEL(ctx) + if err != nil { + l.WithError(err).Error() + } + l.Info("SEL cleared") +} From 3bfa968a50eaf6b80361aa82a854ae7288b13c1f Mon Sep 17 00:00:00 2001 From: Matthew Burns Date: Tue, 19 Sep 2023 10:03:33 -0700 Subject: [PATCH 6/6] addressed feedback: renamed all the things to be clearer, fixed example --- bmc/sel.go | 36 ++++++++++++++--------------- bmc/sel_test.go | 34 +++++++++++++-------------- client.go | 4 ++-- examples/sel/main.go | 8 +++---- internal/ipmi/ipmi.go | 4 ++-- internal/redfishwrapper/sel.go | 4 ++-- providers/ipmitool/ipmitool.go | 6 ++--- providers/ipmitool/ipmitool_test.go | 6 ++--- providers/providers.go | 4 ++-- providers/redfish/redfish.go | 2 +- providers/redfish/sel.go | 4 ++-- 11 files changed, 56 insertions(+), 56 deletions(-) diff --git a/bmc/sel.go b/bmc/sel.go index 584750da..25c6cfc7 100644 --- a/bmc/sel.go +++ b/bmc/sel.go @@ -9,21 +9,21 @@ import ( "github.com/pkg/errors" ) -// SELServices for various SEL related services -type SELService interface { - ClearSEL(ctx context.Context) (err error) +// System Event Log Services for related services +type SystemEventLog interface { + ClearSystemEventLog(ctx context.Context) (err error) } -type selProviders struct { - name string - selProvider SELService +type systemEventLogProviders struct { + name string + systemEventLogProvider SystemEventLog } -func clearSEL(ctx context.Context, timeout time.Duration, s []selProviders) (metadata Metadata, err error) { +func clearSystemEventLog(ctx context.Context, timeout time.Duration, s []systemEventLogProviders) (metadata Metadata, err error) { var metadataLocal Metadata for _, elem := range s { - if elem.selProvider == nil { + if elem.systemEventLogProvider == nil { continue } select { @@ -35,7 +35,7 @@ func clearSEL(ctx context.Context, timeout time.Duration, s []selProviders) (met metadataLocal.ProvidersAttempted = append(metadataLocal.ProvidersAttempted, elem.name) ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - selErr := elem.selProvider.ClearSEL(ctx) + selErr := elem.systemEventLogProvider.ClearSystemEventLog(ctx) if selErr != nil { err = multierror.Append(err, errors.WithMessagef(selErr, "provider: %v", elem.name)) continue @@ -46,24 +46,24 @@ func clearSEL(ctx context.Context, timeout time.Duration, s []selProviders) (met } - return metadataLocal, multierror.Append(err, errors.New("failed to reset SEL")) + return metadataLocal, multierror.Append(err, errors.New("failed to reset System Event Log")) } -func ClearSELFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (metadata Metadata, err error) { - selServices := make([]selProviders, 0) +func ClearSystemEventLogFromInterfaces(ctx context.Context, timeout time.Duration, generic []interface{}) (metadata Metadata, err error) { + selServices := make([]systemEventLogProviders, 0) for _, elem := range generic { - temp := selProviders{name: getProviderName(elem)} + temp := systemEventLogProviders{name: getProviderName(elem)} switch p := elem.(type) { - case SELService: - temp.selProvider = p + case SystemEventLog: + temp.systemEventLogProvider = p selServices = append(selServices, temp) default: - e := fmt.Sprintf("not a SELService implementation: %T", p) + e := fmt.Sprintf("not a SystemEventLog service implementation: %T", p) err = multierror.Append(err, errors.New(e)) } } if len(selServices) == 0 { - return metadata, multierror.Append(err, errors.New("no SelService implementations found")) + return metadata, multierror.Append(err, errors.New("no SystemEventLog implementations found")) } - return clearSEL(ctx, timeout, selServices) + return clearSystemEventLog(ctx, timeout, selServices) } diff --git a/bmc/sel_test.go b/bmc/sel_test.go index 14f3a96a..88b10d13 100644 --- a/bmc/sel_test.go +++ b/bmc/sel_test.go @@ -9,53 +9,53 @@ import ( "github.com/stretchr/testify/assert" ) -type mockSELService struct { +type mockSystemEventLogService struct { name string err error } -func (m *mockSELService) ClearSEL(ctx context.Context) error { +func (m *mockSystemEventLogService) ClearSystemEventLog(ctx context.Context) error { return m.err } -func (m *mockSELService) Name() string { +func (m *mockSystemEventLogService) Name() string { return m.name } -func TestClearSEL(t *testing.T) { +func TestClearSystemEventLog(t *testing.T) { ctx := context.Background() timeout := 1 * time.Second - // Test with a mock SELService that returns nil - mockService := &mockSELService{name: "mock1", err: nil} - metadata, err := clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}}) + // Test with a mock SystemEventLogService that returns nil + mockService := &mockSystemEventLogService{name: "mock1", err: nil} + metadata, err := clearSystemEventLog(ctx, timeout, []systemEventLogProviders{{name: mockService.name, systemEventLogProvider: mockService}}) assert.Nil(t, err) assert.Equal(t, mockService.name, metadata.SuccessfulProvider) - // Test with a mock SELService that returns an error - mockService = &mockSELService{name: "mock2", err: errors.New("mock error")} - metadata, err = clearSEL(ctx, timeout, []selProviders{{name: mockService.name, selProvider: mockService}}) + // Test with a mock SystemEventLogService that returns an error + mockService = &mockSystemEventLogService{name: "mock2", err: errors.New("mock error")} + metadata, err = clearSystemEventLog(ctx, timeout, []systemEventLogProviders{{name: mockService.name, systemEventLogProvider: mockService}}) assert.NotNil(t, err) assert.NotEqual(t, mockService.name, metadata.SuccessfulProvider) } -func TestClearSELFromInterfaces(t *testing.T) { +func TestClearSystemEventLogFromInterfaces(t *testing.T) { ctx := context.Background() timeout := 1 * time.Second // Test with an empty slice - metadata, err := ClearSELFromInterfaces(ctx, timeout, []interface{}{}) + metadata, err := ClearSystemEventLogFromInterfaces(ctx, timeout, []interface{}{}) assert.NotNil(t, err) assert.Empty(t, metadata.SuccessfulProvider) - // Test with a slice containing a non-SELService object - metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{"not a SELService"}) + // Test with a slice containing a non-SystemEventLog object + metadata, err = ClearSystemEventLogFromInterfaces(ctx, timeout, []interface{}{"not a SystemEventLog Service"}) assert.NotNil(t, err) assert.Empty(t, metadata.SuccessfulProvider) - // Test with a slice containing a mock SELService - mockService := &mockSELService{name: "mock1"} - metadata, err = ClearSELFromInterfaces(ctx, timeout, []interface{}{mockService}) + // Test with a slice containing a mock SystemEventLogService that returns nil + mockService := &mockSystemEventLogService{name: "mock1"} + metadata, err = ClearSystemEventLogFromInterfaces(ctx, timeout, []interface{}{mockService}) assert.Nil(t, err) assert.Equal(t, mockService.name, metadata.SuccessfulProvider) } diff --git a/client.go b/client.go index a704dc7c..437a919d 100644 --- a/client.go +++ b/client.go @@ -406,8 +406,8 @@ func (c *Client) Screenshot(ctx context.Context) (image []byte, fileType string, return image, fileType, err } -func (c *Client) ClearSEL(ctx context.Context) (err error) { - metadata, err := bmc.ClearSELFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces()) +func (c *Client) ClearSystemEventLog(ctx context.Context) (err error) { + metadata, err := bmc.ClearSystemEventLogFromInterfaces(ctx, c.perProviderTimeout(ctx), c.registry().GetDriverInterfaces()) c.setMetadata(metadata) return err } diff --git a/examples/sel/main.go b/examples/sel/main.go index 803d38ff..114d6496 100644 --- a/examples/sel/main.go +++ b/examples/sel/main.go @@ -49,7 +49,7 @@ func main() { } cl := bmclib.NewClient(*host, *user, *pass, clientOpts...) - cl.Registry.Drivers = cl.Registry.Supports(providers.FeatureSELClear) + cl.Registry.Drivers = cl.Registry.Supports(providers.FeatureClearSystemEventLog) ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() @@ -60,9 +60,9 @@ func main() { } defer cl.Close(ctx) - err = cl.ClearSEL(ctx) + err = cl.ClearSystemEventLog(ctx) if err != nil { - l.WithError(err).Error() + l.WithError(err).Fatal(err, "failed to clear System Event Log") } - l.Info("SEL cleared") + l.Info("System Event Log cleared") } diff --git a/internal/ipmi/ipmi.go b/internal/ipmi/ipmi.go index c79ea089..5161b7dd 100644 --- a/internal/ipmi/ipmi.go +++ b/internal/ipmi/ipmi.go @@ -378,8 +378,8 @@ func (i *Ipmi) ReadUsers(ctx context.Context) (users []map[string]string, err er return users, err } -// Clear SEL clears the SEL -func (i *Ipmi) ClearSEL(ctx context.Context) (err error) { +// ClearSystemEventLog clears the system event log +func (i *Ipmi) ClearSystemEventLog(ctx context.Context) (err error) { _, err = i.run(ctx, []string{"sel", "clear"}) return err } diff --git a/internal/redfishwrapper/sel.go b/internal/redfishwrapper/sel.go index 099abd31..78798735 100644 --- a/internal/redfishwrapper/sel.go +++ b/internal/redfishwrapper/sel.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" ) -// Clear SEL clears all of the LogServices logs -func (c *Client) ClearSEL(ctx context.Context) (err error) { +// ClearSystemEventLog clears all of the LogServices logs +func (c *Client) ClearSystemEventLog(ctx context.Context) (err error) { if err := c.SessionActive(); err != nil { return errors.Wrap(bmclibErrs.ErrNotAuthenticated, err.Error()) } diff --git a/providers/ipmitool/ipmitool.go b/providers/ipmitool/ipmitool.go index bf929ca2..90aedbd4 100644 --- a/providers/ipmitool/ipmitool.go +++ b/providers/ipmitool/ipmitool.go @@ -27,7 +27,7 @@ var ( providers.FeatureUserRead, providers.FeatureBmcReset, providers.FeatureBootDeviceSet, - providers.FeatureSELClear, + providers.FeatureClearSystemEventLog, } ) @@ -182,6 +182,6 @@ func (c *Conn) PowerSet(ctx context.Context, state string) (ok bool, err error) return ok, err } -func (c *Conn) ClearSEL(ctx context.Context) (err error) { - return c.ipmitool.ClearSEL(ctx) +func (c *Conn) ClearSystemEventLog(ctx context.Context) (err error) { + return c.ipmitool.ClearSystemEventLog(ctx) } diff --git a/providers/ipmitool/ipmitool_test.go b/providers/ipmitool/ipmitool_test.go index 324d8b1e..0e9589c2 100644 --- a/providers/ipmitool/ipmitool_test.go +++ b/providers/ipmitool/ipmitool_test.go @@ -107,7 +107,7 @@ func TestBMCReset(t *testing.T) { t.Fatal() } -func TestSELClear(t *testing.T) { +func TestSystemEventLogClear(t *testing.T) { t.Skip("need real ipmi server") host := "127.0.0.1" port := "623" @@ -117,10 +117,10 @@ func TestSELClear(t *testing.T) { if err != nil { t.Fatal(err) } - err = i.ClearSEL(context.Background()) + err = i.ClearSystemEventLog(context.Background()) if err != nil { t.Fatal(err) } - t.Log("SEL cleared") + t.Log("System Event Log cleared") t.Fatal() } diff --git a/providers/providers.go b/providers/providers.go index 45de269c..28ffd83a 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -33,6 +33,6 @@ const ( FeaturePostCodeRead registrar.Feature = "postcoderead" // FeatureScreenshot means an implementation that returns a screenshot of the video. FeatureScreenshot registrar.Feature = "screenshot" - // FeatureSELClear means an implementation that clears the BMC SEL - FeatureSELClear registrar.Feature = "selclear" + // FeatureClearSystemEventLog means an implementation that clears the BMC System Event Log (SEL) + FeatureClearSystemEventLog registrar.Feature = "clearsystemeventlog" ) diff --git a/providers/redfish/redfish.go b/providers/redfish/redfish.go index c6d523b6..172e71a4 100644 --- a/providers/redfish/redfish.go +++ b/providers/redfish/redfish.go @@ -37,7 +37,7 @@ var ( providers.FeatureFirmwareInstall, providers.FeatureFirmwareInstallStatus, providers.FeatureBmcReset, - providers.FeatureSELClear, + providers.FeatureClearSystemEventLog, } ) diff --git a/providers/redfish/sel.go b/providers/redfish/sel.go index 7501712d..9d516243 100644 --- a/providers/redfish/sel.go +++ b/providers/redfish/sel.go @@ -2,6 +2,6 @@ package redfish import "context" -func (c *Conn) ClearSEL(ctx context.Context) (err error) { - return c.redfishwrapper.ClearSEL(ctx) +func (c *Conn) ClearSystemEventLog(ctx context.Context) (err error) { + return c.redfishwrapper.ClearSystemEventLog(ctx) }