Skip to content
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
294 changes: 294 additions & 0 deletions redfish/internal/controller/http/v1/generated/server.gen.go

Large diffs are not rendered by default.

565 changes: 292 additions & 273 deletions redfish/internal/controller/http/v1/generated/spec.gen.go

Large diffs are not rendered by default.

428 changes: 415 additions & 13 deletions redfish/internal/controller/http/v1/generated/types.gen.go

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions redfish/internal/controller/http/v1/handler/systems_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelCompu
MethodNotAllowedError(c)
}

// PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent handles canceling SOL consent for a computer system.
// This is a stub implementation.
//
//nolint:revive // Method name is generated from OpenAPI spec and cannot be changed
func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent(c *gin.Context, computerSystemID string) {
if err := validateSystemID(computerSystemID); err != nil {
BadRequestError(c, fmt.Sprintf("Invalid system ID: %s", err.Error()))

return
}

MethodNotAllowedError(c)
}

// PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemGenerateRedirectionToken handles generating a redirection token for a computer system.
// This is a stub implementation.
//
Expand Down Expand Up @@ -145,6 +159,20 @@ func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelCompu
MethodNotAllowedError(c)
}

// PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent handles requesting SOL consent for a computer system.
// This is a stub implementation.
//
//nolint:revive // Method name is generated from OpenAPI spec and cannot be changed
func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent(c *gin.Context, computerSystemID string) {
if err := validateSystemID(computerSystemID); err != nil {
BadRequestError(c, fmt.Sprintf("Invalid system ID: %s", err.Error()))

return
}

MethodNotAllowedError(c)
}

// PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitKVMConsentCode handles submitting a KVM consent code for a computer system.
// This is a stub implementation.
//
Expand All @@ -158,3 +186,17 @@ func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelCompu

MethodNotAllowedError(c)
}

// PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode handles submitting a SOL consent code for a computer system.
// This is a stub implementation.
//
//nolint:revive // Method name is generated from OpenAPI spec and cannot be changed
func (s *RedfishServer) PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode(c *gin.Context, computerSystemID string) {
if err := validateSystemID(computerSystemID); err != nil {
BadRequestError(c, fmt.Sprintf("Invalid system ID: %s", err.Error()))

return
}

MethodNotAllowedError(c)
}
104 changes: 104 additions & 0 deletions redfish/internal/controller/http/v1/handler/systems_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,107 @@ func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmit

assert.Equal(t, http.StatusBadRequest, w.Code)
}

