|
| 1 | +// |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | +// |
| 4 | + |
| 5 | +package smc |
| 6 | + |
| 7 | +import ( |
| 8 | + "encoding/json" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/stmcginnis/gofish/redfish" |
| 13 | +) |
| 14 | + |
| 15 | +var computerSystemBody = `{ |
| 16 | + "@odata.type": "#ComputerSystem.v1_14_0.ComputerSystem", |
| 17 | + "@odata.id": "/redfish/v1/Systems/1", |
| 18 | + "Id": "1", |
| 19 | + "Name": "System", |
| 20 | + "Description": "Description of server", |
| 21 | + "Status": { |
| 22 | + "State": "Enabled", |
| 23 | + "Health": "OK" |
| 24 | + }, |
| 25 | + "SerialNumber": "S514359X4916804", |
| 26 | + "PartNumber": "SYS-821GE-200-02-LL014", |
| 27 | + "IndicatorLED": "Off", |
| 28 | + "LocationIndicatorActive": false, |
| 29 | + "SystemType": "Physical", |
| 30 | + "BiosVersion": "2.1", |
| 31 | + "Manufacturer": "Supermicro", |
| 32 | + "Model": "SYS-821GE-TNHR", |
| 33 | + "SKU": "0x1D1415D9", |
| 34 | + "UUID": "D4216600-C32C-11EE-8000-7CC25586E492", |
| 35 | + "ProcessorSummary": { |
| 36 | + "Count": 2, |
| 37 | + "Model": "Intel(R) Xeon(R) processor", |
| 38 | + "Status": { |
| 39 | + "State": "Enabled", |
| 40 | + "Health": "OK", |
| 41 | + "HealthRollup": "OK" |
| 42 | + }, |
| 43 | + "Metrics": { |
| 44 | + "@odata.id": "/redfish/v1/Systems/1/ProcessorSummary/ProcessorMetrics" |
| 45 | + } |
| 46 | + }, |
| 47 | + "MemorySummary": { |
| 48 | + "TotalSystemMemoryGiB": 2048, |
| 49 | + "MemoryMirroring": "System", |
| 50 | + "Status": { |
| 51 | + "State": "Enabled", |
| 52 | + "Health": "OK", |
| 53 | + "HealthRollup": "OK" |
| 54 | + }, |
| 55 | + "Metrics": { |
| 56 | + "@odata.id": "/redfish/v1/Systems/1/MemorySummary/MemoryMetrics" |
| 57 | + } |
| 58 | + }, |
| 59 | + "PowerState": "On", |
| 60 | + "PowerOnDelaySeconds": 3, |
| 61 | + |
| 62 | + "3:254:1" |
| 63 | + ], |
| 64 | + "PowerOffDelaySeconds": 3, |
| 65 | + |
| 66 | + "3:254:1" |
| 67 | + ], |
| 68 | + "PowerCycleDelaySeconds": 5, |
| 69 | + |
| 70 | + "5:254:1" |
| 71 | + ], |
| 72 | + "Boot": { |
| 73 | + "BootSourceOverrideEnabled": "Disabled", |
| 74 | + "BootSourceOverrideMode": "UEFI", |
| 75 | + "BootSourceOverrideTarget": "Pxe", |
| 76 | + |
| 77 | + "None", |
| 78 | + "Pxe", |
| 79 | + "Floppy", |
| 80 | + "Cd", |
| 81 | + "Usb", |
| 82 | + "Hdd", |
| 83 | + "BiosSetup", |
| 84 | + "UsbCd", |
| 85 | + "UefiBootNext", |
| 86 | + "UefiHttp" |
| 87 | + ], |
| 88 | + "BootOptions": { |
| 89 | + "@odata.id": "/redfish/v1/Systems/1/BootOptions" |
| 90 | + }, |
| 91 | + "BootNext": null, |
| 92 | + "BootOrder": [ |
| 93 | + "Boot0003", |
| 94 | + "Boot0004", |
| 95 | + "Boot0005", |
| 96 | + "Boot0006", |
| 97 | + "Boot0002", |
| 98 | + "Boot0001" |
| 99 | + ] |
| 100 | + }, |
| 101 | + "GraphicalConsole": { |
| 102 | + "ServiceEnabled": true, |
| 103 | + "Port": 5900, |
| 104 | + "MaxConcurrentSessions": 4, |
| 105 | + "ConnectTypesSupported": [ |
| 106 | + "KVMIP" |
| 107 | + ] |
| 108 | + }, |
| 109 | + "SerialConsole": { |
| 110 | + "MaxConcurrentSessions": 1, |
| 111 | + "SSH": { |
| 112 | + "ServiceEnabled": true, |
| 113 | + "Port": 22, |
| 114 | + "SharedWithManagerCLI": true, |
| 115 | + "ConsoleEntryCommand": "cd system1/sol1; start", |
| 116 | + "HotKeySequenceDisplay": "press <Enter>, <Esc>, and then <T> to terminate session" |
| 117 | + }, |
| 118 | + "IPMI": { |
| 119 | + "HotKeySequenceDisplay": "Press ~. - terminate connection", |
| 120 | + "ServiceEnabled": true, |
| 121 | + "Port": 623 |
| 122 | + } |
| 123 | + }, |
| 124 | + "VirtualMediaConfig": { |
| 125 | + "ServiceEnabled": true, |
| 126 | + "Port": 623 |
| 127 | + }, |
| 128 | + "BootProgress": { |
| 129 | + "LastState": "SystemHardwareInitializationComplete" |
| 130 | + }, |
| 131 | + "Processors": { |
| 132 | + "@odata.id": "/redfish/v1/Systems/1/Processors" |
| 133 | + }, |
| 134 | + "Memory": { |
| 135 | + "@odata.id": "/redfish/v1/Systems/1/Memory" |
| 136 | + }, |
| 137 | + "EthernetInterfaces": { |
| 138 | + "@odata.id": "/redfish/v1/Systems/1/EthernetInterfaces" |
| 139 | + }, |
| 140 | + "NetworkInterfaces": { |
| 141 | + "@odata.id": "/redfish/v1/Systems/1/NetworkInterfaces" |
| 142 | + }, |
| 143 | + "SimpleStorage": { |
| 144 | + "@odata.id": "/redfish/v1/Systems/1/SimpleStorage" |
| 145 | + }, |
| 146 | + "Storage": { |
| 147 | + "@odata.id": "/redfish/v1/Systems/1/Storage" |
| 148 | + }, |
| 149 | + "LogServices": { |
| 150 | + "@odata.id": "/redfish/v1/Systems/1/LogServices" |
| 151 | + }, |
| 152 | + "SecureBoot": { |
| 153 | + "@odata.id": "/redfish/v1/Systems/1/SecureBoot" |
| 154 | + }, |
| 155 | + "Bios": { |
| 156 | + "@odata.id": "/redfish/v1/Systems/1/Bios" |
| 157 | + }, |
| 158 | + "VirtualMedia": { |
| 159 | + "@odata.id": "/redfish/v1/Managers/1/VirtualMedia" |
| 160 | + }, |
| 161 | + "Links": { |
| 162 | + "Chassis": [ |
| 163 | + { |
| 164 | + "@odata.id": "/redfish/v1/Chassis/1" |
| 165 | + } |
| 166 | + ], |
| 167 | + "ManagedBy": [ |
| 168 | + { |
| 169 | + "@odata.id": "/redfish/v1/Managers/1" |
| 170 | + } |
| 171 | + ] |
| 172 | + }, |
| 173 | + "Actions": { |
| 174 | + "Oem": {}, |
| 175 | + "#ComputerSystem.Reset": { |
| 176 | + "target": "/redfish/v1/Systems/1/Actions/ComputerSystem.Reset", |
| 177 | + "@Redfish.ActionInfo": "/redfish/v1/Systems/1/ResetActionInfo" |
| 178 | + } |
| 179 | + }, |
| 180 | + "Oem": { |
| 181 | + "Supermicro": { |
| 182 | + "NodeManager": { |
| 183 | + "@odata.id": "/redfish/v1/Systems/1/Oem/Supermicro/NodeManager" |
| 184 | + }, |
| 185 | + "FixedBootOrder": { |
| 186 | + "@odata.id": "/redfish/v1/Systems/1/Oem/Supermicro/FixedBootOrder" |
| 187 | + }, |
| 188 | + "@odata.type": "#SmcSystemExtensions.v1_0_0.System" |
| 189 | + } |
| 190 | + }, |
| 191 | + "@odata.etag": "\"36f059d60095337115952f02709f65d6\"" |
| 192 | +}` |
| 193 | + |
| 194 | +// TestComputerSystem tests the parsing of ComputerSystem objects. |
| 195 | +func TestComputerSystem(t *testing.T) { |
| 196 | + var cs redfish.ComputerSystem |
| 197 | + err := json.NewDecoder(strings.NewReader(computerSystemBody)).Decode(&cs) |
| 198 | + if err != nil { |
| 199 | + t.Errorf("Error decoding JSON: %s", err) |
| 200 | + } |
| 201 | + |
| 202 | + result, err := FromComputerSystem(&cs) |
| 203 | + if err != nil { |
| 204 | + t.Errorf("Error converting Redfish ComputerSystem to SMC ComputerSystem: %s", err) |
| 205 | + } |
| 206 | + |
| 207 | + if result.ID != "1" { |
| 208 | + t.Errorf("Received invalid ID: %s", result.ID) |
| 209 | + } |
| 210 | + |
| 211 | + if result.Name != "System" { |
| 212 | + t.Errorf("Received invalid name: %s", result.Name) |
| 213 | + } |
| 214 | + |
| 215 | + if result.nodeManager != "/redfish/v1/Systems/1/Oem/Supermicro/NodeManager" { |
| 216 | + t.Errorf("Invalid node manager link: %s", result.nodeManager) |
| 217 | + } |
| 218 | + |
| 219 | + if result.fixedBootOrder != "/redfish/v1/Systems/1/Oem/Supermicro/FixedBootOrder" { |
| 220 | + t.Errorf("Invalid fixed boot order link: %s", result.fixedBootOrder) |
| 221 | + } |
| 222 | +} |
0 commit comments