Skip to content

Commit

Permalink
Fix ComputerSystem.ManagedBy access
Browse files Browse the repository at this point in the history
This is an array of links to Managers. We had been just collecting the
strings for the URIs, but to make this consistent with how other related
objects are handled this makes the objects themselves accessible by a
method call.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis committed May 1, 2024
1 parent 2d5d848 commit 95ec097
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
28 changes: 23 additions & 5 deletions redfish/computersystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,7 @@ type ComputerSystem struct {
// settingsApplyTimes is a set of allowed settings update apply times. If none
// are specified, then the system does not provide that information.
settingsApplyTimes []common.ApplyTime
// ManagedBy An array of references to the Managers responsible for this system.
// This is temporary until a proper method can be implemented to actually
// retrieve those objects directly.
ManagedBy []string
managedBy []string

// addResourceBlockTarget is the internal URL for the AddResourceBlock action.
addResourceBlockTarget string
Expand Down Expand Up @@ -1009,7 +1006,7 @@ func (computersystem *ComputerSystem) UnmarshalJSON(b []byte) error {
computersystem.setDefaultBootOrderTarget = t.Actions.SetDefaultBootOrder.Target

computersystem.chassis = t.Links.Chassis.ToStrings()
computersystem.ManagedBy = t.Links.ManagedBy.ToStrings()
computersystem.managedBy = t.Links.ManagedBy.ToStrings()
computersystem.settingsApplyTimes = t.Settings.SupportedApplyTimes

// Some implementations use a @Redfish.Settings object to direct settings updates to a
Expand Down Expand Up @@ -1170,6 +1167,27 @@ func (computersystem *ComputerSystem) LogServices() ([]*LogService, error) {
return ListReferencedLogServices(computersystem.GetClient(), computersystem.logServices)
}

// ManagedBy gets all Managers for this system.
func (computersystem *ComputerSystem) ManagedBy() ([]*Manager, error) {
var result []*Manager

collectionError := common.NewCollectionError()
for _, uri := range computersystem.managedBy {
manager, err := GetManager(computersystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, manager)
}
}

if collectionError.Empty() {
return result, nil
}

return result, collectionError
}

// Memory gets this system's memory.
func (computersystem *ComputerSystem) Memory() ([]*Memory, error) {
return ListReferencedMemorys(computersystem.GetClient(), computersystem.memory)
Expand Down
8 changes: 4 additions & 4 deletions redfish/computersystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ func TestComputerSystem(t *testing.T) { //nolint
t.Errorf("Invalid allowable reset actions, expected 6, got %d",
len(result.SupportedResetTypes))
}
if len(result.ManagedBy) != 1 {
t.Errorf("Received invalid number of ManagedBy: %d", len(result.ManagedBy))
if len(result.managedBy) != 1 {
t.Errorf("Received invalid number of ManagedBy: %d", len(result.managedBy))
}
if result.ManagedBy[0] != "/redfish/v1/Managers/BMC-1" {
t.Errorf("Received invalid Managers reference: %s", result.ManagedBy[0])
if result.managedBy[0] != "/redfish/v1/Managers/BMC-1" {
t.Errorf("Received invalid Managers reference: %s", result.managedBy[0])
}
}

Expand Down

0 comments on commit 95ec097

Please sign in to comment.