// Stub implementation tests for SOL actions

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent_Stub(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/"+testSystemID+"/Actions/Oem/IntelComputerSystem.CancelSolConsent", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: testSystemID}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent(ctx, testSystemID)

assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent_InvalidSystemID(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/../invalid/Actions/Oem/IntelComputerSystem.CancelSolConsent", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: "../invalid"}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemCancelSolConsent(ctx, "../invalid")

assert.Equal(t, http.StatusBadRequest, w.Code)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent_Stub(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/"+testSystemID+"/Actions/Oem/IntelComputerSystem.RequestSolConsent", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: testSystemID}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent(ctx, testSystemID)

assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent_InvalidSystemID(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/test%00null/Actions/Oem/IntelComputerSystem.RequestSolConsent", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: "test%00null"}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemRequestSolConsent(ctx, "test%00null")

assert.Equal(t, http.StatusBadRequest, w.Code)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode_Stub(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/"+testSystemID+"/Actions/Oem/IntelComputerSystem.SubmitSolConsentCode", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: testSystemID}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode(ctx, testSystemID)

assert.Equal(t, http.StatusMethodNotAllowed, w.Code)
}

func TestPostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode_InvalidSystemID(t *testing.T) {
t.Parallel()

repo := NewTestSystemsComputerSystemRepository()
server := setupSystemActionsTestServer(repo)

req := httptest.NewRequest(http.MethodPost, "/redfish/v1/Systems/<script>/Actions/Oem/IntelComputerSystem.SubmitSolConsentCode", http.NoBody)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = req
ctx.Params = gin.Params{{Key: "computerSystemId", Value: "<script>"}}

server.PostRedfishV1SystemsComputerSystemIdActionsOemIntelComputerSystemSubmitSolConsentCode(ctx, "<script>")

assert.Equal(t, http.StatusBadRequest, w.Code)
}
24 changes: 12 additions & 12 deletions redfish/internal/usecase/computer_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,29 +558,29 @@ func (uc *ComputerSystemUseCase) convertStateToGenerated(state string) *generate

switch state {
case StateEnabled:
stateEnum = generated.Enabled
stateEnum = generated.ResourceStateEnabled
case StateDisabled:
stateEnum = generated.Disabled
stateEnum = generated.ResourceStateDisabled
case StateStandbyOffline:
stateEnum = generated.StandbyOffline
stateEnum = generated.ResourceStateStandbyOffline
case StateStandbySpare:
stateEnum = generated.StandbySpare
stateEnum = generated.ResourceStateStandbySpare
case StateInTest:
stateEnum = generated.InTest
stateEnum = generated.ResourceStateInTest
case StateStarting:
stateEnum = generated.Starting
stateEnum = generated.ResourceStateStarting
case StateAbsent:
stateEnum = generated.Absent
stateEnum = generated.ResourceStateAbsent
case StateUnavailableOffline:
stateEnum = generated.UnavailableOffline
stateEnum = generated.ResourceStateUnavailableOffline
case StateDeferring:
stateEnum = generated.Deferring
stateEnum = generated.ResourceStateDeferring
case StateQuiesced:
stateEnum = generated.Quiesced
stateEnum = generated.ResourceStateQuiesced
case StateUpdating:
stateEnum = generated.Updating
stateEnum = generated.ResourceStateUpdating
case StateDegraded:
stateEnum = generated.Degraded
stateEnum = generated.ResourceStateDegraded
default:
return nil // Don't create state if unknown value
}
Expand Down
132 changes: 132 additions & 0 deletions redfish/internal/usecase/computer_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,135 @@ func TestGetComputerSystemGraphicalConsoleDropsUnsupportedConnectTypes(t *testin
t.Fatalf("expected unsupported connect types to be omitted, got %#v", result.GraphicalConsole.ConnectTypesSupported)
}
}

func TestConvertStateToGenerated(t *testing.T) {
t.Parallel()

tests := []struct {
name string
state string
wantNil bool
wantState generated.ResourceState
}{
{
name: "StateEnabled",
state: StateEnabled,
wantNil: false,
wantState: generated.ResourceStateEnabled,
},
{
name: "StateDisabled",
state: StateDisabled,
wantNil: false,
wantState: generated.ResourceStateDisabled,
},
{
name: "StateStandbyOffline",
state: StateStandbyOffline,
wantNil: false,
wantState: generated.ResourceStateStandbyOffline,
},
{
name: "StateStandbySpare",
state: StateStandbySpare,
wantNil: false,
wantState: generated.ResourceStateStandbySpare,
},
{
name: "StateInTest",
state: StateInTest,
wantNil: false,
wantState: generated.ResourceStateInTest,
},
{
name: "StateStarting",
state: StateStarting,
wantNil: false,
wantState: generated.ResourceStateStarting,
},
{
name: "StateAbsent",
state: StateAbsent,
wantNil: false,
wantState: generated.ResourceStateAbsent,
},
{
name: "StateUnavailableOffline",
state: StateUnavailableOffline,
wantNil: false,
wantState: generated.ResourceStateUnavailableOffline,
},
{
name: "StateDeferring",
state: StateDeferring,
wantNil: false,
wantState: generated.ResourceStateDeferring,
},
{
name: "StateQuiesced",
state: StateQuiesced,
wantNil: false,
wantState: generated.ResourceStateQuiesced,
},
{
name: "StateUpdating",
state: StateUpdating,
wantNil: false,
wantState: generated.ResourceStateUpdating,
},
{
name: "StateDegraded",
state: StateDegraded,
wantNil: false,
wantState: generated.ResourceStateDegraded,
},
{
name: "UnknownState",
state: "UnknownState",
wantNil: true,
},
{
name: "EmptyState",
state: "",
wantNil: true,
},
}

uc := &ComputerSystemUseCase{}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
validateConvertStateResult(t, uc, tt.state, tt.wantNil, tt.wantState)
})
}
}

// validateConvertStateResult validates the result of convertStateToGenerated.
func validateConvertStateResult(t *testing.T, uc *ComputerSystemUseCase, state string, wantNil bool, wantState generated.ResourceState) {
t.Helper()

result := uc.convertStateToGenerated(state)

if wantNil {
if result != nil {
t.Fatalf("convertStateToGenerated(%q) expected nil, got %v", state, result)
}

return
}

if result == nil {
t.Fatalf("convertStateToGenerated(%q) expected non-nil result", state)
}

got, err := result.AsResourceState()
if err != nil {
t.Fatalf("Failed to convert result back to ResourceState: %v", err)
}

if got != wantState {
t.Errorf("convertStateToGenerated(%q) got %v, want %v", state, got, wantState)
}
}
Loading
Loading