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

Improve test coverage for updated objects #307

Merged
merged 9 commits into from
Apr 18, 2024
8 changes: 8 additions & 0 deletions redfish/certificateservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ func (certificateservice *CertificateService) UnmarshalJSON(b []byte) error {
return nil
}

// CertificateLocations get the certificate locations.
func (certificateservice *CertificateService) CertificateLocations() (*CertificateLocations, error) {
if certificateservice.certificateLocations == "" {
return nil, nil
}
return GetCertificateLocations(certificateservice.GetClient(), certificateservice.certificateLocations)
}

// GetCertificateService will get a CertificateService instance from the service.
func GetCertificateService(c common.Client, uri string) (*CertificateService, error) {
resp, err := c.Get(uri)
Expand Down
33 changes: 32 additions & 1 deletion redfish/computersystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,27 @@ var computerSystemBody = `{
"SDCard",
"UefiHttp"
],
"BootOptions": {
"@odata.id": "/redfish/v1/Systems/1/BootOptions"
},
"BootNext": "",
"BootOrder": [
"Boot0003",
"Boot0011",
"Boot0014",
"Boot0007",
"Boot0008",
"Boot0009",
"Boot000A",
"Boot000B",
"Boot000C",
"Boot000D",
"Boot000E",
"Boot000F",
"Boot0002"
],
"UefiTargetBootSourceOverride": "uefi device path",
"HttpBootURI": "http://localhost/boot.efi"
"HttpBootUri": "http://localhost/boot.efi"
},
"BiosVersion": "P79 v1.00 (09/20/2013)",
"ProcessorSummary": {
Expand Down Expand Up @@ -103,6 +122,18 @@ var computerSystemBody = `{
"SimpleStorage": {
"@odata.id": "/redfish/v1/Systems/System-1/SimpleStorage"
},
"Storage": {
"@odata.id": "/redfish/v1/Systems/1/Storage"
},
"LogServices": {
"@odata.id": "/redfish/v1/Systems/1/LogServices"
},
"SecureBoot": {
"@odata.id": "/redfish/v1/Systems/1/SecureBoot"
},
"Bios": {
"@odata.id": "/redfish/v1/Systems/1/Bios"
},
"Links": {
"Chassis": [
{
Expand Down
37 changes: 37 additions & 0 deletions redfish/ethernetinterface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var ethernetInterfaceBody = `{
"FQDN": "default.local",
"FullDuplex": true,
"HostName": "default",
"MaxIPv6StaticAddresses": 1,
"IPv4Addresses": [
{
"Address": "172.16.3.39",
Expand All @@ -29,6 +30,42 @@ var ethernetInterfaceBody = `{
"SubnetMask": "255.255.0.0"
}
],
"IPv6AddressPolicyTable": [
{
"Prefix": "::1/128",
"Precedence": 50,
"Label": 0
}
],
"IPv4StaticAddresses": [
{
"Address": "169.254.3.254",
"SubnetMask": "255.255.255.0",
"Gateway": "169.254.3.254"
}
],
"IPv6StaticAddresses": [
{
"Address": "",
"PrefixLength": 0
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
}
],
"Id": "NIC-0",
"InterfaceEnabled": true,
"LinkStatus": "LinkUp",
Expand Down
24 changes: 4 additions & 20 deletions redfish/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ type Manager struct {
SerialConsole SerialConsole
// serialInterfaces shall be a link to a collection of type
// SerialInterfaceCollection which are for the use of this manager.
serialInterfaces []string
serialInterfaces string
// SerialNumber shall contain a manufacturer-allocated number that
// identifies the manager.
SerialNumber string
Expand Down Expand Up @@ -427,7 +427,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error {
NetworkProtocol common.Link
ManagerDiagnosticData common.Link
RemoteAccountService common.Link
SerialInterfaces common.LinksCollection
SerialInterfaces common.Link
USBPorts common.LinksCollection
VirtualMedia common.Link
Links linkReference
Expand All @@ -451,7 +451,7 @@ func (manager *Manager) UnmarshalJSON(b []byte) error {
manager.OemActions = t.Actions.Oem
manager.Oem = t.Oem
manager.remoteAccountService = t.RemoteAccountService.String()
manager.serialInterfaces = t.SerialInterfaces.ToStrings()
manager.serialInterfaces = t.SerialInterfaces.String()
manager.usbPorts = t.USBPorts.ToStrings()
manager.virtualMedia = t.VirtualMedia.String()

Expand Down Expand Up @@ -667,23 +667,7 @@ func (manager *Manager) RemoteAccountService() (*AccountService, error) {

// SerialInterfaces get this manager's serial interfaces.
func (manager *Manager) SerialInterfaces() ([]*SerialInterface, error) {
var result []*SerialInterface

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

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

return result, collectionError
return ListReferencedSerialInterfaces(manager.GetClient(), manager.serialInterfaces)
}

// USBPorts get the USB ports of the manager.
Expand Down
5 changes: 5 additions & 0 deletions redfish/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var memoryBody = `{
},
"LogicalSizeMiB": 2097152,
"Manufacturer": "Generic",
"MaxTDPMilliWatts": [0],
"MemoryDeviceType": "DDR4",
"MemoryLocation": {
"Channel": 1,
Expand All @@ -59,9 +60,13 @@ var memoryBody = `{
},
"MemoryMedia": ["DRAM"],
"MemoryType": "NVDIMM_N",
"Metrics": {
"@odata.id": "/redfish/v1/Systems/1/Memory/1/MemoryMetrics"
},
"OperatingMemoryModes": [
"PMEM"
],
"OperatingSpeedMhz": 3200,
"PowerManagementPolicy": {
"AveragePowerBudgetMilliWatts": 42,
"MaxTDPMilliWatts": 12,
Expand Down
44 changes: 44 additions & 0 deletions redfish/networkinterface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@ var networkInterfaceBody = strings.NewReader(
"Id": "NetworkInterface-1",
"Name": "NetworkInterfaceOne",
"Description": "NetworkInterface One",
"InterfaceEnabled": false,
"PermanentMACAddress": "BE:3A:F2:B6:05:9F",
"MACAddress": "00:00:00:00:00:00",
"SpeedMbps": 100,
"AutoNeg": true,
"FullDuplex": true,
"MTUSize": 0,
"IPv4Addresses": [
{
"Address": "169.254.3.1",
"SubnetMask": "255.255.255.0",
"AddressOrigin": "Static",
"Gateway": "169.254.3.254"
}
],
"IPv4StaticAddresses": [
{
"Address": "169.254.3.1",
"SubnetMask": "255.255.255.0",
"Gateway": "169.254.3.254"
}
],
"IPv6StaticAddresses": [
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
},
{
"Address": "::",
"PrefixLength": 64
}
],
"Links": {
"NetworkAdapter": {
"@odata.id": "/redfish/v1/NetworkAdapters/1"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,75 @@ var networkProtocolBody = `{
}
}`

var managerNetworkProtocolBody = `{
"@odata.type": "#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol",
"@odata.id": "/redfish/v1/Managers/1/NetworkProtocol",
"Id": "NetworkProtocol",
"Name": "Manager Network Protocol",
"Description": "Manager Network Service Status",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"HostName": "",
"FQDN": "",
"HTTP": {
"ProtocolEnabled": true,
"Port": 80
},
"HTTPS": {
"ProtocolEnabled": true,
"Port": 443,
"Certificates": {
"@odata.id": "/redfish/v1/Managers/1/NetworkProtocol/HTTPS/Certificates"
}
},
"SNMP": {
"AuthenticationProtocol": null,
"CommunityAccessMode": null,
"CommunityStrings": [],
"EnableSNMPv2c": false,
"EnableSNMPv3": false,
"EncryptionProtocol": null,
"EngineId": {
"PrivateEnterpriseId": "00005345"
},
"HideCommunityStrings": null,
"ProtocolEnabled": false,
"Port": 161
},
"IPMI": {
"ProtocolEnabled": true,
"Port": 623
},
"SSH": {
"ProtocolEnabled": true,
"Port": 22
},
"VirtualMedia": {
"ProtocolEnabled": true,
"Port": 623
},
"KVMIP": {
"ProtocolEnabled": true,
"Port": 5900
},
"NTP": {
"ProtocolEnabled": false,
"NTPServers": [
"localhost",
"127.0.0.1"
],
"[email protected]": 2
},
"SSDP": {
"ProtocolEnabled": true,
"Port": 1900,
"NotifyTTL": 2,
"NotifyIPv6Scope": "Link"
}
}`

func TestNetworkProtocol(t *testing.T) {
var result NetworkProtocolSettings
err := json.NewDecoder(strings.NewReader(networkProtocolBody)).Decode(&result)
Expand All @@ -150,6 +219,35 @@ func TestNetworkProtocol(t *testing.T) {
}
}

func TestNetworkProtocolManager(t *testing.T) {
var result NetworkProtocolSettings
err := json.NewDecoder(strings.NewReader(managerNetworkProtocolBody)).Decode(&result)

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

if !result.SSH.ProtocolEnabled {
t.Error("SSH Protocol should be enabled")
}

if len(result.NTP.NTPServers) != 2 {
t.Error("Should be 2 NTP servers defined")
}

if result.NTP.NTPServers[1] != "127.0.0.1" {
t.Error("NTPServers should be set")
}

if result.SNMP.EngineID.PrivateEnterpriseID != "00005345" {
t.Error("Wrong SNMP EngineID PrivateEnterpriseId property")
}

if result.HTTPS.certificates != "/redfish/v1/Managers/1/NetworkProtocol/HTTPS/Certificates" {
t.Errorf("Wrong HTTPS certificates link: %s", result.HTTPS.certificates)
}
}

func TestNetworkProtocol_Update(t *testing.T) {
var result NetworkProtocolSettings
err := json.NewDecoder(strings.NewReader(networkProtocolBody)).Decode(&result)
Expand Down
Loading