Skip to content

Commit

Permalink
Fix references in ThermalSubsystem
Browse files Browse the repository at this point in the history
Some linked objects were not defined right. Fixed that and added unit
test coverage based on a real system.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis committed Apr 19, 2024
1 parent 80de948 commit 6d550fa
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 123 deletions.
4 changes: 2 additions & 2 deletions redfish/heatermetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func GetHeaterMetrics(c common.Client, uri string) (*HeaterMetrics, error) {
return &heatermetrics, nil
}

// ListReferencedHeaterMetricss gets the collection of HeaterMetrics from
// ListReferencedHeaterMetrics gets the collection of HeaterMetrics from
// a provided reference.
func ListReferencedHeaterMetricss(c common.Client, link string) ([]*HeaterMetrics, error) {
func ListReferencedHeaterMetrics(c common.Client, link string) ([]*HeaterMetrics, error) {
var result []*HeaterMetrics
if link == "" {
return result, nil
Expand Down
2 changes: 1 addition & 1 deletion redfish/thermalmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func GetThermalMetrics(c common.Client, uri string) (*ThermalMetrics, error) {

// ListReferencedThermalMetricss gets the collection of ThermalMetrics from
// a provided reference.
func ListReferencedThermalMetricss(c common.Client, link string) ([]*ThermalMetrics, error) {
func ListReferencedThermalMetrics(c common.Client, link string) ([]*ThermalMetrics, error) {
var result []*ThermalMetrics
if link == "" {
return result, nil
Expand Down
147 changes: 27 additions & 120 deletions redfish/thermalsubsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@ type ThermalSubsystem struct {
CoolantConnectorRedundancy []RedundantGroup
// CoolantConnectors shall contain a link to a resource collection of type CoolantConnectorCollection that contains
// the coolant connectors for this equipment.
coolantConnectors []string
coolantConnectors string
// Description provides a description of this resource.
Description string
// FanRedundancy shall contain redundancy information for the groups of fans in this subsystem.
FanRedundancy []RedundantGroup
// Fans shall contain a link to a resource collection of type FanCollection.
fans []string
fans string
// Heaters shall contain a link to a resource collection of type HeaterCollection.
heaters []string
heaters string
// LeakDetection shall contain a link to a resource collection of type LeakDetection.
leakDetection []string
leakDetection string
// Oem shall contain the OEM extensions. All values for properties that this object contains shall conform to the
// Redfish Specification-described requirements.
OEM json.RawMessage `json:"Oem"`
// Pumps shall contain a link to a resource collection of type PumpCollection that contains details for the pumps
// included in this equipment.
pumps []string
pumps string
// Status shall contain any status or health properties of the resource.
Status common.Status
// ThermalMetrics shall contain a link to a resource collection of type ThermalMetrics.
thermalMetrics []string
thermalMetrics string
}

// UnmarshalJSON unmarshals a ThermalSubsystem object from the raw JSON.
func (thermalsubsystem *ThermalSubsystem) UnmarshalJSON(b []byte) error {
type temp ThermalSubsystem
var t struct {
temp
CoolantConnectors common.LinksCollection
Fans common.LinksCollection
Heaters common.LinksCollection
LeakDetection common.LinksCollection
Pumps common.LinksCollection
ThermalMetrics common.LinksCollection
CoolantConnectors common.Link
Fans common.Link
Heaters common.Link
LeakDetection common.Link
Pumps common.Link
ThermalMetrics common.Link
}

err := json.Unmarshal(b, &t)
Expand All @@ -68,140 +68,47 @@ func (thermalsubsystem *ThermalSubsystem) UnmarshalJSON(b []byte) error {
*thermalsubsystem = ThermalSubsystem(t.temp)

// Extract the links to other entities for later
thermalsubsystem.coolantConnectors = t.CoolantConnectors.ToStrings()
thermalsubsystem.fans = t.Fans.ToStrings()
thermalsubsystem.heaters = t.Heaters.ToStrings()
thermalsubsystem.leakDetection = t.LeakDetection.ToStrings()
thermalsubsystem.pumps = t.Pumps.ToStrings()
thermalsubsystem.thermalMetrics = t.ThermalMetrics.ToStrings()
thermalsubsystem.coolantConnectors = t.CoolantConnectors.String()
thermalsubsystem.fans = t.Fans.String()
thermalsubsystem.heaters = t.Heaters.String()
thermalsubsystem.leakDetection = t.LeakDetection.String()
thermalsubsystem.pumps = t.Pumps.String()
thermalsubsystem.thermalMetrics = t.ThermalMetrics.String()

return nil
}

// CoolantConnectors gets the coolant connectors for this equipment.
func (thermalsubsystem *ThermalSubsystem) CoolantConnectors() ([]*CoolantConnector, error) {
var result []*CoolantConnector

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.coolantConnectors {
item, err := GetCoolantConnector(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

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

return result, collectionError
return ListReferencedCoolantConnectors(thermalsubsystem.GetClient(), thermalsubsystem.coolantConnectors)
}

// Fans gets the fans for this equipment.
func (thermalsubsystem *ThermalSubsystem) Fans() ([]*Fan, error) {
var result []*Fan

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.fans {
item, err := GetFan(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

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

return result, collectionError
return ListReferencedFans(thermalsubsystem.GetClient(), thermalsubsystem.fans)
}

// Heaters gets the heaters within this subsystem.
func (thermalsubsystem *ThermalSubsystem) Heaters() ([]*Heater, error) {
var result []*Heater

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.heaters {
item, err := GetHeater(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

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

return result, collectionError
return ListReferencedHeaters(thermalsubsystem.GetClient(), thermalsubsystem.heaters)
}

// LeakDetection gets the leak detection system within this chassis.
func (thermalsubsystem *ThermalSubsystem) LeakDetection() ([]*LeakDetection, error) {
var result []*LeakDetection

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.leakDetection {
item, err := GetLeakDetection(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

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

return result, collectionError
return ListReferencedLeakDetections(thermalsubsystem.GetClient(), thermalsubsystem.leakDetection)
}

// Pumps gets the pumps for this equipment.
func (thermalsubsystem *ThermalSubsystem) Pumps() ([]*Pump, error) {
var result []*Pump

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.pumps {
item, err := GetPump(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

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

return result, collectionError
return ListReferencedPumps(thermalsubsystem.GetClient(), thermalsubsystem.pumps)
}

// ThermalMetrics gets the summary of thermal metrics for this subsystem.
func (thermalsubsystem *ThermalSubsystem) ThermalMetrics() ([]*ThermalMetrics, error) {
var result []*ThermalMetrics

collectionError := common.NewCollectionError()
for _, uri := range thermalsubsystem.thermalMetrics {
item, err := GetThermalMetrics(thermalsubsystem.GetClient(), uri)
if err != nil {
collectionError.Failures[uri] = err
} else {
result = append(result, item)
}
}

if collectionError.Empty() {
return result, nil
func (thermalsubsystem *ThermalSubsystem) ThermalMetrics() (*ThermalMetrics, error) {
if thermalsubsystem.thermalMetrics == "" {
return nil, nil
}

return result, collectionError
return GetThermalMetrics(thermalsubsystem.GetClient(), thermalsubsystem.thermalMetrics)
}

// GetThermalSubsystem will get a ThermalSubsystem instance from the service.
Expand Down
65 changes: 65 additions & 0 deletions redfish/thermalsubsystem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package redfish

import (
"encoding/json"
"strings"
"testing"
)

var thermalSubsystemBody = `{
"@odata.context": "/redfish/v1/$metadata#ThermalSubsystem.ThermalSubsystem",
"@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem",
"@odata.type": "#ThermalSubsystem.v1_2_0.ThermalSubsystem",
"Description": "Represents the properties of a Thermal Subsystem of the Chassis",
"Name": "Thermal Subsystem for Chassis",
"FanRedundancy": [
{
"RedundancyType": "NPlusM",
"MaxSupportedInGroup": null,
"MinNeededInGroup": null,
"RedundancyGroup": [],
"[email protected]": 0,
"Status": {
"State": "Enabled",
"Health": "OK"
}
}
],
"Fans": {
"@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/Fans"
},
"ThermalMetrics": {
"@odata.id": "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/ThermalMetrics"
},
"Status": {
"State": "Enabled",
"Health": "OK"
},
"Id": "ThermalSubsystem"
}`

// TestThermalSubsystem tests the parsing of ThermalSubsystem objects.
func TestThermalSubsystem(t *testing.T) {
var result ThermalSubsystem
err := json.NewDecoder(strings.NewReader(thermalSubsystemBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "ThermalSubsystem" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.Name != "Thermal Subsystem for Chassis" {
t.Errorf("Received invalid name: %s", result.Name)
}

if result.fans != "/redfish/v1/Chassis/System.Embedded.1/ThermalSubsystem/Fans" {
t.Errorf("Invalid fans link: %s", result.fans)
}
}

0 comments on commit 6d550fa

Please sign in to comment.