Skip to content

Commit

Permalink
expose manager's Links object to allow caller to further process
Browse files Browse the repository at this point in the history
Signed-off-by: Leslie Qi Wang <[email protected]>
  • Loading branch information
leslie-qiwa authored and leslie-wang committed Oct 20, 2020
1 parent 42c14ec commit e74245f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
11 changes: 10 additions & 1 deletion common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ func (e *Entity) Update(originalEntity reflect.Value, currentEntity reflect.Valu
fieldName := originalEntity.Type().Field(i).Name
originalValue := originalEntity.Field(i).Interface()
currentValue := currentEntity.Field(i).Interface()
if originalValue != currentValue {
if originalValue == nil && currentValue == nil {
continue
} else if originalValue == nil {
payload[fieldName] = currentValue
} else if reflect.TypeOf(originalValue).Kind() != reflect.Map {
if originalValue != currentValue {
// TODO: Handle JSON name being different than field name
payload[fieldName] = currentValue
}
} else if !reflect.DeepEqual(originalValue, currentValue) {
// TODO: Handle JSON name being different than field name
payload[fieldName] = currentValue
}
Expand Down
8 changes: 8 additions & 0 deletions redfish/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ type Manager struct {
// ManagerNetworkProtocol which represents the network services for this
// manager.
networkProtocol string
// OEMData are all OEM data under top level manager section
OEMData map[string]interface{}
// OEMLinks are all OEM data under link section
OEMLinks map[string]interface{}
// PartNumber shall contain a part number assigned by the organization that
// is responsible for producing or manufacturing the manager.
PartNumber string
Expand Down Expand Up @@ -304,6 +308,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error {
ManagerForSwitches common.Links
ManagerForSwitchesCount int `json:"[email protected]"`
ManagerInChassis common.Link
OEM map[string]interface{} `json:"Oem"`
}
var t struct {
temp
Expand All @@ -315,6 +320,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error {
VirtualMedia common.Link
Links linkReference
Actions actions
OEM map[string]interface{} `json:"Oem"`
}

err := json.Unmarshal(b, &t)
Expand All @@ -327,6 +333,8 @@ func (manager *Manager) UnmarshalJSON(b []byte) error {
manager.ethernetInterfaces = string(t.EthernetInterfaces)
manager.logServices = string(t.LogServices)
manager.networkProtocol = string(t.NetworkProtocol)
manager.OEMData = t.OEM
manager.OEMLinks = t.Links.OEM
manager.remoteAccountService = string(t.RemoteAccountService)
manager.serialInterfaces = string(t.SerialInterfaces)
manager.virtualMedia = string(t.VirtualMedia)
Expand Down
64 changes: 58 additions & 6 deletions redfish/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,46 @@ package redfish

import (
"encoding/json"
"github.com/stmcginnis/gofish/common"
"reflect"
"strings"
"testing"

"github.com/stmcginnis/gofish/common"
)

var oemLinksBody = `
{
"Dell": {
"DellAttributes": [
{
"@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/Attributes"
},
{
"@odata.id": "/redfish/v1/Managers/System.Embedded.1/Attributes"
},
{
"@odata.id": "/redfish/v1/Managers/LifecycleController.Embedded.1/Attributes"
}
],
"[email protected]": 3,
"DellTimeService": {
"@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/DellTimeService"
}
}
}
`
var oemDataBody = `
{
"Dell": {
"DelliDRACCard": {
"@odata.context": "/redfish/v1/$metadata#DelliDRACCard.DelliDRACCard",
"@odata.id": "/redfish/v1/Managers/iDRAC.Embedded.1/DelliDRACCard/iDRAC.Embedded.1-1_0x23_IDRACinfo",
"@odata.type": "#DelliDRACCard.v1_1_0.DelliDRACCard",
"IPMIVersion": "2.0",
"URLString": "https://10.5.1.83:443"
}
}
}
`
var managerBody = `{
"@Redfish.Copyright": "Copyright 2014-2019 DMTF. All rights reserved.",
"@odata.context": "/redfish/v1/$metadata#Manager.Manager",
Expand Down Expand Up @@ -92,8 +126,10 @@ var managerBody = `{
],
"ManagerInChassis": {
"@odata.id": "/redfish/v1/Chassis/Chassis-1"
}
},
},
"Oem":
` + oemLinksBody +
` },
"Actions": {
"#Manager.Reset": {
"target": "/redfish/v1/Managers/BMC-1/Actions/Manager.Reset",
Expand All @@ -102,8 +138,10 @@ var managerBody = `{
"GracefulRestart"
]
}
}
}`
},
"Oem":
` + oemDataBody +
` }`

// TestManager tests the parsing of Manager objects.
func TestManager(t *testing.T) {
Expand Down Expand Up @@ -146,6 +184,20 @@ func TestManager(t *testing.T) {
if result.resetTarget != "/redfish/v1/Managers/BMC-1/Actions/Manager.Reset" {
t.Errorf("Invalid Reset target: %s", result.resetTarget)
}

var expectedOEM map[string]interface{}
if err := json.Unmarshal([]byte(oemLinksBody), &expectedOEM); err != nil {
t.Errorf("Failed to unmarshall link body: %v", err)
}
if !reflect.DeepEqual(result.OEMLinks, expectedOEM) {
t.Errorf("Invalid OEM Links: %+v", result.OEMLinks)
}
if err := json.Unmarshal([]byte(oemDataBody), &expectedOEM); err != nil {
t.Errorf("Failed to unmarshall data body: %v", err)
}
if !reflect.DeepEqual(result.OEMData, expectedOEM) {
t.Errorf("Invalid OEM Data: %+v", result.OEMData)
}
}

// TestManagerUpdate tests the Update call.
Expand Down

0 comments on commit e74245f

Please sign in to comment.