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

added the ability to take networkDeviceFunctions, pcieDevices and networkPorts from Controller #301

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion redfish/eventdestination.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func sendCreateEventDestinationRequest(

resp, err := c.Post(uri, s)
if err != nil {
return
return err.Error(), err
}
defer resp.Body.Close()

Expand Down
105 changes: 89 additions & 16 deletions redfish/networkadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ type ControllerCapabilities struct {
}
}

// Controllers shall describe a network controller ASIC that makes up part of a
// Controller shall describe a network controller ASIC that makes up part of a
// NetworkAdapter.
type Controllers struct {
type Controller struct {
common.Entity
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned about changing the existing struct name in case someone is explicitly defining a variable type with it. But I think that is a low risk.

The bigger issue is Controller is not a top level API object, so it does not include the common.Entity properties. If you are seeing a system adding this, they may not be following the actual spec for the object.

https://redfish.dmtf.org/schemas/v1/NetworkAdapter.v1_10_0.json

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the unit tests. This still needs to be addressed though. Is that something you are able to do?


// ControllerCapabilities shall contain the capabilities of this controller.
ControllerCapabilities ControllerCapabilities
// FirmwarePackageVersion shall be the version number of the user-facing
Expand Down Expand Up @@ -109,15 +111,15 @@ type Controllers struct {
PCIeDevicesCount int
}

// UnmarshalJSON unmarshals a Controllers object from the raw JSON.
func (controllers *Controllers) UnmarshalJSON(b []byte) error {
type temp Controllers
// UnmarshalJSON unmarshals a Controller object from the raw JSON.
func (controller *Controller) UnmarshalJSON(b []byte) error {
type temp Controller
type links struct {
NetworkPorts common.Links
NetworkPortsCount int `json:"[email protected]"`
NetworkDeviceFunctions common.Links
NetworkDeviceFunctionsCount int `json:"[email protected]"`
PCIeDevice common.Link
PCIeDevices common.Links
PCIeDevicesCount int `json:"[email protected]"`
}

Expand All @@ -132,17 +134,80 @@ func (controllers *Controllers) UnmarshalJSON(b []byte) error {
}

// Extract the links to other entities for later
*controllers = Controllers(t.temp)
controllers.networkPorts = t.Links.NetworkPorts.ToStrings()
controllers.NetworkPortsCount = t.Links.NetworkPortsCount
controllers.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings()
controllers.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount
controllers.pcieDevices = t.Links.NetworkDeviceFunctions.ToStrings()
controllers.PCIeDevicesCount = t.Links.NetworkDeviceFunctionsCount
*controller = Controller(t.temp)
controller.networkPorts = t.Links.NetworkPorts.ToStrings()
controller.NetworkPortsCount = t.Links.NetworkPortsCount
controller.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings()
controller.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount
controller.pcieDevices = t.Links.PCIeDevices.ToStrings()
controller.PCIeDevicesCount = t.Links.NetworkDeviceFunctionsCount

return nil
}

// PCIeDevices gets all PCIeDevices for this controller.
func (controller *Controller) PCIeDevices() ([]*PCIeDevice, error) {
var result []*PCIeDevice

collectionError := common.NewCollectionError()
for _, pciedeviceLink := range controller.pcieDevices {
pciedevice, err := GetPCIeDevice(controller.GetClient(), pciedeviceLink)
if err != nil {
collectionError.Failures[pciedeviceLink] = err
} else {
result = append(result, pciedevice)
}
}

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

return result, collectionError
}

// NetworkDeviceFunction gets all NetworkDeviceFunction for this controller.
func (controller *Controller) NetworkDeviceFunctions() ([]*NetworkDeviceFunction, error) {
var result []*NetworkDeviceFunction

collectionError := common.NewCollectionError()
for _, networkDeviceLink := range controller.networkDeviceFunctions {
networkDeviceFunction, err := GetNetworkDeviceFunction(controller.GetClient(), networkDeviceLink)
if err != nil {
collectionError.Failures[networkDeviceLink] = err
} else {
result = append(result, networkDeviceFunction)
}
}

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

return result, collectionError
}

// NetworkPorts gets all NetworkPorts for this controller.
func (controller *Controller) NetworkPorts() ([]*NetworkPort, error) {
var result []*NetworkPort

collectionError := common.NewCollectionError()
for _, networkPortLink := range controller.networkPorts {
networkPort, err := GetNetworkPort(controller.GetClient(), networkPortLink)
if err != nil {
collectionError.Failures[networkPortLink] = err
} else {
result = append(result, networkPort)
}
}

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

return result, collectionError
}

// DataCenterBridging shall describe the capability, status,
// and configuration values related to Data Center Bridging (DCB) for a
// controller.
Expand Down Expand Up @@ -176,9 +241,9 @@ type NetworkAdapter struct {
ODataType string `json:"@odata.type"`
// Assembly shall be a link to a resource of type Assembly.
assembly string
// Controllers shall contain the set of network controllers ASICs that make
// Controller shall contain the set of network controllers ASICs that make
// up this NetworkAdapter.
Controllers []Controllers
controllers []*Controller
// Description provides a description of this resource.
Description string
// Manufacturer shall contain a value that represents the manufacturer of
Expand Down Expand Up @@ -218,6 +283,7 @@ func (networkadapter *NetworkAdapter) UnmarshalJSON(b []byte) error {
Assembly common.Link
NetworkDeviceFunctions common.Link
NetworkPorts common.Link
Controllers []*Controller
Actions actions
}

Expand All @@ -232,7 +298,7 @@ func (networkadapter *NetworkAdapter) UnmarshalJSON(b []byte) error {
networkadapter.networkDeviceFunctions = t.NetworkDeviceFunctions.String()
networkadapter.networkPorts = t.NetworkPorts.String()
networkadapter.resetSettingsToDefaultTarget = t.Actions.ResetSettingsToDefault.Target

networkadapter.controllers = t.Controllers
return nil
}

Expand Down Expand Up @@ -308,3 +374,10 @@ func (networkadapter *NetworkAdapter) NetworkPorts() ([]*NetworkPort, error) {
func (networkadapter *NetworkAdapter) ResetSettingsToDefault() error {
return networkadapter.Post(networkadapter.resetSettingsToDefaultTarget, nil)
}

func (networkadapter *NetworkAdapter) Controllers() []*Controller {
for i := range networkadapter.controllers {
networkadapter.controllers[i].SetClient(networkadapter.GetClient())
}
return networkadapter.controllers
}
30 changes: 18 additions & 12 deletions redfish/networkadapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ var networkAdapterBody = strings.NewReader(
"[email protected]": 1,
"NetworkPorts": [{
"@odata.id": "/redfish/v1/NetworkAdapters/Port-1"
},
{
"@odata.id": "/redfish/v1/NetworkAdapters/Port-2"
}
],
}],
"[email protected]": 2,
"PCIeDevices": [{
"@odata.id": "/redfish/v1/NetworkAdapters/PCIeDevice-1"
Expand Down Expand Up @@ -108,21 +104,31 @@ func TestNetworkAdapter(t *testing.T) {
t.Errorf("Received invalid name: %s", result.Name)
}

if !result.Controllers[0].ControllerCapabilities.DataCenterBridging.Capable {
stmcginnis marked this conversation as resolved.
Show resolved Hide resolved
if !result.controllers[0].ControllerCapabilities.DataCenterBridging.Capable {
t.Error("DCB should be enabled")
}

if result.Controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins != 1024 {
if result.controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins != 1024 {
t.Errorf("Received incorrect Controller NPIC max device logins: %d",
result.Controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins)
result.controllers[0].ControllerCapabilities.NPIV.MaxDeviceLogins)
}

if result.controllers[0].PCIeInterface.MaxPCIeType != Gen4PCIeTypes {
t.Errorf("Received incorrect max PCIe type: %s", result.controllers[0].PCIeInterface.MaxPCIeType)
}

if result.Controllers[0].PCIeInterface.MaxPCIeType != Gen4PCIeTypes {
t.Errorf("Received incorrect max PCIe type: %s", result.Controllers[0].PCIeInterface.MaxPCIeType)
if result.controllers[0].PCIeInterface.PCIeType != Gen4PCIeTypes {
t.Errorf("Received incorrect PCIe type: %s", result.controllers[0].PCIeInterface.PCIeType)
}

if result.Controllers[0].PCIeInterface.PCIeType != Gen4PCIeTypes {
t.Errorf("Received incorrect PCIe type: %s", result.Controllers[0].PCIeInterface.PCIeType)
if PCIeTypes(result.controllers[0].pcieDevices[0]) != "/redfish/v1/NetworkAdapters/PCIeDevice-1" {
t.Errorf("Received incorrect PCIeDevice Link: %s", "/redfish/v1/NetworkAdapters/PCIeDevice-1")
}
if PCIeTypes(result.controllers[0].networkPorts[0]) != "/redfish/v1/NetworkAdapters/Port-1" {
t.Errorf("Received incorrect NetworkPorts Link: %s", "/redfish/v1/NetworkAdapters/Port-1")
}
if PCIeTypes(result.controllers[0].networkDeviceFunctions[0]) != "/redfish/v1/NetworkAdapters/DeviceFunction-1" {
t.Errorf("Received incorrect NetworkDeviceFunctions Link: %s", "/redfish/v1/NetworkAdapters/DeviceFunction-1")
}

if result.resetSettingsToDefaultTarget != "/redfish/v1/NetworkAdapter/Actions/NetworkAdapter.ResetSettingsToDefault" {
Expand Down
Loading