Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

providers/supermicro/supermicro.go: Initialize sum 'client' during serviceclient init #402

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions providers/supermicro/firmware_bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func Test_setComponentUpdateMisc(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down Expand Up @@ -169,7 +171,9 @@ func Test_setBIOSFirmwareInstallMode(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down
23 changes: 19 additions & 4 deletions providers/supermicro/supermicro.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,21 @@ func NewClient(host, user, pass string, log logr.Logger, opts ...Option) *Client
opt(defaultConfig)
}

serviceClient := newBmcServiceClient(
serviceClient, err := newBmcServiceClient(
host,
defaultConfig.Port,
user,
pass,
httpclient.Build(defaultConfig.httpClientSetupFuncs...),
)

// We probably want to treat this as a fatal error and/or pass the error back to the caller
// I did not want to chase that thread atm, so we intentionally return nil here if
// newBmcServiceClient returns an error.
if err != nil {
return nil
splaspood marked this conversation as resolved.
Show resolved Hide resolved
}

return &Client{
serviceClient: serviceClient,
log: log,
Expand Down Expand Up @@ -443,12 +450,20 @@ type serviceClient struct {
sum *sum.Sum
}

func newBmcServiceClient(host, port, user, pass string, client *http.Client) *serviceClient {
func newBmcServiceClient(host, port, user, pass string, client *http.Client) (*serviceClient, error) {
sc := &serviceClient{host: host, port: port, user: user, pass: pass, client: client}

if !strings.HasPrefix(host, "https://") && !strings.HasPrefix(host, "http://") {
host = "https://" + host
sc.host = "https://" + host
}

s, err := sum.New(host, user, pass)
if err != nil {
return nil, err
}
sc.sum = s

return &serviceClient{host: host, port: port, user: user, pass: pass, client: client}
return sc, nil
}

func (c *serviceClient) setCsrfToken(t string) {
Expand Down
17 changes: 12 additions & 5 deletions providers/supermicro/x11_firmware_bmc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func TestX11SetBMCFirmwareInstallMode(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

client := &x11{serviceClient: serviceClient, log: logr.Discard()}

if err := client.setBMCFirmwareInstallMode(context.Background()); err != nil {
Expand Down Expand Up @@ -184,7 +186,8 @@ func TestX11UploadBMCFirmware(t *testing.T) {
defer os.Remove(binPath)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)
serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down Expand Up @@ -265,7 +268,8 @@ func TestX11VerifyBMCFirmwareVersion(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)
serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down Expand Up @@ -346,7 +350,8 @@ func TestX11InitiateBMCFirmwareInstall(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)
serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down Expand Up @@ -509,7 +514,9 @@ func TestX11StatusBMCFirmwareInstall(t *testing.T) {
t.Fatal(err)
}

serviceClient := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
serviceClient, err := newBmcServiceClient(parsedURL.Hostname(), parsedURL.Port(), "foo", "bar", httpclient.Build())
assert.Nil(t, err)

serviceClient.csrfToken = "foobar"
client := &x11{serviceClient: serviceClient, log: logr.Discard()}

Expand Down
Loading